Search in sources :

Example 1 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite 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 IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project xtext-eclipse by eclipse.

the class HierarchyTreeContentProvider method inputChanged.

@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
    if ((viewer instanceof AbstractTreeViewer)) {
        IWorkbenchPartSite _site = this.viewPart.getSite();
        DeferredTreeContentManager _deferredTreeContentManager = new DeferredTreeContentManager(((AbstractTreeViewer) viewer), _site);
        this.deferredTreeContentManager = _deferredTreeContentManager;
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DeferredTreeContentManager(org.eclipse.ui.progress.DeferredTreeContentManager) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer)

Example 3 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project xtext-eclipse by eclipse.

the class ImportsAwareClipboardAction method getShell.

private Shell getShell() {
    ITextEditor editor = getTextEditor();
    if (editor != null) {
        IWorkbenchPartSite site = editor.getSite();
        Shell shell = site.getShell();
        if (shell != null && !shell.isDisposed()) {
            return shell;
        }
    }
    return null;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Shell(org.eclipse.swt.widgets.Shell) ITextEditor(org.eclipse.ui.texteditor.ITextEditor)

Example 4 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project xtext-eclipse by eclipse.

the class HighlightingReconciler method getDisplay.

private Display getDisplay() {
    XtextEditor editor = this.editor;
    if (editor == null) {
        if (sourceViewer != null)
            return sourceViewer.getControl().getDisplay();
        return null;
    }
    IWorkbenchPartSite site = editor.getSite();
    if (site == null)
        return null;
    Shell shell = site.getShell();
    if (shell == null || shell.isDisposed())
        return null;
    Display display = shell.getDisplay();
    if (display == null || display.isDisposed())
        return null;
    return display;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Shell(org.eclipse.swt.widgets.Shell) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Display(org.eclipse.swt.widgets.Display)

Example 5 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project cubrid-manager by CUBRID.

the class CUBRIDTextEditor method createPartControl.

/**
	 * Create Part Controls.
	 *
	 * @param parent composite.
	 */
public void createPartControl(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout());
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    initTextViewer(composite);
    undoManager.connect(textViewer);
    createActions();
    updateActions();
    //create context menu
    MenuManager contextMenuManager = new MenuManager("#PopupMenu", "CUBRIDTExtEditorContextMenu");
    contextMenuManager.setRemoveAllWhenShown(true);
    contextMenuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            createContextMenu(manager);
        }
    });
    Menu contextMenu = contextMenuManager.createContextMenu(textViewer.getTextWidget());
    textViewer.getTextWidget().setMenu(contextMenu);
    IWorkbenchPartSite site = getSite();
    site.registerContextMenu(contextMenuManager, textViewer);
    site.setSelectionProvider(textViewer);
    textViewer.getTextWidget().addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent event) {
            hookRetargetActions();
        }

        public void focusLost(FocusEvent event) {
            unHookRetargetActions();
        }
    });
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) FillLayout(org.eclipse.swt.layout.FillLayout) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) IMenuListener(org.eclipse.jface.action.IMenuListener)

Aggregations

IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)73 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)13 ISelection (org.eclipse.jface.viewers.ISelection)12 IEditorPart (org.eclipse.ui.IEditorPart)12 ArrayList (java.util.ArrayList)10 MenuManager (org.eclipse.jface.action.MenuManager)9 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 Composite (org.eclipse.swt.widgets.Composite)9 Display (org.eclipse.swt.widgets.Display)9 Shell (org.eclipse.swt.widgets.Shell)9 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)9 Menu (org.eclipse.swt.widgets.Menu)7 IEditorSite (org.eclipse.ui.IEditorSite)7 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)7 SWT (org.eclipse.swt.SWT)6 PartInitException (org.eclipse.ui.PartInitException)6 List (java.util.List)5 IToolBarManager (org.eclipse.jface.action.IToolBarManager)4 Separator (org.eclipse.jface.action.Separator)4