Search in sources :

Example 1 with IEvaluationService

use of org.eclipse.ui.services.IEvaluationService in project translationstudio8 by heartsome.

the class ConcordanceSearchHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    if (!isEnabled()) {
        return null;
    }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            // IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
            IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
            ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
            List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
            if (lstDatabase.size() == 0) {
                MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
                return null;
            }
            String selectText = xliffEditor.getSelectPureText();
            if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
                selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
            } else if (selectText == null) {
                selectText = "";
            }
            String srcLang = xliffEditor.getSrcColumnName();
            String tgtLang = xliffEditor.getTgtColumnName();
            ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
            Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
            Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
            dialog.open();
            if (srcLangL.isBidi() || tgtLangL.isBidi()) {
                dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
            }
            if (selectText != null && !selectText.trim().equals("")) {
                dialog.initGroupIdAndSearch();
                IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
                ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
                Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
                IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
                IEvaluationContext currentState = evalService.getCurrentState();
                ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
                try {
                    command.executeWithChecks(executionEvent);
                } catch (Exception e1) {
                }
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ConcordanceSearchDialog(net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 2 with IEvaluationService

use of org.eclipse.ui.services.IEvaluationService in project yamcs-studio by yamcs.

the class CommandStackView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.verticalSpacing = 1;
    parent.setLayout(gl);
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    errorBackgroundColor = resourceManager.createColor(new RGB(255, 221, 221));
    bracketStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
        }
    };
    argNameStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
        }
    };
    numberStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
        }
    };
    errorStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
            textStyle.underline = true;
            textStyle.underlineColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
            textStyle.underlineStyle = SWT.UNDERLINE_ERROR;
        }
    };
    issuedStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
        }
    };
    skippedStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
            textStyle.strikeout = true;
            textStyle.strikeoutColor = textStyle.foreground;
        }
    };
    Composite tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    TableColumnLayout tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    commandTableViewer = new CommandStackTableViewer(tableWrapper, tcl, this);
    commandTableViewer.addDoubleClickListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            StackedCommand cmd = (StackedCommand) sel.getFirstElement();
            if (cmd.getStackedState() != StackedState.ISSUED && cmd.getStackedState() != StackedState.SKIPPED) {
                EditStackedCommandDialog dialog = new EditStackedCommandDialog(parent.getShell(), cmd);
                if (dialog.open() == Window.OK) {
                    refreshState();
                }
            }
        }
    });
    Composite controls = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 30;
    controls.setLayoutData(gd);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    controls.setLayout(gl);
    controls.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    Composite bottomLeft = new Composite(controls, SWT.NONE);
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.CENTER;
    bottomLeft.setLayoutData(gd);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    bottomLeft.setLayout(gl);
    messageLabel = new Label(bottomLeft, SWT.NONE);
    messageLabel.setText("");
    messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Composite bottomRight = new Composite(controls, SWT.NONE);
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.CENTER;
    gd.horizontalAlignment = SWT.RIGHT;
    bottomRight.setLayoutData(gd);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    bottomRight.setLayout(gl);
    armButton = new Button(bottomRight, SWT.TOGGLE);
    armButton.setText("1. Arm");
    armButton.setToolTipText("Arm the selected command");
    armButton.setEnabled(false);
    armButton.addListener(SWT.Selection, evt -> {
        if (armButton.getSelection()) {
            ICommandService commandService = (ICommandService) getViewSite().getService(ICommandService.class);
            IEvaluationService evaluationService = (IEvaluationService) getViewSite().getService(IEvaluationService.class);
            Command cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.arm");
            try {
                cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
            } catch (Exception e) {
                log.log(Level.SEVERE, "Could not execute command", e);
            }
        } else {
            CommandStack stack = CommandStack.getInstance();
            if (stack.getActiveCommand() != null && stack.getActiveCommand().isArmed()) {
                stack.getActiveCommand().setStackedState(StackedState.DISARMED);
            }
        }
    });
    issueButton = new Button(bottomRight, SWT.NONE);
    issueButton.setText("2. Issue");
    issueButton.setToolTipText("Issue the selected command");
    issueButton.setEnabled(false);
    issueButton.addListener(SWT.Selection, evt -> {
        ICommandService commandService = (ICommandService) getViewSite().getService(ICommandService.class);
        IEvaluationService evaluationService = (IEvaluationService) getViewSite().getService(IEvaluationService.class);
        Command cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issue");
        try {
            cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
        } catch (Exception e) {
            log.log(Level.SEVERE, "Could not execute command", e);
        }
    });
    commandTableViewer.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        updateMessagePanel(sel);
        CommandStack stack = CommandStack.getInstance();
        armButton.setSelection(false);
        stack.disarmArmed();
        if (sel.isEmpty() || !stack.isValid() || !sel.getFirstElement().equals(stack.getActiveCommand())) {
            armButton.setEnabled(false);
            issueButton.setEnabled(false);
        } else if (stack.hasRemaining()) {
            setButtonEnable(armButton, true);
        }
        refreshState();
    });
    getViewSite().setSelectionProvider(commandTableViewer);
    // Set up connection state, and listen to changes
    connectionStateProvider = RCPUtils.findSourceProvider(getViewSite(), ConnectionStateProvider.STATE_KEY_CONNECTED, ConnectionStateProvider.class);
    connectionStateProvider.addSourceProviderListener(new ISourceProviderListener() {

        @Override
        public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue) {
            refreshState();
        }

        @Override
        @SuppressWarnings("rawtypes")
        public void sourceChanged(int sourcePriority, Map sourceValuesByName) {
            refreshState();
        }
    });
    // Add the popup menu for pasting commands
    addPopupMenu();
    // Set initial state
    refreshState();
    CommandingCatalogue.getInstance().addCommandHistoryListener(cmdhistEntry -> {
        Display.getDefault().asyncExec(() -> processCommandHistoryEntry(cmdhistEntry));
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) HashMap(java.util.HashMap) ConnectionStateProvider(org.yamcs.studio.core.ui.connections.ConnectionStateProvider) ISourceProviderListener(org.eclipse.ui.ISourceProviderListener) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICommandService(org.eclipse.ui.commands.ICommandService) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TextStyle(org.eclipse.swt.graphics.TextStyle) Button(org.eclipse.swt.widgets.Button) Composite(org.eclipse.swt.widgets.Composite) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) RGB(org.eclipse.swt.graphics.RGB) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) GridData(org.eclipse.swt.layout.GridData) Styler(org.eclipse.jface.viewers.StyledString.Styler) HashMap(java.util.HashMap) Map(java.util.Map) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 3 with IEvaluationService

use of org.eclipse.ui.services.IEvaluationService in project translationstudio8 by heartsome.

the class NewProjectWizard method performFinish.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
@Override
public boolean performFinish() {
    final IProject project = firstPage.getProject();
    final List<String> srcFiles = srcFilesPage.getSrcFiles();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(Messages.getString("wizard.NewProjectWizard.task1"), 3);
            try {
                createProject(project, new SubProgressMonitor(monitor, 1));
                // // 获取源文件并复制到项目中
                if (srcFiles != null) {
                    copySourceFile(project, Constant.FOLDER_SRC, srcFiles, new SubProgressMonitor(monitor, 1));
                }
                initProjectConfig(project, new SubProgressMonitor(monitor, 1));
            } catch (CoreException e) {
                try {
                    project.delete(true, monitor);
                } catch (CoreException e1) {
                    logger.error(Messages.getString("wizard.NewProjectWizard.logger3"), e1);
                }
                logger.error(Messages.getString("wizard.NewProjectWizard.logger4"), e);
            }
            monitor.done();
        }
    };
    try {
        getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        logger.error("", e);
        return false;
    } catch (InterruptedException e) {
        logger.error("", e);
        return false;
    }
    // 创建项目成功后刷新导入/导出 RTF 功能的可用状态
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
    if (evaluationService != null) {
        evaluationService.requestEvaluation(RTFEnabledPropertyTester.PROPERTY_NAMESPACE + "." + RTFEnabledPropertyTester.PROPERTY_ENABLED);
    }
    if (srcFilesPage.isOpenConverter()) {
        convertImpl.openConverter(sourcefiles);
    }
    // 创建项目后刷新资源视图
    try {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
        try {
            project.delete(true, null);
        } catch (CoreException e1) {
            logger.error("", e1);
        }
        logger.error("", e);
    }
    return true;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IEvaluationService(org.eclipse.ui.services.IEvaluationService) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 4 with IEvaluationService

use of org.eclipse.ui.services.IEvaluationService in project translationstudio8 by heartsome.

the class NewHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    String parameter = event.getParameter("wizardParameter");
    Command command = null;
    ICommandService commandService = (ICommandService) HandlerUtil.getActiveSite(event).getService(ICommandService.class);
    if (parameter == null || parameter.equalsIgnoreCase("project")) {
        command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newProject");
    } else if (parameter.equalsIgnoreCase("folder")) {
        command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newFolder");
    } else if (parameter.equalsIgnoreCase("tm")) {
        command = commandService.getCommand("net.heartsome.cat.database.ui.tm.command.newTM");
    } else if (parameter.equalsIgnoreCase("tb")) {
        command = commandService.getCommand("net.heartsome.cat.database.ui.tb.command.newTB");
    }
    if (command == null) {
        return null;
    }
    IEvaluationService evalService = (IEvaluationService) HandlerUtil.getActiveSite(event).getService(IEvaluationService.class);
    IEvaluationContext currentState = evalService.getCurrentState();
    ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
    try {
        command.executeWithChecks(executionEvent);
    } catch (NotDefinedException e) {
        LOGGER.error("", e);
    } catch (NotEnabledException e) {
        LOGGER.error("", e);
    } catch (NotHandledException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : NotHandledException(org.eclipse.core.commands.NotHandledException) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ICommandService(org.eclipse.ui.commands.ICommandService) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 5 with IEvaluationService

use of org.eclipse.ui.services.IEvaluationService in project translationstudio8 by heartsome.

the class NattableUtil method refreshCommand.

/**
	 * 刷新 Command 的可用状态
	 * @param nameSpace
	 * @param properties
	 *            ;
	 */
public static void refreshCommand(String nameSpace, String properties) {
    if (nameSpace != null && properties != null) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
        if (evaluationService != null) {
            evaluationService.requestEvaluation(nameSpace + "." + properties);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Aggregations

IEvaluationService (org.eclipse.ui.services.IEvaluationService)10 Command (org.eclipse.core.commands.Command)5 ICommandService (org.eclipse.ui.commands.ICommandService)5 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)3 HashMap (java.util.HashMap)2 CoreException (org.eclipse.core.runtime.CoreException)2 ActionUI (eu.esdihumboldt.hale.ui.io.action.ActionUI)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)1 Language (net.heartsome.cat.common.locale.Language)1 ConcordanceSearchDialog (net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog)1 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 NotEnabledException (org.eclipse.core.commands.NotEnabledException)1 NotHandledException (org.eclipse.core.commands.NotHandledException)1 State (org.eclipse.core.commands.State)1