Search in sources :

Example 21 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project xtext-eclipse by eclipse.

the class XtextEditor method installSelectionChangedListener.

private void installSelectionChangedListener() {
    selectionChangedListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateStatusLine();
        }
    };
    final ISelectionProvider selectionProvider = getSelectionProvider();
    if (selectionProvider instanceof IPostSelectionProvider) {
        final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider;
        postSelectionProvider.addPostSelectionChangedListener(selectionChangedListener);
    } else {
        getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 22 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project xtext-eclipse by eclipse.

the class OutlineWithEditorLinker method activate.

public void activate(OutlinePage outlinePage) {
    this.outlinePage = outlinePage;
    treeViewer = outlinePage.getTreeViewer();
    treeListener = new TreeListener();
    treeViewer.addPostSelectionChangedListener(treeListener);
    treeViewer.addDoubleClickListener(treeListener);
    textViewer = outlinePage.getSourceViewer();
    textListener = new TextListener();
    ISelectionProvider textSelectionProvider = textViewer.getSelectionProvider();
    if (textSelectionProvider instanceof IPostSelectionProvider)
        ((IPostSelectionProvider) textSelectionProvider).addPostSelectionChangedListener(textListener);
    else
        textSelectionProvider.addSelectionChangedListener(textListener);
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider)

Example 23 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project xtext-eclipse by eclipse.

the class OutlineWithEditorLinker method deactivate.

public void deactivate() {
    ISelectionProvider textSelectionProvider = textViewer.getSelectionProvider();
    if (textSelectionProvider instanceof IPostSelectionProvider)
        ((IPostSelectionProvider) textSelectionProvider).removePostSelectionChangedListener(textListener);
    else
        textSelectionProvider.removeSelectionChangedListener(textListener);
    textListener = null;
    textViewer = null;
    treeViewer.removePostSelectionChangedListener(treeListener);
    treeViewer.removeDoubleClickListener(treeListener);
    treeViewer = null;
    treeListener = null;
    outlinePage = null;
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider)

Example 24 with ISelectionProvider

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

the class StopSlaveDbAction method run.

/**
	 * Stop database and refresh navigator
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final ISchemaNode schemaNode = (ISchemaNode) obj[0];
    ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
        CubridDatabase database = StartSlaveDbAction.getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
        databaseSet.add(database);
    }
    StringBuffer dbNamesBuffer = new StringBuffer("");
    Iterator<SlaveInfo> it = replInfo.getSlaveList().iterator();
    while (it.hasNext()) {
        dbNamesBuffer.append(it.next().getSlaveDbName()).append(",");
    }
    String dbNames = dbNamesBuffer.toString().substring(0, dbNamesBuffer.toString().length() - 1);
    boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames));
    if (!isStop) {
        return;
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.STANDALONE);
                    display.syncExec(new Runnable() {

                        public void run() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).exec();
        if (taskExcutor.isSuccess()) {
            for (int i = 0; i < dbObjectArr.length; i++) {
                CubridDatabase database = (CubridDatabase) dbObjectArr[i];
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
            }
            ActionManager.getInstance().fireSelectionChanged(getSelection());
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SlaveInfo(com.cubrid.cubridmanager.core.replication.model.SlaveInfo) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Example 25 with ISelectionProvider

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

the class StartSlaveDbAction method run.

/**
	 * Start database and refresh navigator
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final ISchemaNode schemaNode = (ISchemaNode) obj[0];
    ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
        CubridDatabase database = getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
        databaseSet.add(database);
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.CS);
                    display.syncExec(new Runnable() {

                        public void run() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).exec();
        if (taskExcutor.isSuccess()) {
            for (int i = 0; i < dbObjectArr.length; i++) {
                CubridDatabase database = (CubridDatabase) dbObjectArr[i];
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_START));
            }
            ActionManager.getInstance().fireSelectionChanged(getSelection());
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

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