use of org.eclipse.ui.handlers.IHandlerService in project netxms by netxms.
the class ExportFileBuilder method createActions.
/**
* Create actions
*/
private void createActions() {
final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
actionSave = new Action(Messages.get().ExportFileBuilder_Save, SharedIcons.SAVE) {
@Override
public void run() {
save();
}
};
// $NON-NLS-1$
actionSave.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.save_exported_config");
handlerService.activateHandler(actionSave.getActionDefinitionId(), new ActionHandler(actionSave));
actionPublish = new Action("&Publish...", Activator.getImageDescriptor("icons/publish.gif")) {
@Override
public void run() {
publish();
}
};
// $NON-NLS-1$
actionPublish.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.publish_config");
handlerService.activateHandler(actionPublish.getActionDefinitionId(), new ActionHandler(actionPublish));
}
use of org.eclipse.ui.handlers.IHandlerService in project eclipse-integration-commons by spring-projects.
the class ExtensionsEditor method createPartControl.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
* .Composite)
*/
@Override
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
Composite body = form.getBody();
body.setLayout(new GridLayout(5, false));
discoveryViewer = new DashboardDiscoveryViewer(getSite(), this);
initialize(discoveryViewer);
discoveryViewer.setDirectoryUrl(ResourceProvider.getUrl(RESOURCE_DISCOVERY_DIRECTORY).replace("%VERSION%", IdeUiUtils.getShortVersion()));
discoveryViewer.setShowConnectorDescriptorKindFilter(false);
discoveryViewer.createControl(body);
adaptRecursively(discoveryViewer.getControl(), toolkit);
GridDataFactory.fillDefaults().span(5, 1).grab(true, true).applyTo(discoveryViewer.getControl());
findUpdatesButton = toolkit.createButton(body, "&Find Updates", SWT.NONE);
findUpdatesButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
try {
handlerService.executeCommand("org.eclipse.equinox.p2.ui.sdk.update", new Event());
} catch (Exception e) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "Find updates failed with an unexpected error.", e), StatusManager.SHOW | StatusManager.LOG);
}
}
});
Hyperlink configureLink = toolkit.createHyperlink(body, "Configure Extensions...", SWT.NONE);
configureLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent event) {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), ID_PREFERENCE_PAGE, new String[] { ID_PREFERENCE_PAGE }, null);
dialog.open();
}
});
progressMonitorPart = new ProgressMonitorPart(body, null);
monitor.attach(progressMonitorPart);
progressMonitorPart.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
monitor.setCanceled(true);
monitor.detach(progressMonitorPart);
}
});
adaptRecursively(progressMonitorPart, toolkit);
GridDataFactory.fillDefaults().grab(true, false).applyTo(progressMonitorPart);
// Button refreshButton = toolkit.createButton(body, "Refresh",
// SWT.NONE);
// refreshButton.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// pane.updateDiscovery();
// }
// });
cancelButton = toolkit.createButton(body, "&Cancel", SWT.NONE);
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
cancelButton.setEnabled(false);
progressMonitorPart.setCanceled(true);
}
});
installButton = toolkit.createButton(body, "&Install", SWT.NONE);
installButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// check for conflicts
List<ConnectorDescriptor> selection = discoveryViewer.getInstallableConnectors();
IStatus conflictStatus = new MultiStatus(IdeUiPlugin.PLUGIN_ID, -1, new IStatus[] { checkForConflicts(SVN_FEATURES, " Please select only one SVN team provider.", selection), checkForConflicts(M2E_EXTENSION_IDS, " Please select only one m2e version to install.", selection) }, "Could not perform install due to conflicts.", null);
if (!conflictStatus.isOK()) {
StatusManager.getManager().handle(conflictStatus, StatusManager.SHOW | StatusManager.BLOCK);
return;
}
// now, if m2e is going to be installed, ensure that all other
// versions of m2e are uninstalled first.
Set<String> featuresToUninstall = chooseUnwantedFeatures(selection);
if (!featuresToUninstall.isEmpty()) {
IStatus uninstallResult = uninstallFeatures(featuresToUninstall);
if (!uninstallResult.isOK()) {
if (uninstallResult.getSeverity() != IStatus.CANCEL) {
StatusManager.getManager().handle(uninstallResult, StatusManager.SHOW | StatusManager.LOG | StatusManager.BLOCK);
}
return;
}
}
DiscoveryUi.install(discoveryViewer.getInstallableConnectors(), ExtensionsEditor.this);
}
private IStatus uninstallFeatures(final Set<String> featuresToUninstall) {
String allInstalled = findFeaturesToUninstall(featuresToUninstall, discoveryViewer.getInstalledFeatures());
if (allInstalled.length() == 0) {
return Status.OK_STATUS;
}
boolean res = MessageDialog.openQuestion(getEditorSite().getShell(), "Perform uninstall?", "In order to switch versions of m2eclipse, the following features will be uninstalled:\n" + allInstalled + "Do you want to continue?");
if (!res) {
return Status.CANCEL_STATUS;
}
// uninstall previous Maven tooling
AbstractInstallJob job = DiscoveryUi.createInstallJob();
try {
return job.uninstall(new UninstallRequest() {
/**
* Uninstall all features that are somehow related to
* m2eclipse
*/
@Override
public boolean select(@SuppressWarnings("rawtypes") InstalledItem item) {
String featureId = item.getId();
return isRelatedToM2e(featuresToUninstall, featureId);
}
}, new NullProgressMonitor());
} catch (Exception e) {
return new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, NLS.bind("Could not uninstall features:\n{0},\n try uninstalling manually.", featuresToUninstall), e);
}
}
private String findFeaturesToUninstall(Set<String> featuresToUninstall, Set<String> installedFeatures) {
StringBuilder sb = new StringBuilder();
for (String featureId : installedFeatures) {
if (isRelatedToM2e(featuresToUninstall, featureId)) {
if (featureId.endsWith(".feature.group")) {
featureId = featureId.substring(0, featureId.length() - ".feature.group".length());
}
sb.append(" " + featureId + "\n");
}
}
return sb.toString();
}
private Set<String> chooseUnwantedFeatures(List<ConnectorDescriptor> selection) {
boolean uninstallOld = false;
boolean uninstallNew = false;
for (ConnectorDescriptor feature : selection) {
// first and vice versa
if (feature.getId().equals(NEW_M2E_EXTENSION_ID)) {
uninstallOld = true;
} else if (feature.getId().equals(OLD_M2E_EXTENSION_ID)) {
uninstallNew = true;
}
}
Set<String> maybeUninstall;
if (uninstallOld) {
maybeUninstall = OLD_M2E_FEATURES;
} else if (uninstallNew) {
maybeUninstall = NEW_M2E_FEATURES;
} else {
maybeUninstall = Collections.emptySet();
}
Set<String> installedFeatures = ExtensionsEditor.this.discoveryViewer.getInstalledFeatures();
Set<String> definitelyUninstall = new HashSet<String>();
for (String feature : maybeUninstall) {
if (installedFeatures.contains(feature)) {
definitelyUninstall.add(feature);
}
}
if (definitelyUninstall.size() > 0) {
IdeUiPlugin.log(new Status(IStatus.INFO, IdeUiPlugin.PLUGIN_ID, "To make way for a new version of m2eclipse, we will uninstall these features: " + definitelyUninstall));
}
return definitelyUninstall;
}
/**
* This method checks for conflicts with requested installs. If a
* conflict is found, this method will pop up a dialog explaining
* the conflict and it will return true.
*
* @param featuresToCheck set of features of which only one can be
* installed at once.
* @param message message to add if there is an error
* @param selection
*
* @return true iff there is a conflict.
*/
public IStatus checkForConflicts(Set<String> featuresToCheck, String prependedMessage, List<ConnectorDescriptor> selection) {
StringBuilder message = new StringBuilder();
List<ConnectorDescriptor> conflicting = new ArrayList<ConnectorDescriptor>();
for (ConnectorDescriptor descriptor : selection) {
if (featuresToCheck.contains(descriptor.getId())) {
conflicting.add(descriptor);
if (message.length() > 0) {
message.append(", ");
}
message.append(descriptor.getName());
}
}
if (conflicting.size() > 1) {
return new Status(IStatus.WARNING, IdeUiPlugin.PLUGIN_ID, NLS.bind("The following extensions can not be installed at the same time: {0}.", message.toString()));
} else {
return Status.OK_STATUS;
}
}
});
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
if (form != null && !form.isDisposed()) {
discoveryViewer.updateDiscovery();
}
}
});
discoveryViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
installButton.setEnabled(discoveryViewer.isComplete());
}
});
}
use of org.eclipse.ui.handlers.IHandlerService in project bndtools by bndtools.
the class BndEditor method setupActions.
private void setupActions() {
String fileName = getFileAndProject(getEditorInput()).getFirst();
if (fileName.endsWith(LaunchConstants.EXT_BNDRUN)) {
final IHandlerService handlerSvc = (IHandlerService) getEditorSite().getService(IHandlerService.class);
final AbstractHandler handler = new AbstractHandler() {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
resolveRunBundles(new NullProgressMonitor(), false);
return null;
}
};
final IHandlerActivation activation = handlerSvc.activateHandler("bndtools.runEditor.resolve", handler);
this.resolveJobListener = new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
if (event.getJob() instanceof ResolveJob)
Display.getDefault().asyncExec(() -> handlerSvc.deactivateHandler(activation));
}
@Override
public void done(IJobChangeEvent event) {
if (event.getJob() instanceof ResolveJob)
Display.getDefault().asyncExec(() -> handlerSvc.activateHandler(activation));
}
};
Job.getJobManager().addJobChangeListener(resolveJobListener);
}
}
use of org.eclipse.ui.handlers.IHandlerService in project dbeaver by serge-rider.
the class AboutBoxDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Color background = JFaceColors.getBannerBackground(parent.getDisplay());
// Color foreground = JFaceColors.getBannerForeground(parent.getDisplay());
parent.setBackground(background);
Composite group = new Composite(parent, SWT.NONE);
group.setBackground(background);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 20;
layout.marginWidth = 20;
group.setLayout(layout);
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridData gd;
IProduct product = Platform.getProduct();
{
Label nameLabel = new Label(group, SWT.NONE);
nameLabel.setBackground(background);
nameLabel.setFont(NAME_FONT);
nameLabel.setText(product.getName());
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.CENTER;
nameLabel.setLayoutData(gd);
}
Label titleLabel = new Label(group, SWT.NONE);
titleLabel.setBackground(background);
titleLabel.setFont(TITLE_FONT);
titleLabel.setText(product.getProperty(PRODUCT_PROP_SUB_TITLE));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.CENTER;
titleLabel.setLayoutData(gd);
titleLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
@Override
public void run() {
// Do not create InstallationDialog directly
// but execute "org.eclipse.ui.help.installationDialog" command
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IHandlerService service = workbenchWindow.getService(IHandlerService.class);
if (service != null) {
try {
// $NON-NLS-1$
service.executeCommand("org.eclipse.ui.help.installationDialog", null);
} catch (Exception e1) {
// just ignore error
}
}
}
});
}
});
Label imageLabel = new Label(group, SWT.NONE);
imageLabel.setBackground(background);
gd = new GridData();
gd.verticalAlignment = GridData.BEGINNING;
gd.horizontalAlignment = GridData.CENTER;
gd.grabExcessHorizontalSpace = false;
imageLabel.setLayoutData(gd);
imageLabel.setImage(ABOUT_IMAGE);
Text versionLabel = new Text(group, SWT.NONE);
versionLabel.setEditable(false);
versionLabel.setBackground(background);
versionLabel.setText(CoreMessages.dialog_about_label_version + GeneralUtils.getProductVersion().toString());
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.CENTER;
versionLabel.setLayoutData(gd);
Label releaseTimeLabel = new Label(group, SWT.NONE);
releaseTimeLabel.setBackground(background);
releaseTimeLabel.setText("Release date: " + DateFormat.getDateInstance(DateFormat.LONG).format(GeneralUtils.getProductReleaseDate()));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.CENTER;
releaseTimeLabel.setLayoutData(gd);
Label authorLabel = new Label(group, SWT.NONE);
authorLabel.setBackground(background);
authorLabel.setText(product.getProperty(PRODUCT_PROP_COPYRIGHT));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.CENTER;
authorLabel.setLayoutData(gd);
Link siteLink = UIUtils.createLink(group, UIUtils.makeAnchor(product.getProperty(PRODUCT_PROP_WEBSITE)), new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIUtils.launchProgram(e.text);
}
});
siteLink.setBackground(background);
gd = new GridData();
gd.horizontalAlignment = GridData.CENTER;
siteLink.setLayoutData(gd);
String infoDetails = DBWorkbench.getPlatform().getApplication().getInfoDetails();
if (!CommonUtils.isEmpty(infoDetails)) {
Text extraText = new Text(group, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
extraText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
extraText.setText(infoDetails);
}
return parent;
}
use of org.eclipse.ui.handlers.IHandlerService in project dbeaver by dbeaver.
the class ActionUtils method runCommand.
public static void runCommand(String commandId, ISelection selection, Map<String, Object> parameters, IServiceLocator serviceLocator) {
if (commandId != null) {
try {
ICommandService commandService = serviceLocator.getService(ICommandService.class);
IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
boolean needContextPatch = false;
if (selection != null) {
needContextPatch = true;
if (serviceLocator instanceof IWorkbenchSite) {
final ISelection curSelection = ((IWorkbenchSite) serviceLocator).getSelectionProvider().getSelection();
if (curSelection instanceof IStructuredSelection && selection instanceof IStructuredSelection) {
if (((IStructuredSelection) curSelection).size() == ((IStructuredSelection) selection).size() && ((IStructuredSelection) curSelection).getFirstElement() == ((IStructuredSelection) selection).getFirstElement()) {
// The same selection
needContextPatch = false;
}
}
}
}
Parameterization[] parametrization = null;
if (!CommonUtils.isEmpty(parameters)) {
parametrization = new Parameterization[parameters.size()];
int paramIndex = 0;
for (Map.Entry<String, Object> param : parameters.entrySet()) {
IParameter parameter = command.getParameter(param.getKey());
if (parameter != null) {
parametrization[paramIndex] = new Parameterization(parameter, CommonUtils.toString(param.getValue()));
} else {
log.debug("Parameter '" + param.getKey() + "' not found in command '" + commandId + "'");
parametrization[paramIndex] = null;
}
paramIndex++;
}
}
if (selection != null && needContextPatch) {
// Create new eval context
IEvaluationContext context = new EvaluationContext(handlerService.createContextSnapshot(false), selection);
if (serviceLocator instanceof IWorkbenchPartSite) {
context.addVariable(ISources.ACTIVE_PART_NAME, ((IWorkbenchPartSite) serviceLocator).getPart());
}
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
ParameterizedCommand pc = new ParameterizedCommand(command, parametrization);
handlerService.executeCommandInContext(pc, null, context);
} else if (command != null) {
if (command.isEnabled()) {
ParameterizedCommand pc = new ParameterizedCommand(command, parametrization);
handlerService.executeCommand(pc, null);
} else {
log.warn("Command '" + commandId + "' is disabled");
}
} else {
log.warn("Command '" + commandId + "' not found");
}
}
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Error running command", "Can't execute command '" + commandId + "'", e);
}
}
}
Aggregations