Search in sources :

Example 51 with IHandlerService

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) IHandlerService(org.eclipse.ui.handlers.IHandlerService) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IProduct(org.eclipse.core.runtime.IProduct)

Example 52 with IHandlerService

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);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IPerspectiveListener(org.eclipse.ui.IPerspectiveListener) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 53 with IHandlerService

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;
        }
    });
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) AbstractHandler(org.eclipse.core.commands.AbstractHandler)

Example 54 with IHandlerService

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);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IAction(org.eclipse.jface.action.IAction) IHandler(org.eclipse.core.commands.IHandler) IContextService(org.eclipse.ui.contexts.IContextService) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 55 with IHandlerService

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);
        }
    }
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) ISelection(org.eclipse.jface.viewers.ISelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException)

Aggregations

IHandlerService (org.eclipse.ui.handlers.IHandlerService)102 ActionHandler (org.eclipse.jface.commands.ActionHandler)44 Action (org.eclipse.jface.action.Action)41 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)25 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)18 Command (org.eclipse.core.commands.Command)17 ICommandService (org.eclipse.ui.commands.ICommandService)17 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 AbstractHandler (org.eclipse.core.commands.AbstractHandler)10 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)9 IHandler (org.eclipse.core.commands.IHandler)8 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)8 ArrayList (java.util.ArrayList)7 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IAction (org.eclipse.jface.action.IAction)7 IContextService (org.eclipse.ui.contexts.IContextService)7