[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sapphire-dev] diagram floating palette question
|
### Eclipse Workspace Patch 1.0
#P org.eclipse.sapphire.ui.swt.gef
Index: src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonEntry.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui.swt.gef/src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonEntry.java,v
retrieving revision 1.1
diff -u -r1.1 ContextButtonEntry.java
--- src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonEntry.java 26 Apr 2012 22:47:49 -0000 1.1
+++ src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonEntry.java 27 Apr 2012 01:56:15 -0000
@@ -41,6 +41,7 @@
private SapphireDiagramEditor editor;
private ISapphirePart sapphirePart;
private SapphireAction action;
+ private SapphireActionHandler handler;
private List<ContextButtonEntry> contextButtonMenuEntries = new ArrayList<ContextButtonEntry>();
private static ImageDescriptor defaultImageDescriptor = null;
@@ -62,33 +63,63 @@
public List<ContextButtonEntry> getContextButtonMenuEntries() {
return this.contextButtonMenuEntries;
}
-
- public ContextButtonEntry(SapphireDiagramEditor editor, ISapphirePart part, SapphireAction action)
+
+ public ContextButtonEntry(SapphireDiagramEditor editor, ISapphirePart part, SapphireAction action, SapphireActionHandler handler)
{
this.editor = editor;
this.sapphirePart = part;
this.action = action;
+ this.handler = handler;
}
-
- public SapphireAction getAction()
+
+ public SapphireActionHandler getActionHandler()
{
- return this.action;
+ return this.handler;
}
-
+
+ public SapphireAction getAction()
+ {
+ return this.action;
+ }
+
public String getText()
{
- return this.action.getLabel();
+ if (this.action.getActiveHandlers().size() > 1 && this.handler != null)
+ {
+ return this.handler.getLabel();
+ }
+ else
+ {
+ return this.action.getLabel();
+ }
}
-
+
public String getDescription()
{
- return this.action.getDescription();
+ if (this.action.getActiveHandlers().size() > 1 && this.handler != null)
+ {
+ return this.handler.getDescription();
+ }
+ else
+ {
+ return this.action.getDescription();
+ }
}
-
+
public Image getImage()
{
- ImageData imageData = this.getAction().getImage(16);
- ImageDescriptor imageDescriptor;
+ ImageData imageData = null;
+
+ if (this.action.getActiveHandlers().size() > 1 && this.handler != null)
+ {
+ imageData = this.getActionHandler().getImage(16);
+ }
+ else
+ {
+ imageData = this.getAction().getImage(16);
+ }
+
+ ImageDescriptor imageDescriptor;
if (imageData == null)
{
imageDescriptor = getDefaultImageDescriptor();
@@ -97,25 +128,31 @@
{
imageDescriptor = SwtRendererUtil.toImageDescriptor(imageData);
}
- return imageDescriptor.createImage();
+ return imageDescriptor.createImage();
}
-
+
public boolean canExecute()
{
- return this.action.isEnabled();
+ if (this.action.getActiveHandlers().size() > 1 && this.handler != null)
+ {
+ return this.handler.isEnabled();
+ }
+ else
+ {
+ return this.action.isEnabled();
+ }
}
-
+
public void execute()
- {
- SapphireActionHandler handler = this.action.getFirstActiveHandler();
- if (handler != null)
- {
- DiagramRenderingContext context =
- this.editor.getConfigurationManager().getDiagramRenderingContextCache().get(this.sapphirePart);
- handler.execute(context);
- }
- }
-
+ {
+ if (handler != null)
+ {
+ DiagramRenderingContext context =
+ this.editor.getConfigurationManager().getDiagramRenderingContextCache().get(this.sapphirePart);
+ handler.execute(context);
+ }
+ }
+
private static ImageDescriptor getDefaultImageDescriptor()
{
if (defaultImageDescriptor == null)
Index: src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonManager.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui.swt.gef/src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonManager.java,v
retrieving revision 1.2
diff -u -r1.2 ContextButtonManager.java
--- src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonManager.java 26 Apr 2012 23:10:41 -0000 1.2
+++ src/org/eclipse/sapphire/ui/swt/gef/contextbuttons/ContextButtonManager.java 27 Apr 2012 01:56:16 -0000
@@ -37,9 +37,10 @@
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.tools.AbstractConnectionCreationTool;
import org.eclipse.gef.tools.CreationTool;
-import org.eclipse.osgi.service.datalocation.Location;
+import org.eclipse.sapphire.ui.ISapphirePart;
import org.eclipse.sapphire.ui.SapphireAction;
import org.eclipse.sapphire.ui.SapphireActionGroup;
+import org.eclipse.sapphire.ui.SapphireActionHandler;
import org.eclipse.sapphire.ui.SapphireActionSystem;
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
import org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor;
@@ -393,8 +394,7 @@
List<SapphireAction> actions = new ArrayList<SapphireAction>(originalActions.size());
for (SapphireAction action : originalActions)
{
- if (!(action.getId().equals(DIAGRAM_NODE_DEFAULT_ACTION)) &&
- !(action.getId().equals(SAPPHIRE_ADD_ACTION)))
+ if (!(action.getId().equals(DIAGRAM_NODE_DEFAULT_ACTION)))
{
actions.add(action);
}
@@ -442,17 +442,50 @@
for (int i = numTopActions - 1; i >= 0; i--)
{
SapphireAction action = actions.get(i);
- ContextButtonEntry entry = new ContextButtonEntry(getEditor(), nodePart, action);
- contextButtonPadData.getTopContextButtons().add(entry);
-
+
+ if (action.isEnabled())
+ {
+ ContextButtonEntry entry = createContextButtonEntry(action, nodePart);
+
+ contextButtonPadData.getTopContextButtons().add(entry);
+ }
+
}
for (int i = numTopActions; i < numOfActions; i++)
{
SapphireAction action = actions.get(i);
- ContextButtonEntry entry = new ContextButtonEntry(getEditor(), nodePart, action);
- contextButtonPadData.getRightContextButtons().add(entry);
+
+ if (action.isEnabled())
+ {
+ ContextButtonEntry entry = createContextButtonEntry(action, nodePart);
+
+ contextButtonPadData.getRightContextButtons().add(entry);
+ }
}
return contextButtonPadData;
}
-
+
+ private ContextButtonEntry createContextButtonEntry(SapphireAction action, ISapphirePart nodePart)
+ {
+ ContextButtonEntry entry = null;
+
+ if (action.getActiveHandlers().size() > 1)
+ {
+ entry = new ContextButtonEntry(getEditor(), nodePart, action, null);
+
+ for (SapphireActionHandler handler : action.getActiveHandlers())
+ {
+ entry.addContextButtonMenuEntry( new ContextButtonEntry(getEditor(), nodePart, action, handler));
+ }
+ }
+ else
+ {
+ entry = new ContextButtonEntry(getEditor(), nodePart, action, action.getFirstActiveHandler());
+ }
+
+ return entry;
+ }
+
+
+
}