[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sapphire-dev] diagram floating palette question

I spent a few minutes playing around with the popupmenu support for floating palette.  Also I added the Sapphire.Add to this floating palette for you guys to evaluate.  Attached is a patch for getting submenus to work.  See screenshot of them in action:

Inline image 1


Inline image 2


Thanks for taking a look at this,
G


On Fri, Apr 27, 2012 at 9:25 AM, Greg Amerson <gregory.amerson@xxxxxxxxxxx> wrote:
Also, I noticed in the code that the Sapphire.Add context is not added to the floating palette.  What do you guys think about adding that?  Currently in my diagram editor I have a Sapphire.Add context on the node and would like to see if it would be possible to have it show up as well.

Also, as you can see on my screenshot, some of my action factories don't actually render any actions when nodes have particular state (see the first action on top left in my screenshot).   So I think we should protect the adding of actions to the floating palette to check to see if they are actually enabled.

Looking at the floating palette code it seems that it supports the notion of popup menus.  Can we take advantage of this for when actions have multiple handlers (as in the case of action handler factories)?  


On Fri, Apr 27, 2012 at 8:50 AM, Greg Amerson <gregory.amerson@xxxxxxxxxxx> wrote:
Hey guys,

I just synced and see the new floating palette (very nice!).  However, I see some issues with the floating palette and the action handler factories that I have added to a particular node.  See this screenshot:


  Inline image 2

You can see that I have 3 action handler factories, one for Sapphire.Add, and two for Sapphire.Edit (that I have added in my sapphire-extension.xml).  Sometimes these nodes action handler factories have sub menus, but I don't see these on the floating palette. It just seems to execute the first action from the sub menu.

Any thoughts? 



--
Greg Amerson
Liferay, Inc.
---
17 May 2012 | Liferay Budapest Symposium | liferay.com/budapest2012
23 May 2012 | Liferay France Symposium | liferay.com/france2012




--
Greg Amerson
Liferay, Inc.
---
17 May 2012 | Liferay Budapest Symposium | liferay.com/budapest2012
23 May 2012 | Liferay France Symposium | liferay.com/france2012




--
Greg Amerson
Liferay, Inc.
www.liferay.com
---
17 May 2012 | Liferay Budapest Symposium | liferay.com/budapest2012
23 May 2012 | Liferay France Symposium | liferay.com/france2012

### 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;
+    }
+
+
+
 }