Search in sources :

Example 26 with IEditorInput

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

the class ERSchemaEditor method initializeGraphicalViewer.

protected void initializeGraphicalViewer() {
    IEditorInput input = this.getEditorInput();
    if (input instanceof ICubridNode) {
        ICubridNode node = (ICubridNode) input;
        ERSchema erSchema = (ERSchema) node.getAdapter(ERSchema.class);
        getGraphicalViewer().setContents(erSchema);
    }
}
Also used : ERSchema(com.cubrid.common.ui.er.model.ERSchema) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorInput(org.eclipse.ui.IEditorInput)

Example 27 with IEditorInput

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

the class BatchRunDialog method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == RUN_ID) {
        if (!MessageDialog.openConfirm(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.titleBatchRunConfirm, Messages.msgBatchRunConfirm)) {
            return;
        }
        List<String> fileList = container.getFileList();
        RunSQLFileEditorInput input = new RunSQLFileEditorInput(cubridDatabase, fileList);
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, RunSQLFileViewPart.ID);
        } catch (Exception e) {
            LOGGER.error(e.getLocalizedMessage());
        }
        super.buttonPressed(IDialogConstants.OK_ID);
    } else if (buttonId == PASTE_ID) {
        //			if (!MessageDialog.openConfirm(
        //					PlatformUI.getWorkbench().getDisplay().getActiveShell(),
        //					Messages.titleBatchRunConfirm, Messages.msgBatchRunPasteConfirm)) {
        //				return;
        //			}
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window == null || window.getActivePage() == null) {
            return;
        }
        IEditorPart editor = window.getActivePage().getActiveEditor();
        try {
            if (editor == null) {
                IEditorInput input = new QueryUnit();
                editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
            }
        } catch (PartInitException e) {
            CommonUITool.openErrorBox(e.getMessage());
        }
        if (editor == null) {
            return;
        }
        QueryEditorPart oldEditor = (QueryEditorPart) editor;
        try {
            QueryEditorPart queryEditor = (QueryEditorPart) editor;
            String encoding = queryEditor.getCombinedQueryComposite().getSqlEditorComp().getDocument().getEncoding();
            StringBuilder sb = new StringBuilder();
            List<String> fileList = container.getFileList();
            for (int i = 0; i < fileList.size(); i++) {
                sb.delete(0, sb.length());
                sb.append("/* SQL Filename: ").append(fileList.get(i)).append(" */").append(StringUtil.NEWLINE);
                BufferedReader in = null;
                try {
                    in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileList.get(i))), encoding));
                    String line = in.readLine();
                    while (line != null) {
                        sb.append(line + StringUtil.NEWLINE);
                        line = in.readLine();
                    }
                } finally {
                    try {
                        if (in != null) {
                            in.close();
                        }
                    } catch (IOException e) {
                    }
                }
                try {
                    QueryUnit input = new QueryUnit();
                    QueryEditorPart newEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
                    newEditor.setQuery(sb.toString(), false, false, false);
                    newEditor.connect(oldEditor.getSelectedDatabase());
                } catch (Exception e) {
                    CommonUITool.openErrorBox(e.getMessage());
                }
            }
        } catch (IOException e) {
            CommonUITool.openErrorBox(e.getMessage());
        }
        super.buttonPressed(IDialogConstants.OK_ID);
    } else {
        super.buttonPressed(buttonId);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InputStreamReader(java.io.InputStreamReader) RunSQLFileEditorInput(com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) BufferedReader(java.io.BufferedReader) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Example 28 with IEditorInput

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

the class WorkbenchContrItem method closeAllEditorAndViewInDatabase.

/**
	 * Close all editor and view part related with this CUBRID Manager database
	 * node,not include query editor
	 *
	 * @param databaseNode the CubridDatabase object
	 * @param eventType CubridNodeChangedEventType
	 */
public void closeAllEditorAndViewInDatabase(CubridDatabase databaseNode, CubridNodeChangedEventType eventType) {
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    for (int i = 0; editorRefArr != null && i < editorRefArr.length; i++) {
        IEditorReference editorRef = editorRefArr[i];
        try {
            IEditorInput editorInput = editorRef.getEditorInput();
            if (!(editorInput instanceof ISchemaNode)) {
                continue;
            }
            ISchemaNode schemaNode = ((ISchemaNode) editorInput);
            ISchemaNode dbNode = schemaNode.getDatabase();
            if (dbNode.getId().equals(databaseNode.getId())) {
                page.closeEditor(editorRef.getEditor(false), true);
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
    IViewReference[] viewRefArr = page.getViewReferences();
    if (viewRefArr == null || viewRefArr.length == 0) {
        return;
    }
    for (IViewReference viewRef : viewRefArr) {
        IViewPart viewPart = viewRef.getView(false);
        if (!(viewPart instanceof CubridViewPart)) {
            continue;
        }
        CubridViewPart cubridViewPart = (CubridViewPart) viewPart;
        ICubridNode cubridNode = cubridViewPart.getCubridNode();
        if (!(cubridNode instanceof ISchemaNode)) {
            continue;
        }
        ICubridNode cubridDatabaseNode = ((ISchemaNode) cubridNode).getDatabase();
        if (cubridDatabaseNode.getId().equals(databaseNode.getId())) {
            page.hideView(viewPart);
        }
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IEditorReference(org.eclipse.ui.IEditorReference) CubridViewPart(com.cubrid.common.ui.spi.part.CubridViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorInput(org.eclipse.ui.IEditorInput)

Example 29 with IEditorInput

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

the class LayoutUtil method closeAllCubridEditorAndView.

/**
	 * 
	 * Close all opened editor and view part related with CUBRID Manager,not
	 * include query editor
	 * 
	 */
public static void closeAllCubridEditorAndView() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return;
    }
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr != null && editorRefArr.length > 0) {
        for (IEditorReference editorRef : editorRefArr) {
            try {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput instanceof ICubridNode) {
                    window.getActivePage().closeEditor(editorRef.getEditor(false), true);
                }
            } catch (PartInitException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
    IViewReference[] viewRefArr = page.getViewReferences();
    if (viewRefArr != null && viewRefArr.length > 0) {
        for (IViewReference viewRef : viewRefArr) {
            IViewPart viewPart = viewRef.getView(false);
            if (viewPart instanceof CubridViewPart) {
                page.hideView(viewPart);
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IEditorReference(org.eclipse.ui.IEditorReference) CubridViewPart(com.cubrid.common.ui.spi.part.CubridViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 30 with IEditorInput

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

the class LayoutUtil method getEditorPart.

/**
	 * 
	 * Get the editor part of this CUBRID node and this editorId
	 * 
	 * @param cubridNode the ICubridNode object
	 * @param editorId the editor id
	 * @return the IEditorPart object
	 */
public static IEditorPart getEditorPart(ICubridNode cubridNode, String editorId) {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return null;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr == null || editorRefArr.length == 0) {
        return null;
    }
    for (IEditorReference editorRef : editorRefArr) {
        try {
            IEditorInput editorInput = editorRef.getEditorInput();
            String id = editorRef.getId();
            if (editorInput instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) editorInput;
                if (node.getId().equals(cubridNode.getId()) && editorId.equals(id)) {
                    return editorRef.getEditor(false);
                }
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
    return null;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)71 IFile (org.eclipse.core.resources.IFile)26 PartInitException (org.eclipse.ui.PartInitException)21 IEditorPart (org.eclipse.ui.IEditorPart)19 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)17 IEditorReference (org.eclipse.ui.IEditorReference)14 CoreException (org.eclipse.core.runtime.CoreException)13 ArrayList (java.util.ArrayList)11 IViewPart (org.eclipse.ui.IViewPart)11 FileEditorInput (org.eclipse.ui.part.FileEditorInput)10 Shell (org.eclipse.swt.widgets.Shell)9 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)8 IFileEditorInput (org.eclipse.ui.IFileEditorInput)8 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)8 File (java.io.File)7 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)7 Item (org.talend.core.model.properties.Item)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)6 IProject (org.eclipse.core.resources.IProject)6