Search in sources :

Example 1 with AbstractItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput in project tdq-studio-se by Talend.

the class WorkbenchUtils method closeAndOpenEditor.

/**
 * close and open the editors same method {@link CorePlugin}.getDefault().itemIsOpening() MOD TDQ-8360 20140410
 * yyin: will only operate the analysis who is related and has opened (by its observer --added when opening)
 *
 * @param iEditorReference
 */
private static void closeAndOpenEditor(List<IEditorReference> iEditorReference) {
    // Refresh current opened editors.
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPartReference activePartReference = activePage.getActivePartReference();
    // MOD qiongli 2011-9-8 TDQ-3317.when focucs on DI perspective,don't refresh the open editors
    DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
    if (findView == null) {
        return;
    }
    if (iEditorReference.size() > 0) {
        try {
            for (IEditorReference editorRef : iEditorReference) {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput instanceof AbstractItemEditorInput) {
                    AbstractItemEditorInput anaItemEditorInput = (AbstractItemEditorInput) editorInput;
                    // close the editor
                    activePage.closeEditor(editorRef.getEditor(false), false);
                    // reopen the analysis
                    new OpenItemEditorAction(new IRepositoryNode[] { anaItemEditorInput.getRepNode() }).run();
                }
            }
        } catch (PartInitException e) {
            log.error(e);
        }
    }
    activePage.activate(activePartReference.getPart(false));
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with AbstractItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput in project tdq-studio-se by Talend.

the class CorePlugin method itemIsOpening.

/**
 * check the item's editor is opening or not.
 *
 * @param item
 * @param closeEditor close the editor if it is opening
 * @return
 */
public boolean itemIsOpening(Item item, boolean closeEditor) {
    boolean opening = false;
    IWorkbenchPage activePage = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] editorReferences = activePage.getEditorReferences();
    IEditorInput editorInput = null;
    Property property = item.getProperty();
    for (IEditorReference reference : editorReferences) {
        try {
            editorInput = reference.getEditorInput();
            if (editorInput instanceof FileEditorInput) {
                FileEditorInput fileInput = (FileEditorInput) editorInput;
                if (property.eResource() != null) {
                    IPath itemPath = PropertyHelper.getItemPath(property);
                    if (itemPath != null && itemPath.equals(fileInput.getFile().getFullPath())) {
                        opening = true;
                        if (closeEditor) {
                            activePage.closeEditor(reference.getEditor(false), false);
                        }
                        break;
                    }
                }
            } else if (editorInput instanceof AbstractItemEditorInput) {
                AbstractItemEditorInput input = (AbstractItemEditorInput) editorInput;
                Item it = input.getItem();
                if (it != null && property != null && it.getProperty().getId().equals(property.getId())) {
                    opening = true;
                    if (closeEditor) {
                        activePage.closeEditor(reference.getEditor(false), false);
                    }
                    break;
                }
            }
        } catch (PartInitException e) {
            log.error(e);
            continue;
        }
    }
    return opening;
}
Also used : Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IEditorReference(org.eclipse.ui.IEditorReference) IPath(org.eclipse.core.runtime.IPath) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property) IEditorInput(org.eclipse.ui.IEditorInput)

Example 3 with AbstractItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput in project tdq-studio-se by Talend.

the class CorePlugin method refreshOpenedEditor.

/**
 * refresh the related connection which is opened in DQ side.
 *
 * @param item
 */
public void refreshOpenedEditor(Item item) {
    if (item == null) {
        return;
    }
    IWorkbenchPage activePage = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] editorReferences = activePage.getEditorReferences();
    Property property = item.getProperty();
    for (IEditorReference reference : editorReferences) {
        try {
            IEditorInput input = reference.getEditorInput();
            if (input instanceof AbstractItemEditorInput) {
                AbstractItemEditorInput itemInput = (AbstractItemEditorInput) input;
                Item it = itemInput.getItem();
                if (it != null && property != null && it.getProperty().getId().equals(property.getId())) {
                    // make sure the item in editorInput is latest.
                    if (!item.equals(it)) {
                        itemInput.setRepNode(RepositoryNodeHelper.recursiveFind(property));
                    }
                    CommonFormEditor editor = (CommonFormEditor) reference.getEditor(false);
                    editor.refreshEditor();
                    break;
                }
            }
        } catch (PartInitException e) {
            log.error(e);
            continue;
        }
    }
}
Also used : Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IEditorReference(org.eclipse.ui.IEditorReference) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property) IEditorInput(org.eclipse.ui.IEditorInput) CommonFormEditor(org.talend.dataprofiler.core.ui.editor.CommonFormEditor)

Example 4 with AbstractItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput in project tdq-studio-se by Talend.

the class WorkbenchUtils method getIEditorReference.

/**
 * Get Editors which is is same as editorID --used for the analysis editor only
 *
 * @param editorID
 * @param analysisName
 * @return
 */
private static List<IEditorReference> getIEditorReference(String editorID, String analysisName) {
    List<IEditorReference> returnCode = new ArrayList<IEditorReference>();
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] editors = activePage.getEditorReferences();
    if (editors != null) {
        for (IEditorReference editorRef : editors) {
            if (editorRef.getId().equals(editorID)) {
                IEditorInput editorInput;
                try {
                    editorInput = editorRef.getEditorInput();
                    if (editorInput instanceof AbstractItemEditorInput) {
                        AnalysisItemEditorInput anaItemEditorInput = (AnalysisItemEditorInput) editorInput;
                        // if not pointed which analysis, add all opened ones.
                        if (StringUtils.isEmpty(analysisName) || StringUtils.equals(analysisName, anaItemEditorInput.getModel().getName())) {
                            returnCode.add(editorRef);
                        }
                    }
                } catch (PartInitException e) {
                    log.error(e, e);
                }
            }
        }
    }
    return returnCode;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) ArrayList(java.util.ArrayList) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with AbstractItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput in project tdq-studio-se by Talend.

the class RepNodeUtils method closeModelElementEditor.

/**
 * close ModelElement node's editor.
 *
 * @param nodes
 */
public static void closeModelElementEditor(List<? extends IRepositoryNode> nodes, boolean save) {
    List<String> uuids = RepositoryNodeHelper.getUuids(nodes);
    List<IEditorReference> need2CloseEditorRefs = new ArrayList<IEditorReference>();
    IEditorReference[] editorReferences = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    try {
        for (IEditorReference editorRef : editorReferences) {
            if (editorRef != null) {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput != null) {
                    if (editorInput instanceof AbstractItemEditorInput) {
                        String modelElementUuid = ((AbstractItemEditorInput) editorInput).getModelElementUuid();
                        if (modelElementUuid != null && uuids.contains(modelElementUuid)) {
                            need2CloseEditorRefs.add(editorRef);
                        }
                    }
                }
            }
        }
    } catch (PartInitException e) {
        log.warn(e, e);
    }
    if (need2CloseEditorRefs.size() > 0) {
        CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(need2CloseEditorRefs.toArray(new IEditorReference[need2CloseEditorRefs.size()]), save);
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) ArrayList(java.util.ArrayList) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)6 IEditorReference (org.eclipse.ui.IEditorReference)6 PartInitException (org.eclipse.ui.PartInitException)6 AbstractItemEditorInput (org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 ArrayList (java.util.ArrayList)3 TreeItem (org.eclipse.swt.widgets.TreeItem)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 Item (org.talend.core.model.properties.Item)2 Property (org.talend.core.model.properties.Property)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)1 OpenItemEditorAction (org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction)1 CommonFormEditor (org.talend.dataprofiler.core.ui.editor.CommonFormEditor)1 AnalysisItemEditorInput (org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput)1 DQRespositoryView (org.talend.dataprofiler.core.ui.views.DQRespositoryView)1