Search in sources :

Example 71 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tmdm-studio-se by Talend.

the class RepositoryResourceUtil method closeEditor.

public static void closeEditor(IEditorReference ref, boolean save) {
    if (ref != null) {
        IEditorReference[] editorRefs = new IEditorReference[] { ref };
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        activePage.closeEditors(editorRefs, save);
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 72 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tmdm-studio-se by Talend.

the class AddBrowseItemsWizardR method newBrowseItemView.

@Override
protected void newBrowseItemView(String browseItem) {
    if (toRecreateBrowserView(browseItem)) {
        IRepositoryViewObject viewObject = RepositoryResourceUtil.findViewObjectByName(IServerObjectRepositoryType.TYPE_VIEW, browseItem);
        if (viewObject != null) {
            IEditorReference ref = RepositoryResourceUtil.isOpenedInEditor(viewObject);
            if (ref != null) {
                RepositoryResourceUtil.closeEditor(ref, false);
            }
            try {
                ProxyRepositoryFactory.getInstance().deleteObjectPhysical(viewObject);
            } catch (PersistenceException e) {
                log.error(e.getMessage(), e);
                return;
            }
        }
        for (XSDElementDeclaration decl : declList) {
            String fullName = BROWSE_ITEMS + decl.getName();
            if (browseItem.equals(fullName) || browseItem.startsWith(fullName + "#")) {
                // $NON-NLS-1$
                try {
                    newViewAction.setXSDElementDeclaration(decl);
                    newViewAction.createNewView(browseItem);
                } catch (Exception e) {
                    // $NON-NLS-1$
                    log.error("Error occurred when generating default view " + browseItem, e);
                }
            }
        }
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 73 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tmdm-studio-se by Talend.

the class JobResourceListener method isOpenInEditor.

private boolean isOpenInEditor(IRepositoryViewObject vObj) {
    if (!ProxyRepositoryFactory.getInstance().isFullLogonFinished()) {
        return false;
    }
    if (PlatformUI.getWorkbench() == null || PlatformUI.getWorkbench().getActiveWorkbenchWindow() == null || PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() == null) {
        return false;
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] editorReferences = activePage.getEditorReferences();
    for (IEditorReference ref : editorReferences) {
        String editorId = ref.getId();
        if (ref != null && JOB_EDITOR_ID.equals(editorId)) {
            try {
                IEditorInput editorInput = ref.getEditorInput();
                if (editorInput instanceof RepositoryEditorInput) {
                    Item item = ((RepositoryEditorInput) editorInput).getItem();
                    if (item != null && item.equals(vObj.getProperty().getItem())) {
                        return true;
                    }
                }
            } catch (PartInitException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    return false;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IEditorReference(org.eclipse.ui.IEditorReference) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 74 with IEditorReference

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

the class CodePropertyEditorRenderer method createContents.

@Override
protected void createContents(Composite parent) {
    PropertyEditorPart part = getPart();
    Composite scriptEditorParent = createMainComposite(parent, new CreateMainCompositeDelegate(part) {

        @Override
        public boolean canScaleVertically() {
            return true;
        }
    });
    context.adapt(scriptEditorParent);
    int textFieldParentColumns = 1;
    SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
    boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
    if (actionsToolBarNeeded || true)
        textFieldParentColumns++;
    scriptEditorParent.setLayout(glayout(textFieldParentColumns, 0, 0, 0, 0));
    Composite nestedComposite = new Composite(scriptEditorParent, SWT.NONE);
    nestedComposite.setLayoutData(gdfill());
    nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
    this.context.adapt(nestedComposite);
    PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
    decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
    decorator.addEditorControl(nestedComposite);
    /*
		 * scriptEditorParent.setLayout( new FillLayout( SWT.HORIZONTAL ) );
		 * scriptEditorParent.setLayoutData( gdhhint( gdfill(), 300 ) );
		 */
    PropertyEditorInput editorInput = new PropertyEditorInput(part.getLocalModelElement(), (ValueProperty) part.getProperty());
    try {
        ScriptLanguageType scriptLang = context.getPart().getLocalModelElement().nearest(IScriptable.class).getScriptLanguage().getContent(false);
        String fileName = scriptLang.getClass().getField(scriptLang.toString()).getAnnotation(DefaultValue.class).text();
        IContentDescription contentDescription = ContentTypeManager.getInstance().getDescriptionFor(editorInput.getStorage().getContents(), fileName, IContentDescription.ALL);
        EditorDescriptor defaultEditor = (EditorDescriptor) PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(editorInput.getName(), contentDescription.getContentType());
        _textEditor = (ITextEditor) defaultEditor.createEditor();
    } catch (Exception e1) {
    }
    IEditorReference ref = new ScriptEditorReference(_textEditor, editorInput);
    IEditorSite site = new ScriptEditorSite(ref, _textEditor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
    try {
        _textEditor.init(site, editorInput);
        _textEditor.getDocumentProvider().getDocument(editorInput).addDocumentListener(new IDocumentListener() {

            public void documentAboutToBeChanged(DocumentEvent event) {
            }

            public void documentChanged(DocumentEvent event) {
                String content = event.getDocument().get();
                part.getLocalModelElement().write(((ValueProperty) part.getProperty()), content);
            }
        });
        ModelPropertyListener modelListener = new ModelPropertyListener() {

            @Override
            public void handlePropertyChangedEvent(ModelPropertyChangeEvent event) {
                CodePropertyEditorRenderer.this.textEditor.getDocumentProvider().getDocument(editorInput).set(part.getLocalModelElement().read(getProperty()).getText());
            }
        };
        part.getLocalModelElement().addListener(modelListener, part.getProperty().getName());
    } catch (PartInitException pie) {
        pie.printStackTrace();
    }
    Control[] prevChildren = scriptEditorParent.getChildren();
    // _textEditor.createPartControl( scriptEditorParent );
    new Label(scriptEditorParent, SWT.NONE);
    Control[] newChildren = scriptEditorParent.getChildren();
    decorator.addEditorControl(newChildren[prevChildren.length], true);
    if (actionsToolBarNeeded) {
        ToolBar toolbar = new ToolBar(scriptEditorParent, SWT.FLAT | SWT.HORIZONTAL);
        toolbar.setLayoutData(gdvfill());
        toolBarActionsPresentation.setToolBar(toolbar);
        toolBarActionsPresentation.render();
        context.adapt(toolbar);
        decorator.addEditorControl(toolbar);
    // relatedControls.add( toolbar );
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) DefaultValue(org.eclipse.sapphire.modeling.annotations.DefaultValue) Control(org.eclipse.swt.widgets.Control) IEditorReference(org.eclipse.ui.IEditorReference) PartInitException(org.eclipse.ui.PartInitException) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) PropertyEditorPart(org.eclipse.sapphire.ui.PropertyEditorPart) ModelPropertyChangeEvent(org.eclipse.sapphire.modeling.ModelPropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) PartInitException(org.eclipse.ui.PartInitException) SapphireToolBarActionPresentation(org.eclipse.sapphire.ui.swt.renderer.SapphireToolBarActionPresentation) ModelPropertyListener(org.eclipse.sapphire.modeling.ModelPropertyListener) ToolBar(org.eclipse.swt.widgets.ToolBar) IEditorSite(org.eclipse.ui.IEditorSite)

Example 75 with IEditorReference

use of org.eclipse.ui.IEditorReference in project eclipse-cs by checkstyle.

the class CheckFileOnOpenPartListener method getEditorFile.

/**
 * Returns the file behind the referenced workbench part.
 *
 * @param partRef
 *          the workbench part in question
 * @return the editors file or <code>null</code> if the workbench part is no file based editor
 */
private IFile getEditorFile(IWorkbenchPartReference partRef) {
    if (!(partRef instanceof IEditorReference)) {
        return null;
    }
    IFile file = null;
    // fix for 3522695
    IWorkbenchPart part = partRef.getPart(false);
    // do *NOT* restore the part here to prevent startup issues with large
    // number of opened files
    // instead use a different path the rip the input file reference
    IEditorInput input = null;
    if (part != null && part instanceof IEditorPart) {
        IEditorPart editor = (IEditorPart) part;
        input = editor.getEditorInput();
    } else {
        // fix for 3522695 - rip input file from editor ref without initializing
        // the actual part
        IEditorReference editRef = (IEditorReference) partRef;
        input = getRestoredInput(editRef);
    }
    if (input instanceof FileEditorInput) {
        file = ((FileEditorInput) input).getFile();
    }
    return file;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10