From: Tuukka Lehtonen Date: Thu, 15 Sep 2016 18:18:22 +0000 (+0300) Subject: Sync git svn branch with SVN repository r33198. X-Git-Tag: v1.25.0~116^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=d11239c402eec37ba28edcfa7ea6ca7c1f01147f Sync git svn branch with SVN repository r33198. refs #6688 refs #6692 --- diff --git a/bundles/org.simantics.document.ui.ontology/graph.tg b/bundles/org.simantics.document.ui.ontology/graph.tg index a32cf12e7..66fea4038 100644 Binary files a/bundles/org.simantics.document.ui.ontology/graph.tg and b/bundles/org.simantics.document.ui.ontology/graph.tg differ diff --git a/bundles/org.simantics.document.ui.ontology/graph/DocumentUI.pgraph b/bundles/org.simantics.document.ui.ontology/graph/DocumentUI.pgraph index cb7cd6498..3ac065d5e 100644 --- a/bundles/org.simantics.document.ui.ontology/graph/DocumentUI.pgraph +++ b/bundles/org.simantics.document.ui.ontology/graph/DocumentUI.pgraph @@ -15,6 +15,7 @@ UI = : L0.Ontology L0.HasResourceClass "org.simantics.document.ui.DocumentUIResource" UI.Functions : L0.Library +UI.Functions.editorLoaded : L0.Function UI.CSSEditorContribution L0.HasLabel "Wiki Style Editor" @@ -187,7 +188,7 @@ UI.Alternative : VIEWS.Alternative UI.NoDocument UI.Sash : VIEWS.SashForm - VIEWS.onLoaded UI.Functions.editorLoaded : L0.Function + VIEWS.onLoaded UI.Functions.editorLoaded VIEWS.Control.layoutData _ : VIEWS.GridLayout.GridData VIEWS.GridLayout.GridData.horizontalGrab true VIEWS.GridLayout.GridData.verticalGrab true @@ -243,7 +244,7 @@ UI.NoDocument : VIEWS.Composite VIEWS.Button.modifier UI.Functions.onCreateDocumentButton : L0.Function UI.Editor : VIEWS.Composite - VIEWS.onLoaded UI.Functions.editorLoaded : L0.Function + VIEWS.onLoaded UI.Functions.editorLoaded L0.HasValueType "WriteGraph => Variable -> Variable -> Boolean" VIEWS.Control.layoutData _ : VIEWS.GridLayout.GridData VIEWS.GridLayout.GridData.horizontalGrab true diff --git a/bundles/org.simantics.event.ontology/graph.tg b/bundles/org.simantics.event.ontology/graph.tg index ffa0b161c..ed95dc026 100644 Binary files a/bundles/org.simantics.event.ontology/graph.tg and b/bundles/org.simantics.event.ontology/graph.tg differ diff --git a/bundles/org.simantics.event.ontology/graph/Event.pgraph b/bundles/org.simantics.event.ontology/graph/Event.pgraph index c48cda2d8..bec7cfe4f 100644 --- a/bundles/org.simantics.event.ontology/graph/Event.pgraph +++ b/bundles/org.simantics.event.ontology/graph/Event.pgraph @@ -100,7 +100,8 @@ EVENT.Returns EVENT.Event + <-- EVENT.Event + --> EVENT.Event EVENT.NoReturn L0.HasDescription "A tag for marking events that are not expected to be returned. This can be used as a hint for user interfaces." @@ -111,7 +112,8 @@ EVENT.ReturnEvent L0.HasDescription "Indicates that an event is a return event." @L0.defTag @L0.symmetric - <-- EVENT.Event --> EVENT.Event + <-- EVENT.Event + --> EVENT.Event /* // Future ideas: diff --git a/bundles/org.simantics.selectionview.ontology/graph.tg b/bundles/org.simantics.selectionview.ontology/graph.tg index 67160405a..757158d3b 100644 Binary files a/bundles/org.simantics.selectionview.ontology/graph.tg and b/bundles/org.simantics.selectionview.ontology/graph.tg differ diff --git a/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph b/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph index d19eb4ed0..f9eb00666 100644 --- a/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph +++ b/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph @@ -10,6 +10,7 @@ SEL.Functions : L0.Library SEL.TabContribution "Resource -> Resource" + + + @@ -123,6 +127,25 @@ TODO: investigate, if the mechanism could be used with menus aswell. + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolBarCommandRegistry.java b/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolBarCommandRegistry.java index 7287c5ae3..2e2ea3f19 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolBarCommandRegistry.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolBarCommandRegistry.java @@ -74,6 +74,12 @@ public class ToolBarCommandRegistry implements IExtensionChangeHandler { ext.type = el.getAttribute("type"); ext.value = el.getAttribute("value"); ext.contributorId = el.getContributor().getName(); + for (IConfigurationElement param : el.getChildren("parameter")) { + Parameter parameter = new Parameter(); + parameter.name = param.getAttribute("name"); + parameter.value = param.getAttribute("value"); + ext.parameters.add(parameter); + } tracker.registerObject(el.getDeclaringExtension(), ext, IExtensionTracker.REF_STRONG); extensions.add(ext); @@ -111,6 +117,7 @@ public class ToolBarCommandRegistry implements IExtensionChangeHandler { public String value; public String image; public String contributorId; + public List parameters = new ArrayList<>(); public ToolbarCommandExtension(String commandId) { super(); this.commandId = commandId; @@ -122,5 +129,10 @@ public class ToolBarCommandRegistry implements IExtensionChangeHandler { } } + public class Parameter { + public String name; + public String value; + } + } diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolbarContributor.java b/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolbarContributor.java index 84413bb46..0f7d3e26d 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolbarContributor.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/toolbar/ToolbarContributor.java @@ -11,6 +11,9 @@ import org.eclipse.core.commands.Command; import org.eclipse.core.commands.CommandEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ICommandListener; +import org.eclipse.core.commands.IParameter; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.State; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -42,11 +45,12 @@ import org.eclipse.ui.handlers.RadioState; import org.eclipse.ui.handlers.RegistryToggleState; import org.eclipse.ui.menus.WorkbenchWindowControlContribution; import org.eclipse.ui.part.EditorActionBarContributor; - import org.simantics.db.common.utils.Logger; import org.simantics.ui.internal.Activator; +import org.simantics.ui.toolbar.ToolBarCommandRegistry.Parameter; import org.simantics.ui.toolbar.ToolBarCommandRegistry.ToolbarCommandExtension; import org.simantics.utils.datastructures.MapList; +import org.simantics.utils.ui.ExceptionUtils; /** @@ -64,7 +68,8 @@ import org.simantics.utils.datastructures.MapList; public class ToolbarContributor extends EditorActionBarContributor implements ICommandListener, IPartListener, CommandStateListener, IExecutableExtension { private static boolean DEBUG = false; // Print debug messages to console - private static boolean REUSE = true; // true: Reuse contribution items / false: delete items on dispose + private boolean REUSE = true; // true: Reuse contribution items (leave toolbar in disabled state when editor closes) + // false: delete items on dispose (remove toolbar editor closes) private static final String PLATFORM = "platform:/plugin/"; @@ -81,6 +86,8 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC MapList actions = new MapList(); CommandStateRegistry stateRegistry; + + IPartListener partListener; private Map menus = new HashMap(); @@ -88,6 +95,28 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); stateRegistry = CommandStateRegistry.getInstance(); + // we need part listener to be notified for other editor activations (i.e editors that do not use this contributor). + partListener = new IPartListener() { + + @Override + public void partOpened(IWorkbenchPart part) {} + + @Override + public void partDeactivated(IWorkbenchPart part) {} + + @Override + public void partClosed(IWorkbenchPart part) {} + + @Override + public void partBroughtToTop(IWorkbenchPart part) {} + + @Override + public void partActivated(IWorkbenchPart part) { + if (part instanceof IEditorPart) + setContext2((IEditorPart)part); + } + }; + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addPartListener(partListener); } @@ -106,7 +135,9 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC if ("toolbar".equals(key)) { toolbarId = value; - } + } else if ("hide".equals(key)) { + REUSE = !Boolean.parseBoolean(value); + } } } @@ -144,6 +175,26 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC if (DEBUG) System.out.println("Adding command to toolbar " +getToolbarId() + " " + ext); String commandId = ext.commandId; Command command = service.getCommand(commandId); + ICommandWrapper wrapper = new CommandWrapper(command); + + ParameterizedCommand parameterizedCommand = null; + + if (ext.parameters.size() > 0) { + try { + Parameterization parameterizations[] = new Parameterization[ext.parameters.size()]; + for (int i = 0; i < ext.parameters.size(); i++) { + Parameter param = ext.parameters.get(i); + IParameter parameter = command.getParameter(param.name); + parameterizations[i] = new Parameterization(parameter, param.value); + } + parameterizedCommand = new ParameterizedCommand(command, parameterizations); + wrapper = new ParameterizedCommandWrapper(parameterizedCommand); + } catch (org.eclipse.core.commands.common.NotDefinedException e) { + e.printStackTrace(); + ExceptionUtils.logError(e); + return; + } + } String type = ext.type; @@ -157,15 +208,15 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC CommandAction a = null; if (type.equals("toggle") && toggleState != null) { - a = new CommandCheckboxAction(command,name,image); + a = new CommandCheckboxAction(wrapper,name,image); stateRegistry.storeDefaultState(commandId); } else if (radioState != null && ext.value != null) { stateRegistry.storeDefaultState(commandId); if (type.equals("radio")) { - a = new CommandRadioAction(command,name,ext.value,image); + a = new CommandRadioAction(wrapper,name,ext.value,image); } else if (type.equals("combo")) { - a = new CommandRadioAction(command,name,ext.value,image); + a = new CommandRadioAction(wrapper,name,ext.value,image); ComboContribution combo = menus.get(commandId); if (REUSE && combo == null) { combo = (ComboContribution)mgr.find(commandId); @@ -190,7 +241,7 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC return; } } else if (type.equals("push")) { - a = new CommandPushAction(command,name,image); + a = new CommandPushAction(wrapper,name,image); } else { if (DEBUG) System.out.println(ext + " is not valid."); Logger.defaultLogError(ext + " is not valid."); @@ -267,6 +318,14 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC setContext((IEditorPart)part); } + private void setContext2(IEditorPart part) { + if (REUSE) + return; + if (this.activePart == part) + return; + setContext(null); + } + private void setContext(IEditorPart part) { this.activePart = part; if (activePart != null && !parts.contains(activePart)) { @@ -289,8 +348,9 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC a.setEnabled(false); } ComboContribution menu = menus.get(commandId); - if (menu != null) + if (menu != null) { menu.setEnabled(false); + } } } @@ -323,13 +383,16 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC actions.clear(); // without this the contributed toolbar widgets would continue reserve the space even when they are destroyed. - // TODO : how to make the toolbar fix its layout? - // Note: Using REUSE flag alleviates the problem, since the widgets are not removed. coolBarManager.update(true); + mgr.update(true); } CommandStateRegistry.getInstance().removeListener(this); super.dispose(); activePart = null; + if (partListener != null) { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addPartListener(partListener); + partListener = null; + } } boolean settingState = false; @@ -354,10 +417,12 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC private void restoreActionStates() { if (activePart == null) return; + if (DEBUG)System.out.println("Restore " + activePart); // toggles Map defaultToggleStates = stateRegistry.getDefaultToggleStates(); for (String commandId : defaultToggleStates.keySet()) { for (CommandAction a : actions.getValues(commandId)) { + if (DEBUG)System.out.println(commandId + " def " + defaultToggleStates.get(commandId)); a.setChecked(defaultToggleStates.get(commandId)); } } @@ -365,6 +430,7 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC if (editorStates != null) { for (String commandId : editorStates.keySet()) { for (CommandAction a : actions.getValues(commandId)) { + if (DEBUG)System.out.println(commandId + " " + editorStates.get(commandId)); a.setChecked(editorStates.get(commandId)); } } @@ -375,6 +441,7 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC String defaultValue = defaultRadioStates.get(commandId); for (CommandAction a : actions.getValues(commandId)) { CommandRadioAction r = (CommandRadioAction)a; + if (DEBUG)System.out.println(commandId + " def " + r.getValue().equals(defaultValue) +" " + r.getValue()); r.setChecked(r.getValue().equals(defaultValue)); } } @@ -385,6 +452,7 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC String defaultValue = editorRadioStates.get(commandId); for (CommandAction a : actions.getValues(commandId)) { CommandRadioAction r = (CommandRadioAction)a; + if (DEBUG)System.out.println(commandId + " " + r.getValue().equals(defaultValue) +" " + r.getValue()); r.setChecked(r.getValue().equals(defaultValue)); } } @@ -434,14 +502,28 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC return (Boolean)toggleState.getValue(); } - private abstract class CommandAction extends Action { + private interface ICommandWrapper { + + public Command getCommand(); + public String getCommandId(); + public void run(); + } + + private class CommandWrapper implements ICommandWrapper{ private Command command; - public CommandAction(Command command, String name, ImageDescriptor image, int style) { - super(name,style); + public CommandWrapper(Command command) { this.command = command; - if (image != null) - setImageDescriptor(image); + } + + @Override + public Command getCommand() { + return command; + } + + @Override + public String getCommandId() { + return command.getId(); } @Override @@ -453,35 +535,93 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC } } + @Override + public boolean equals(Object obj) { + if (obj.getClass() != getClass()) + return false; + CommandWrapper other= (CommandWrapper)obj; + return other.getCommandId().equals(getCommandId()); + } + } + + private class ParameterizedCommandWrapper implements ICommandWrapper{ + private ParameterizedCommand command; + + public ParameterizedCommandWrapper(ParameterizedCommand command) { + this.command = command; + } + + @Override public Command getCommand() { - return command; + return command.getCommand(); } + @Override public String getCommandId() { return command.getId(); } + @Override + public void run() { + try { + handlerService.executeCommand(command, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean equals(Object obj) { + if (obj.getClass() != getClass()) + return false; + ParameterizedCommandWrapper other= (ParameterizedCommandWrapper)obj; + return other.command.equals(command); + } + } + + private abstract class CommandAction extends Action { + private ICommandWrapper command; + + public CommandAction(ICommandWrapper command, String name, ImageDescriptor image, int style) { + super(name,style); + this.command = command; + if (image != null) + setImageDescriptor(image); + } + + @Override + public void run() { + command.run(); + } + + public Command getCommand() { + return command.getCommand(); + } + + public String getCommandId() { + return command.getCommandId(); + } + @Override public boolean equals(Object obj) { if (obj.getClass() != getClass()) return false; CommandAction other= (CommandAction)obj; - if (!other.getCommandId().equals(getCommandId())) - return false; - return true; + return command.equals(other.command); } @Override public int hashCode() { - return command.getId().hashCode(); + return command.getCommandId().hashCode(); } } + private class CommandCheckboxAction extends CommandAction { - public CommandCheckboxAction(Command command, String name, ImageDescriptor image) { + public CommandCheckboxAction(ICommandWrapper command, String name, ImageDescriptor image) { super(command,name,image,Action.AS_CHECK_BOX); } @@ -505,7 +645,7 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC private String value; - public CommandRadioAction(Command command, String name, String value, ImageDescriptor image) { + public CommandRadioAction(ICommandWrapper command, String name, String value, ImageDescriptor image) { super(command,name,image,Action.AS_RADIO_BUTTON); this.value = value; } @@ -543,7 +683,7 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC private class CommandPushAction extends CommandAction { - public CommandPushAction(Command command, String name, ImageDescriptor image) { + public CommandPushAction(ICommandWrapper command, String name, ImageDescriptor image) { super(command,name,image,Action.AS_PUSH_BUTTON); } @@ -615,6 +755,12 @@ public class ToolbarContributor extends EditorActionBarContributor implements IC if (combo != null) combo.setEnabled(enabled); } + + @Override + public void dispose() { + combo.dispose(); + super.dispose(); + } } }