summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-11 02:52:22 (EDT)
committerEike Stepper2007-10-11 02:52:22 (EDT)
commit6c8f6dcd8276ad2f2fc983f6d792d9f215db6a94 (patch)
treea9f010cb2079171af1fcf25feea5c4f350a3a810
parent590e7416ee163b9ddafa98bb6541eb0326bdacf0 (diff)
downloadcdo-6c8f6dcd8276ad2f2fc983f6d792d9f215db6a94.zip
cdo-6c8f6dcd8276ad2f2fc983f6d792d9f215db6a94.tar.gz
cdo-6c8f6dcd8276ad2f2fc983f6d792d9f215db6a94.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/actions/StateAction.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/actions/StateAction.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/actions/StateAction.java
index b0c4040..ca73aab 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/actions/StateAction.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/actions/StateAction.java
@@ -8,6 +8,10 @@ import org.eclipse.net4j.internal.buddies.Self;
import org.eclipse.net4j.util.ui.actions.SafeAction;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IMenuCreator;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
/**
* @author Eike Stepper
@@ -42,6 +46,103 @@ public class StateAction extends SafeAction
}
}
+ public static class DropDownAction extends Action implements IMenuCreator
+ {
+ private Menu fMenu;
+
+ private StateAction availableAction = new AvailableAction();
+
+ private StateAction lonesomeAction = new LonesomeAction();
+
+ private StateAction awayAction = new AwayAction();
+
+ private StateAction doNotDisturbAction = new DoNotDisturbAction();
+
+ public DropDownAction()
+ {
+ setText("My Actions");
+ setMenuCreator(this);
+ }
+
+ public void dispose()
+ {
+ if (fMenu != null)
+ {
+ fMenu.dispose();
+ fMenu = null;
+ }
+ }
+
+ public void updateState()
+ {
+ availableAction.updateState();
+ lonesomeAction.updateState();
+ awayAction.updateState();
+ doNotDisturbAction.updateState();
+
+ IBuddySession session = IBuddiesManager.INSTANCE.getSession();
+ if (session != null)
+ {
+ setEnabled(true);
+ State state = session.getSelf().getState();
+ switch (state)
+ {
+ case AVAILABLE:
+ setImageDescriptor(availableAction.getImageDescriptor());
+ break;
+
+ case LONESOME:
+ setImageDescriptor(lonesomeAction.getImageDescriptor());
+ break;
+
+ case AWAY:
+ setImageDescriptor(awayAction.getImageDescriptor());
+ break;
+
+ case DO_NOT_DISTURB:
+ setImageDescriptor(doNotDisturbAction.getImageDescriptor());
+ break;
+ }
+ }
+ else
+ {
+ setImageDescriptor(availableAction.getImageDescriptor());
+ setEnabled(false);
+ }
+ }
+
+ public Menu getMenu(Control parent)
+ {
+ if (fMenu != null)
+ {
+ fMenu.dispose();
+ }
+
+ fMenu = new Menu(parent);
+ addActionToMenu(fMenu, availableAction);
+ addActionToMenu(fMenu, lonesomeAction);
+ addActionToMenu(fMenu, awayAction);
+ addActionToMenu(fMenu, doNotDisturbAction);
+ return fMenu;
+ }
+
+ public Menu getMenu(Menu parent)
+ {
+ return null;
+ }
+
+ @Override
+ public void run()
+ {
+ }
+
+ protected void addActionToMenu(Menu parent, Action action)
+ {
+ ActionContributionItem item = new ActionContributionItem(action);
+ item.fill(parent, -1);
+ }
+ }
+
public static final class AvailableAction extends StateAction
{
public AvailableAction()