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 translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method setListenerToPespective.
/**
* 给默认透视图添加监听,当透视图发生改变时,触发相关事件 robert 2012-10-18
* @param commandService
*/
private void setListenerToPespective(final ICommandService commandService) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IPerspectiveListener perspectiveListener = new IPerspectiveListener() {
public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
}
public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
// 改变透视图时,发出监听去检查品质检查结果视图的状态,从而让 视图 菜单的状态与之保持一致。
commandService.refreshElements("net.heartsome.cat.ts.ui.qa.handlers.OpenQAResultViewCommand", null);
// 显示状态栏与工具栏
IHandlerService handlerService = (IHandlerService) window.getService(IHandlerService.class);
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
boolean statusVisible = preferenceStore.getBoolean(TsPreferencesConstant.TS_statusBar_status);
if (!statusVisible) {
preferenceStore.setValue(TsPreferencesConstant.TS_statusBar_status, false);
try {
handlerService.executeCommand("net.heartsome.cat.ts.command.openStatusBar", null);
} catch (Exception ex) {
throw new RuntimeException("CommandTest.exitcommand not found");
}
}
WorkbenchWindow window_1 = (WorkbenchWindow) window;
if (!window_1.getCoolBarVisible()) {
try {
window_1.toggleToolbarVisibility();
commandService.refreshElements("net.heartsome.cat.ts.command.openToolBar", null);
} catch (Exception ex) {
throw new RuntimeException("CommandTest.exitcommand not found");
}
}
}
};
window.addPerspectiveListener(perspectiveListener);
}
use of org.eclipse.ui.handlers.IHandlerService in project dbeaver by serge-rider.
the class CheckForUpdateAction method deactivateStandardHandler.
public static void deactivateStandardHandler(IWorkbenchWindow window) {
if (p2UpdateHandlerActivation != null) {
return;
}
IHandlerService srv = window.getService(IHandlerService.class);
p2UpdateHandlerActivation = srv.activateHandler(CheckForUpdateAction.P2_UPDATE_COMMAND, new AbstractHandler() {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new CheckForUpdateAction().run();
return null;
}
});
}
use of org.eclipse.ui.handlers.IHandlerService in project tdi-studio-se by Talend.
the class BindingActions method registerActions.
/**
* DOC smallet Comment method "registerActions".
*/
private void registerActions() {
IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class);
//$NON-NLS-1$
contextService.activateContext("talend.global");
IWorkbench workbench = PlatformUI.getWorkbench();
IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
IHandler handler;
for (IAction action : actions) {
handler = new ActionHandler(action);
handlerService.activateHandler(action.getActionDefinitionId(), handler);
}
}
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, 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;
}
}
}
}
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, null);
handlerService.executeCommandInContext(pc, null, context);
} else if (command != null) {
if (command.isEnabled()) {
handlerService.executeCommand(commandId, null);
} else {
log.warn("Command '" + commandId + "' is disabled");
}
} else {
log.warn("Command '" + commandId + "' not found");
}
}
} catch (Exception e) {
log.error("Can't execute command '" + commandId + "'", e);
}
}
}
Aggregations