Example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty

List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty.

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:com.aptana.ide.server.ui.views.actions.StartServerAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.Action#isEnabled()
 *///from  w  ww.  j  a v  a2  s.c  om
public boolean isEnabled() {
    IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
    if (!selection.isEmpty()) {
        IServer server = (IServer) selection.getFirstElement();
        IStatus canStart = server.canStart(mode);
        return canStart.isOK();
    }
    return false;
}

From source file:com.aptana.ide.server.ui.views.actions.StartServerAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.Action#run()
 *//* w  w  w.  jav a2s  .c o  m*/
public void run() {
    IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
    if (!selection.isEmpty()) {
        IServer server = (IServer) selection.getFirstElement();
        try {
            server.start(mode, null, null);
        } catch (Exception e) {
            IdeLog.log(ServerUIPlugin.getDefault(), IStatus.ERROR, "exception while starting server", e); //$NON-NLS-1$
        }
    }
}

From source file:com.aptana.ide.server.ui.views.actions.SuspendServerAction.java

License:Open Source License

/**
 * @param event//from  www.j  a  v a2 s . c  o  m
 */
public void selectionChanged(SelectionChangedEvent event) {

    IStructuredSelection selection = (IStructuredSelection) event.getSelection();

    if (!selection.isEmpty()) {
        boolean enabled2 = isEnabled();
        IServer server = (IServer) selection.getFirstElement();
        if (server instanceof IPausableServer) {
            if (server.getServerState() == IPausableServer.STATE_PAUSED) {
                initResumeDescriptors(server, enabled2);
            } else {
                initPauseDescriptors(server, enabled2);
            }
        } else {
            initPauseDescriptors(server, false);
        }
        setEnabled(enabled2);
    } else {
        initPauseDescriptors(null, false);
        setEnabled(false);
    }
}

From source file:com.aptana.ide.server.ui.views.actions.SuspendServerAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.Action#isEnabled()
 *//*from  ww  w .j ava2s .  co m*/
public boolean isEnabled() {
    IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
    if (!selection.isEmpty()) {
        IServer server = (IServer) selection.getFirstElement();
        this.lastStatus = null;
        if (server instanceof IPausableServer) {
            IPausableServer ps = (IPausableServer) server;
            if (ps.getServerState() == IPausableServer.STATE_PAUSED) {
                IStatus canResume = ps.canResume();
                return canResume.isOK();
            }
            IStatus canPause = ps.canPause();
            return canPause.isOK();
        }
        return false;
    }
    return false;
}

From source file:com.aptana.ide.server.ui.views.actions.SuspendServerAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.Action#run()
 *///from   w  w  w  .j  av a2 s.  c  o  m
public void run() {
    IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
    if (!selection.isEmpty()) {
        IPausableServer server = (IPausableServer) selection.getFirstElement();
        try {
            if (server.getServerState() == IPausableServer.STATE_PAUSED) {
                server.resume(null, null);
            } else {
                server.pause(null, null);
            }
        } catch (Exception e) {
            IdeLog.log(ServerUIPlugin.getDefault(), IStatus.ERROR, "exception while starting server", e); //$NON-NLS-1$
        }
    }
}

From source file:com.aptana.ide.server.ui.views.GenericServersView.java

License:Open Source License

private void updateToolbar(final IToolBarManager toolBarManager) {
    IStructuredSelection selection = (IStructuredSelection) serverViewer.getSelection();
    this.pauseAction.selectionChanged(new SelectionChangedEvent(this.serverViewer, selection));
    this.openLog.selectionChanged(new SelectionChangedEvent(this.serverViewer, selection));
    if (selection.isEmpty()) {
        startAction.setEnabled(false);// w w w .j  a  va  2  s  . c o  m
        debugAction.setEnabled(false);
        profileAction.setEnabled(false);
        restartAction.setEnabled(false);
        stopAction.setEnabled(false);
    } else {
        IServer server = (IServer) selection.getFirstElement();
        // boolean isStopped = server.getServerState() == IServer.STATE_STOPPED;
        IStatus canStart0 = server.canStart("run");//$NON-NLS-1$
        startAction.setEnabled(canStart0.isOK());
        if (!canStart0.isOK()) {
            startAction.setToolTipText(canStart0.getMessage());
        } else {
            startAction.setToolTipText(Messages.ServersView_START);
        }
        IStatus canStart = server.canStart("debug");//$NON-NLS-1$
        debugAction.setEnabled(canStart.isOK());
        if (!canStart.isOK()) {
            debugAction.setToolTipText(canStart.getMessage());
        } else {
            debugAction.setToolTipText(Messages.ServersView_DEBUG);
        }
        IStatus canStart2 = server.canStart("profile"); //$NON-NLS-1$
        profileAction.setEnabled(canStart2.isOK());
        if (!canStart2.isOK()) {
            profileAction.setToolTipText(canStart2.getMessage());
        } else {
            profileAction.setToolTipText(Messages.ServersView_PROFILE);
        }
        restartAction.setEnabled(server.canRestart(server.getMode()).getSeverity() == IStatus.OK);
        stopAction.setEnabled(server.canStop().getSeverity() == IStatus.OK);
        openConsole.selectionChanged(new SelectionChangedEvent(serverViewer, serverViewer.getSelection()));
    }
    updateStartActions();
    updateCollapseAllAction();
    updateExpandAllAction();
    toolBarManager.update(true);
}

From source file:com.aptana.ide.server.ui.views.GenericServersView.java

License:Open Source License

private void doDelete() {

    IStructuredSelection selection = (IStructuredSelection) serverViewer.getSelection();
    if (selection.isEmpty()) {
        return;//www.  j  a  va 2 s. co  m
    }
    IServer server = (IServer) selection.getFirstElement();
    if (!server.canDelete().isOK()) {
        return;
    }
    boolean mayStop = (server.getServerState() != IServer.STATE_STOPPED
            && server.getServerState() != IServer.STATE_UNKNOWN);
    boolean askStopBeforeDelete = (server.askStopBeforeDelete().getCode() == IStatus.OK);
    DeleteServerConfirmDialog dlg = new DeleteServerConfirmDialog(getViewSite().getShell(),
            Messages.ServersView_CONFIRM_DELETE, null,
            StringUtils.format(Messages.ServersView_CONFIRM_DELETE_TEXT, server.getName()),
            MessageDialog.QUESTION,
            new String[] { Messages.GenericServersView_YES, Messages.GenericServersView_NO }, 0, mayStop,
            askStopBeforeDelete);

    int openConfirm = dlg.open();
    if (openConfirm != 0) {
        return;
    }
    boolean doStop = dlg.shouldStop;
    if (doStop) {
        server.stop(true, null, null);
    }

    try {
        ServerCore.getServerManager().removeServer(server);
    } catch (CoreException e) {
        MessageDialog.openError(getViewSite().getShell(), Messages.ServersView_CONFIRM_DELETE,
                StringUtils.format(Messages.ServersView_CONFIRM_DELETE_TEXT, server.getName()));
    }
}

From source file:com.aptana.ide.syncing.ui.navigator.actions.SyncingActionProvider.java

License:Open Source License

@Override
public void fillActionBars(IActionBars actionBars) {
    boolean hasSyncConnection = false;
    IStructuredSelection selection = getSelection();
    if (!selection.isEmpty()) {
        Object element = selection.getFirstElement();
        if (element instanceof IAdaptable) {
            hasSyncConnection = hasSyncConnection((IAdaptable) element);
        }//  www  .j  av a  2 s.c o m
    }
    // fillActionBars() is called each time the selection changes, so adds a check to only add the toolbar items
    // once
    IToolBarManager toolbar = actionBars.getToolBarManager();
    if (!isToolbarFilled) {
        if (hasSyncConnection) {
            fillToolBar(toolbar);
            actionBars.updateActionBars();
            isToolbarFilled = true;
        }
    } else if (updateToolbar(toolbar, hasSyncConnection)) {
        actionBars.updateActionBars();
    }
    updateSelection();
}

From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemCopyAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    fFileStores.clear();/*from  w  ww  .ja v a 2s  .c  o  m*/
    if (!super.updateSelection(selection)) {
        return false;
    }

    if (selection == null || selection.isEmpty()) {
        return false;
    }
    Object[] elements = selection.toArray();

    IFileStore fileStore;
    for (Object element : elements) {
        fileStore = getFileStore(element);
        if (fileStore != null) {
            fFileStores.add(fileStore);
        }
    }
    if (fFileStores.size() == 0) {
        return false;
    }

    // must have a common parent
    IFileStore firstParent = fFileStores.get(0).getParent();
    if (firstParent == null) {
        return false;
    }

    for (IFileStore store : fFileStores) {
        if (!store.getParent().equals(firstParent)) {
            return false;
        }
    }

    return true;
}

From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemEditActionGroup.java

License:Open Source License

@Override
public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection selection = getSelection();
    fCopyAction.selectionChanged(selection);
    menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fCopyAction);
    fPasteAction.selectionChanged(selection);
    menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fPasteAction);

    if (selection != null && !selection.isEmpty()) {
        Object[] elements = selection.toArray();
        boolean allFileSystemObjects = true;
        for (Object element : elements) {
            if (element instanceof LocalRoot || element instanceof IConnectionPoint) {
                allFileSystemObjects = false;
                break;
            }//from  w w w . j a va  2  s .  c  om
        }
        if (allFileSystemObjects) {
            menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fDeleteAction);
        }
    }
}