Search in sources :

Example 6 with IEditorSite

use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.

the class EditWorkflowDefinitionAction method perform.

@Override
public void perform(Object entry) {
    if (entry instanceof WorkflowDefinitionEntry) {
        WorkflowDefinitionEntry workflowEntry = (WorkflowDefinitionEntry) entry;
        IWorkbench workBench = PlatformUI.getWorkbench();
        IWorkbenchWindow wbWindow = workBench.getActiveWorkbenchWindow();
        IWorkbenchPage page = wbWindow.getActivePage();
        IEditorPart[] dirtyEditors = page.getDirtyEditors();
        for (IEditorPart dirtyEditor : dirtyEditors) {
            IEditorInput editorInput = dirtyEditor.getEditorInput();
            if (editorInput instanceof WorkflowDefinitionEditorInput) {
                WorkflowDefinitionEditorInput dirtyWorkflowEditorInput = (WorkflowDefinitionEditorInput) editorInput;
                boolean opened = dirtyWorkflowEditorInput.getName().contains(workflowEntry.getName());
                if (opened) {
                    IEditorSite editorSite = dirtyEditor.getEditorSite();
                    boolean saveOld = MessageDialog.openQuestion(editorSite.getShell(), "Save " + dirtyWorkflowEditorInput.getName(), "Do you want to save contents of this editor?");
                    page.closeEditor(dirtyEditor, saveOld);
                }
            }
        }
        try {
            WorkflowDefinitionEditorInput editorInput = new WorkflowDefinitionEditorInput(workflowEntry);
            IEditorPart editor = page.openEditor(editorInput, WorkflowDefinitionEditor.EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT);
            editor.addPropertyListener(new IPropertyListener() {

                public void propertyChanged(Object source, int propId) {
                    if (source.equals(editor) && (propId == WorkflowDefinitionEditor.propUpdateVersion)) {
                        workflowEntry.getParent().clearCache();
                        ((CommonViewer) EditWorkflowDefinitionAction.this.getSelectionProvider()).refresh(true);
                    }
                }
            });
        } catch (PartInitException pie) {
            KaleoUI.logError("Error opening kaleo workflow editor.", pie);
        }
    }
}
Also used : WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) IPropertyListener(org.eclipse.ui.IPropertyListener) IWorkbench(org.eclipse.ui.IWorkbench) WorkflowDefinitionEditorInput(com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IEditorSite(org.eclipse.ui.IEditorSite)

Example 7 with IEditorSite

use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.

the class EditorSiteAdapterService method convert.

@Override
public <A> A convert(Object object, Class<A> adapterType) {
    A retval = null;
    if (IEditorSite.class.equals(adapterType)) {
        SapphirePart sapphirePart = context(SapphirePart.class);
        Element localElement = sapphirePart.getLocalModelElement();
        ITextEditor editor = localElement.adapt(ITextEditor.class);
        IWorkbenchPartSite editorSite = editor.getSite();
        if (editorSite instanceof IEditorSite) {
            retval = adapterType.cast(editorSite);
        }
    }
    return retval;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Element(org.eclipse.sapphire.Element) SapphirePart(org.eclipse.sapphire.ui.SapphirePart) IEditorSite(org.eclipse.ui.IEditorSite)

Example 8 with IEditorSite

use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.

the class ScriptPropertyEditorRenderer method createContents.

@Override
protected void createContents(Composite parent) {
    PropertyEditorPart part = part();
    Element element = part.getLocalModelElement();
    ValueProperty property = part.property().nearest(ValueProperty.class);
    CreateMainCompositeDelegate createMainCompositeDelegate = new CreateMainCompositeDelegate(part) {

        @Override
        public boolean canScaleVertically() {
            return true;
        }
    };
    Composite codeEditorParent = createMainComposite(parent, createMainCompositeDelegate);
    // context.adapt( codeEditorParent );
    int codeEditorParentColumns = 1;
    SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
    boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
    if (actionsToolBarNeeded) {
        codeEditorParentColumns++;
    }
    codeEditorParent.setLayout(glayout(codeEditorParentColumns, 0, 0, 0, 0));
    Composite nestedComposite = new Composite(codeEditorParent, SWT.NONE);
    nestedComposite.setLayoutData(gdfill());
    // nestedComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
    addControl(nestedComposite);
    PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
    decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
    decorator.addEditorControl(nestedComposite);
    ScriptPropertyEditorInput editorInput = new ScriptPropertyEditorInput(element, property);
    List<Control> relatedControls = new ArrayList<>();
    try {
        IEditorSite editorSite = part().adapt(IEditorSite.class);
        _editorPart = createEditorPart(editorInput, editorSite);
        _editorPart.createPartControl(nestedComposite);
        Control editorControl = _editorPart.getAdapter(Control.class);
        // need to find the first child of nestedComposite to relayout
        // editor control
        Composite editorControlParent = null;
        Control control = editorControl;
        while ((editorControlParent == null) && (control != null) && !nestedComposite.equals(control.getParent())) {
            control = control.getParent();
        }
        nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
        control.setLayoutData(gdfill());
        decorator.addEditorControl(editorControl, true);
        editorControl.setData(RELATED_CONTROLS, relatedControls);
    } catch (Exception e) {
        KaleoUI.logError(e);
    }
    if (actionsToolBarNeeded) {
        ToolBar toolbar = new ToolBar(codeEditorParent, SWT.FLAT | SWT.HORIZONTAL);
        toolbar.setLayoutData(gdvfill());
        toolBarActionsPresentation.setToolBar(toolbar);
        toolBarActionsPresentation.render();
        addControl(toolbar);
        decorator.addEditorControl(toolbar);
        relatedControls.add(toolbar);
    }
    List<Class<?>> listenerClasses = part.getRenderingHint(PropertyEditorDef.HINT_LISTENERS, Collections.<Class<?>>emptyList());
    List<ValuePropertyEditorListener> listeners = new ArrayList<>();
    if (ListUtil.isNotEmpty(listenerClasses)) {
        for (Class<?> cl : listenerClasses) {
            try {
                ValuePropertyEditorListener listener = (ValuePropertyEditorListener) cl.newInstance();
                listener.initialize(this);
                listeners.add(listener);
            } catch (Exception e) {
                KaleoUI.logError(e);
            }
        }
    }
    ITextEditor textEditor = null;
    if (_editorPart instanceof ITextEditor) {
        textEditor = (ITextEditor) _editorPart;
    } else {
        ITextEditor textEdit = _editorPart.getAdapter(ITextEditor.class);
        textEditor = textEdit;
    }
    addControl((Control) textEditor.getAdapter(Control.class));
    IDocumentListener documentListener = new IDocumentListener() {

        public void documentAboutToBeChanged(DocumentEvent event) {
        }

        public void documentChanged(DocumentEvent event) {
            Value<Object> elementProperty = element.property(property);
            elementProperty.write(event.getDocument().get());
            if (ListUtil.isNotEmpty(listeners)) {
                for (ValuePropertyEditorListener listener : listeners) {
                    try {
                        listener.handleValueChanged();
                    } catch (Exception e) {
                        KaleoUI.logError(e);
                    }
                }
            }
        }
    };
    IDocumentProvider documentProvider = textEditor.getDocumentProvider();
    IDocument document = documentProvider.getDocument(_editorPart.getEditorInput());
    document.addDocumentListener(documentListener);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Element(org.eclipse.sapphire.Element) ArrayList(java.util.ArrayList) ValueProperty(org.eclipse.sapphire.ValueProperty) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) ValuePropertyEditorListener(org.eclipse.sapphire.ui.listeners.ValuePropertyEditorListener) Control(org.eclipse.swt.widgets.Control) PropertyEditorPart(org.eclipse.sapphire.ui.forms.PropertyEditorPart) Composite(org.eclipse.swt.widgets.Composite) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) SapphireToolBarActionPresentation(org.eclipse.sapphire.ui.forms.swt.SapphireToolBarActionPresentation) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) IEditorSite(org.eclipse.ui.IEditorSite) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with IEditorSite

use of org.eclipse.ui.IEditorSite in project webtools.sourceediting by eclipse.

the class AddImportHandler method execute.

/* (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IEditorSite site = HandlerUtil.getActiveEditor(event).getEditorSite();
    final ISelectionProvider provider = site.getSelectionProvider();
    final ISelection selection = provider != null ? provider.getSelection() : null;
    if (selection instanceof IStructuredSelection && selection instanceof ITextSelection) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        final int offset = ((ITextSelection) selection).getOffset();
        final Object firstElement = structuredSelection.getFirstElement();
        if (firstElement instanceof IDOMNode) {
            final IDOMModel model = ((IDOMNode) firstElement).getModel();
            INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class);
            if (adapter != null) {
                JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
                final JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
                translation.reconcileCompilationUnit();
                final ICompilationUnit cu = translation.getCompilationUnit();
                CompilationUnit astRoot = SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_YES, null);
                if (astRoot != null) {
                    final ASTNode node = NodeFinder.perform(astRoot, translation.getJavaOffset(offset), 0);
                    if (node != null) {
                        SimpleName name = null;
                        if (node.getNodeType() == ASTNode.SIMPLE_NAME) {
                            name = (SimpleName) node;
                        } else if (node.getNodeType() == ASTNode.QUALIFIED_NAME) {
                            name = ((QualifiedName) node).getName();
                        }
                        if (name != null) {
                            IBinding binding = name.resolveBinding();
                            if (binding instanceof ITypeBinding && (binding.getJavaElement() == null || !binding.getJavaElement().exists())) {
                                // Look it up!
                                ITypeBinding typeBinding = (ITypeBinding) binding;
                                final IImportContainer importContainer = cu.getImportContainer();
                                if (!importContainer.getImport(typeBinding.getQualifiedName()).exists()) {
                                    final List typesFound = new ArrayList();
                                    final TypeNameMatchRequestor collector = new TypeNameMatcher(typesFound);
                                    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { cu.getJavaProject() });
                                    final int mode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
                                    try {
                                        new SearchEngine().searchAllTypeNames(null, mode, name.getIdentifier().toCharArray(), mode, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
                                        final int length = typesFound.size();
                                        final List elements = new ArrayList();
                                        for (int i = 0; i < length; i++) {
                                            final TypeNameMatch match = (TypeNameMatch) typesFound.get(i);
                                            final int modifiers = match.getModifiers();
                                            if (!Flags.isPrivate(modifiers) && !Flags.isPackageDefault(modifiers)) {
                                                elements.add(match);
                                            }
                                        }
                                        TypeNameMatch match = null;
                                        // If there's only one match, insert it; otherwise, open the dialog to choose from the list
                                        if (elements.size() == 1) {
                                            match = (TypeNameMatch) elements.get(0);
                                        } else if (elements.size() > 1) {
                                            ElementListSelectionDialog dialog = new ElementListSelectionDialog(site.getShell(), LABEL_PROVIDER);
                                            dialog.setElements(elements.toArray(new TypeNameMatch[elements.size()]));
                                            dialog.setTitle(JSPUIMessages.AddImportHandler_title);
                                            dialog.setMessage(JSPUIMessages.AddImportHandler_label);
                                            if (dialog.open() == Window.OK) {
                                                final Object result = dialog.getFirstResult();
                                                if (result instanceof TypeNameMatch) {
                                                    match = (TypeNameMatch) result;
                                                }
                                            }
                                        }
                                        addImport(match, model.getStructuredDocument());
                                    } catch (JavaModelException e) {
                                        // $NON-NLS-1$
                                        Logger.logException("Exception while determining import.", e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) JavaModelException(org.eclipse.jdt.core.JavaModelException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) TypeNameMatchRequestor(org.eclipse.jdt.core.search.TypeNameMatchRequestor) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IImportContainer(org.eclipse.jdt.core.IImportContainer) ISelection(org.eclipse.jface.viewers.ISelection) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ArrayList(java.util.ArrayList) List(java.util.List) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) ITextSelection(org.eclipse.jface.text.ITextSelection) TypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) IEditorSite(org.eclipse.ui.IEditorSite)

Example 10 with IEditorSite

use of org.eclipse.ui.IEditorSite in project webtools.sourceediting by eclipse.

the class XSDMultiPageEditorContributor method setActivePage.

/*
   * (non-JavaDoc) Method declared in
   * AbstractMultiPageEditorActionBarContributor.
   */
public void setActivePage(IEditorPart part) {
    if (activeEditorPart == part)
        return;
    activeEditorPart = part;
    IActionBars actionBars = getActionBars();
    boolean isSource = false;
    if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
        isSource = true;
        zoomInRetargetAction.setEnabled(false);
        zoomOutRetargetAction.setEnabled(false);
        captureScreenAction.setEnabled(false);
        activateSourcePage(activeEditorPart, true);
    } else {
        activateSourcePage(xsdEditor, false);
        if (part instanceof InternalXSDMultiPageEditor) {
            xsdEditor = (InternalXSDMultiPageEditor) part;
        }
        if (xsdEditor != null) {
            // cs: here's we ensure the UNDO and REDO actions are available when
            // the design view is active
            IWorkbenchPartSite site = xsdEditor.getSite();
            if (site instanceof IEditorSite) {
                ITextEditor textEditor = xsdEditor.getTextEditor();
                IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
                siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
                siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
                siteActionBars.updateActionBars();
            }
            Object adapter = xsdEditor.getAdapter(ActionRegistry.class);
            if (adapter instanceof ActionRegistry) {
                ActionRegistry registry = (ActionRegistry) adapter;
                actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), registry.getAction(DeleteAction.ID));
                actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_IN, registry.getAction(GEFActionConstants.ZOOM_IN));
                actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_OUT, registry.getAction(GEFActionConstants.ZOOM_OUT));
                actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(), registry.getAction(ActionFactory.PRINT.getId()));
                actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), registry.getAction(ActionFactory.SELECT_ALL.getId()));
                zoomInRetargetAction.setEnabled(true);
                zoomOutRetargetAction.setEnabled(true);
                captureScreenAction.setEnabled(true);
            }
        }
    }
    if (actionBars != null) {
        // update menu bar and tool bar
        actionBars.updateActionBars();
    }
    if (zoomComboContributionItem != null) {
        zoomComboContributionItem.setVisible(!isSource);
        zoomComboContributionItem.update();
        // Bug 254772 - parent contribution manager should not be null.  We added this item already.
        // Force the ToolBarManager to update/redraw the items
        zoomComboContributionItem.getParent().update(true);
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry) IActionBars(org.eclipse.ui.IActionBars) IEditorSite(org.eclipse.ui.IEditorSite)

Aggregations

IEditorSite (org.eclipse.ui.IEditorSite)26 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)7 List (java.util.List)5 Control (org.eclipse.swt.widgets.Control)5 IEditorPart (org.eclipse.ui.IEditorPart)5 PartInitException (org.eclipse.ui.PartInitException)5 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 StyledText (org.eclipse.swt.custom.StyledText)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 DBPIdentifierCase (org.jkiss.dbeaver.model.DBPIdentifierCase)4