Slide 74
Slide 74 text
74
Commands - M. Baron - Page
mickael-baron.fr mickaelbaron
Aller plus loin avec menuContribution : control
Exemple (suite) : création d’un élément personnalisé dans
une barre d’outils
public class WorkbenchWindowCustomControlContribution extends WorkbenchWindowControlContribution {
protected Control createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Label label = new Label(composite, SWT.NONE);
label.setText("Click");
Button button = new Button(composite, SWT.PUSH);
button.setText("Call");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IHandlerService hs = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
try {
hs.executeCommand("eclipse.workbench.commandsexample.firstcommand", null);
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
return composite;
}
}
WorkbenchWindowCustomControlContribution.java
du projet CommandsExamples
Composants SWT
Déclenchement d’une commande