1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
package icmp.agent;
import interfaces.ICommandConstant;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import actions.ConfigurationAction;
import actions.StartAction;
import actions.StopAction;
import views.AboutJNetmon;
import views.QuitJNetmon;
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private static final String IMG_START = "/icons/start.gif";
private static final String IMG_STOP = "/icons/stop.gif";
private static final String IMG_CONFIG = "/icons/config.gif";
private IWorkbenchAction exitAction;
private IWorkbenchAction aboutAction;
private Action startAction;
private Action stopAction;
private Action configurationAction;
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}
protected void makeActions(IWorkbenchWindow window) {
// Exit
ActionFactory quit = new ActionFactory("quite") {//$NON-NLS-1$
public IWorkbenchAction create(IWorkbenchWindow window) {
if (window == null) {
throw new IllegalArgumentException();
}
IWorkbenchAction action = new QuitJNetmon(window);
action.setId(getId());
return action;
}
};
exitAction = quit.create(window);
exitAction.setText("Exit");
register(exitAction);
// start
startAction = new StartAction(ICommandConstant.CMD_START);
startAction.setDescription("Start");
startAction.setImageDescriptor(Activator
.getImageDescriptor(IMG_START));
register(startAction);
// configuration
stopAction = new StopAction(ICommandConstant.CMD_STOP);
stopAction.setDescription("Stop");
stopAction.setImageDescriptor(Activator
.getImageDescriptor(IMG_STOP));
register(stopAction);
// configuration
configurationAction = new ConfigurationAction(window);
configurationAction.setDescription("Configuration");
configurationAction.setImageDescriptor(Activator
.getImageDescriptor(IMG_CONFIG));
register(configurationAction);
// about
ActionFactory about = new ActionFactory("about") {//$NON-NLS-1$
public IWorkbenchAction create(IWorkbenchWindow window) {
if (window == null) {
throw new IllegalArgumentException();
}
IWorkbenchAction action = new AboutJNetmon(window);
action.setId(getId());
return action;
}
};
aboutAction = about.create(window);
aboutAction.setText("About");
aboutAction.setImageDescriptor(Activator
.getImageDescriptor("/icons/about.ico"));
register(aboutAction);
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager fileMenu = new MenuManager("&File",
IWorkbenchActionConstants.M_FILE);
menuBar.add(fileMenu);
fileMenu.add(configurationAction);
fileMenu.add(new Separator());
fileMenu.add(exitAction);
menuBar.add(new GroupMarker("additions"));
MenuManager helpMenu = new MenuManager("&Help",
IWorkbenchActionConstants.M_HELP);
menuBar.add(helpMenu);
helpMenu.add(aboutAction);
}
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.BOTTOM);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
toolbar.add(startAction);
toolbar.add(stopAction);
toolbar.add(configurationAction);
}
} |
Partager