Search in sources :

Example 26 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.

the class DeleteQueryConnAction method run.

/**
	 * Drop the query connection
	 */
public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    StringBuffer connNames = new StringBuffer();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ICubridNode node = (ICubridNode) objArr[i];
        connNames.append(node.getLabel());
        if (i != objArr.length - 1) {
            connNames.append(",");
        }
    }
    boolean isDrop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmDropConn, connNames.toString()));
    if (!isDrop) {
        return;
    }
    for (int i = 0; i < objArr.length; i++) {
        CubridDatabase database = (CubridDatabase) objArr[i];
        boolean isContinue = CQBConnectionUtils.processConnectionDeleted(database);
        List<CubridGroupNode> groups = CQBGroupNodePersistManager.getInstance().getAllGroupNodes();
        for (CubridGroupNode grp : groups) {
            grp.removeChild(database);
        }
        if (isContinue) {
            TreeViewer viewer = (TreeViewer) provider;
            viewer.remove(database);
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 27 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.

the class EditQueryConnAction method run.

/**
	 * Open the query connection
	 */
public void run() {
    // TODO remove later
    CQBGroupNodePersistManager.getInstance().fix();
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    ConnectionInfo oldInfo = null;
    ConnectionInfo newInfo = null;
    if (cubridDatabases.length > 1) {
        MultiQueryConnEditDialog dialog = new MultiQueryConnEditDialog(getShell(), Arrays.asList(cubridDatabases));
        if (dialog.open() != MultiQueryConnEditDialog.SAVE_ID) {
            return;
        }
        List<CubridDatabase> newDBList = dialog.getNewDBList();
        for (int i = 0; i < cubridDatabases.length; i++) {
            CubridDatabase saveCubridDatabase = cubridDatabases[i];
            CubridDatabase newCubridDatabase = newDBList.get(i);
            oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(saveCubridDatabase);
            newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(newCubridDatabase);
            saveCubridDatabase.setLabel(newCubridDatabase.getLabel());
            saveCubridDatabase.getDatabaseInfo().setDbName(newCubridDatabase.getDatabaseInfo().getDbName());
            saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setName(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getName());
            saveCubridDatabase.setAutoSavePassword(newCubridDatabase.isAutoSavePassword());
            if (saveCubridDatabase.isAutoSavePassword()) {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword());
            } else {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(null);
            }
            saveCubridDatabase.getDatabaseInfo().setBrokerIP(newCubridDatabase.getDatabaseInfo().getBrokerIP());
            saveCubridDatabase.getDatabaseInfo().setBrokerPort(newCubridDatabase.getDatabaseInfo().getBrokerPort());
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(saveCubridDatabase, false);
            if (editorConfig == null) {
                editorConfig = new DatabaseEditorConfig();
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            } else if (editorConfig.getBackGround() == null) {
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            }
            if (newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY) != null) {
                editorConfig.setDatabaseComment((String) newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY));
            }
            QueryOptions.putEditorConfig(saveCubridDatabase, editorConfig, false);
            CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
            boolean isContinue = CQBConnectionUtils.processConnectionLogout(saveCubridDatabase);
            if (isContinue) {
                TreeViewer viewer = (TreeViewer) provider;
                viewer.refresh(saveCubridDatabase, true);
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(saveCubridDatabase, CubridNodeChangedEventType.DATABASE_LOGOUT));
            }
        }
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        return;
    }
    CubridDatabase database = (CubridDatabase) cubridDatabases[0];
    if (database.getParent() == null) {
        CQBGroupNodePersistManager.getInstance();
    }
    String preName = (database == null || database.getServer() == null) ? "" : database.getServer().getName();
    ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
    oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
    QueryConnDialog dialog = new QueryConnDialog(getShell(), database, false);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID) {
        database.removeAllChild();
        newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
        TreeViewer treeViewer = (TreeViewer) provider;
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        if (!preName.equals(database.getServer().getName())) {
            QueryOptions.removePref(preServerInfo);
        }
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        if (dialog.isFireLogoutEvent()) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
        }
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
        try {
            CommonUITool.openQueryEditor(database, true);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage(), e);
        }
    } else if (returnCode == QueryConnDialog.SAVE_ID) {
        TreeViewer treeViewer = (TreeViewer) provider;
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) MultiQueryConnEditDialog(com.cubrid.cubridquery.ui.connection.dialog.MultiQueryConnEditDialog) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 28 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.

the class QuickDiffRestoreAction method getSelection.

/**
 * Returns the selection of the editor this action belongs to.
 *
 * @return the editor's selection, or <code>null</code>
 */
protected ITextSelection getSelection() {
    if (getTextEditor() == null)
        return null;
    ISelectionProvider sp = getTextEditor().getSelectionProvider();
    if (sp == null)
        return null;
    ISelection s = sp.getSelection();
    if (s instanceof ITextSelection)
        return (ITextSelection) s;
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 29 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.

the class RetrieverAction method extractSearchTextFromEditor.

protected final String extractSearchTextFromEditor(IEditorPart editor) {
    if (editor != null) {
        ITextSelection selection = null;
        ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
        if (provider != null) {
            ISelection s = provider.getSelection();
            if (s instanceof ITextSelection) {
                selection = (ITextSelection) s;
            }
        }
        if (selection != null) {
            if (selection.getLength() == 0) {
                ITextEditor txtEditor = getTextEditor(editor);
                if (txtEditor != null) {
                    IDocument document = txtEditor.getDocumentProvider().getDocument(txtEditor.getEditorInput());
                    selection = expandSelection(selection, document, null);
                }
            }
            if (selection.getLength() > 0 && selection.getText() != null) {
                return trimSearchString(selection.getText());
            }
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) ITextSelection(org.eclipse.jface.text.ITextSelection) IDocument(org.eclipse.jface.text.IDocument)

Example 30 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method setFont.

/**
 * Sets the font for the given viewer sustaining selection and scroll position.
 *
 * @param sourceViewer the source viewer
 * @param font the font
 * @since 2.0
 */
private void setFont(ISourceViewer sourceViewer, Font font) {
    if (sourceViewer.getDocument() != null) {
        ISelectionProvider provider = sourceViewer.getSelectionProvider();
        ISelection selection = provider.getSelection();
        int topIndex = sourceViewer.getTopIndex();
        StyledText styledText = sourceViewer.getTextWidget();
        Control parent = styledText;
        if (sourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) sourceViewer;
            parent = extension.getControl();
        }
        parent.setRedraw(false);
        styledText.setFont(font);
        if (fVerticalRuler instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
            e.setFont(font);
        }
        provider.setSelection(selection);
        sourceViewer.setTopIndex(topIndex);
        if (parent instanceof Composite) {
            Composite composite = (Composite) parent;
            composite.layout(true);
        }
        parent.setRedraw(true);
    } else {
        StyledText styledText = sourceViewer.getTextWidget();
        styledText.setFont(font);
        if (fVerticalRuler instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
            e.setFont(font);
        }
    }
}
Also used : IVerticalRulerExtension(org.eclipse.jface.text.source.IVerticalRulerExtension) Control(org.eclipse.swt.widgets.Control) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Composite(org.eclipse.swt.widgets.Composite) ISelection(org.eclipse.jface.viewers.ISelection) Point(org.eclipse.swt.graphics.Point)

Aggregations

ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)170 ISelection (org.eclipse.jface.viewers.ISelection)61 TreeViewer (org.eclipse.jface.viewers.TreeViewer)40 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 ITextSelection (org.eclipse.jface.text.ITextSelection)26 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)24 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)23 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)21 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)15 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)13 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)13 IPostSelectionProvider (org.eclipse.jface.viewers.IPostSelectionProvider)13 IEditorPart (org.eclipse.ui.IEditorPart)13 Shell (org.eclipse.swt.widgets.Shell)12 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)10 IDocument (org.eclipse.jface.text.IDocument)9