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.ui.widgets.CListTable.java

License:Open Source License

/**
 * @param parent//from w w  w . j  a v a  2 s .c o m
 *            the parent composite
 * @param style
 *            the style bits
 */
public CListTable(Composite parent, int style) {
    super(parent, style);
    items = new ArrayList<Object>();
    listeners = new ArrayList<Listener>();

    setLayout(GridLayoutFactory.fillDefaults().create());

    descriptionLabel = new Label(this, SWT.WRAP);
    descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite buttons = new Composite(this, SWT.NONE);
    buttons.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create());
    buttons.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    addButton = new Button(buttons, SWT.PUSH);
    addButton.setToolTipText(StringUtil.ellipsify(CoreStrings.ADD));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean itemAdded = false;
            Object newItem = null;
            for (Listener listener : listeners) {
                newItem = listener.addItem();
                if (newItem != null) {
                    items.add(newItem);
                    itemAdded = true;
                }
            }
            if (itemAdded) {
                tableViewer.refresh();
                tableViewer.setSelection(new StructuredSelection(newItem));
                for (Listener listener : listeners) {
                    listener.itemsChanged(getItems());
                }
            }
        }
    });
    addButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/add.gif")); //$NON-NLS-1$

    editButton = new Button(buttons, SWT.PUSH);
    editButton.setToolTipText(StringUtil.ellipsify(CoreStrings.EDIT));
    editButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            if (!selection.isEmpty()) {
                Object element = selection.getFirstElement();
                items.remove(element);
                Object newElement = null;
                boolean changed = false;
                for (Listener listener : listeners) {
                    newElement = listener.editItem(element);
                    if (newElement != null) {
                        items.add(newElement);
                        changed = true;
                    }
                }
                if (changed) {
                    tableViewer.refresh();
                    tableViewer.setSelection(new StructuredSelection(newElement));
                    for (Listener listener : listeners) {
                        listener.itemsChanged(getItems());
                    }
                }
            }
        }

    });
    editButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/edit.png")); //$NON-NLS-1$

    removeButton = new Button(buttons, SWT.PUSH);
    removeButton.setToolTipText(CoreStrings.REMOVE);
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Object[] elements = selection.toArray();
            for (Object element : elements) {
                items.remove(element);
            }
            tableViewer.refresh();
            updateStates();
            for (Listener listener : listeners) {
                listener.itemsChanged(getItems());
            }
        }
    });
    removeButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/delete.gif")); //$NON-NLS-1$

    createTable(this);
}

From source file:com.aptana.ui.widgets.CListTable.java

License:Open Source License

private void updateStates() {
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    boolean hasSelection = !selection.isEmpty();
    boolean hasMultiSelections = selection.size() > 1;
    editButton.setEnabled(hasSelection && !hasMultiSelections);
    removeButton.setEnabled(hasSelection);
    addButton.setEnabled(true);//from  ww  w  .j  a  v a 2 s  .co  m
}

From source file:com.arc.cdt.debug.seecode.internal.ui.SeeCodeConfigPage.java

License:Open Source License

/**
 * Returns the current C element context from which to initialize default
 * settings, or <code>null</code> if none. Note, if possible we will
 * return the IBinary based on config entry as this may be more usefull then
 * just the project.//from  w w w.  ja v a 2s .  c  o  m
 * 
 * NOTE: this code was copied from AbstractCDebuggerTab that no longer
 * was accessible since the CDT folks refactored things (2/8/06)
 * 
 * @return C element context.
 */
public static ICElement getContext(ILaunchConfiguration config, String platform) {
    String projectName = null;
    String programName = null;
    IWorkbenchPage page = LaunchUIPlugin.getActivePage();
    Object obj = null;
    try {
        projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
        programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
    } catch (CoreException e) {
    }
    if (projectName != null && !projectName.equals("")) { //$NON-NLS-1$
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
        if (cProject != null && cProject.exists()) {
            obj = cProject;
        }
    } else {
        if (page != null) {
            ISelection selection = page.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                if (!ss.isEmpty()) {
                    obj = ss.getFirstElement();
                }
            }
        }
    }
    if (obj instanceof IResource) {
        ICElement ce = CoreModel.getDefault().create((IResource) obj);
        if (ce == null) {
            IProject pro = ((IResource) obj).getProject();
            ce = CoreModel.getDefault().create(pro);
        }
        obj = ce;
    }
    if (obj instanceof ICElement) {
        if (platform != null && !platform.equals("*")) { //$NON-NLS-1$
            ICDescriptor descriptor;
            try {
                descriptor = CCorePlugin.getDefault()
                        .getCProjectDescription(((ICElement) obj).getCProject().getProject(), false);
                if (descriptor != null) {
                    String projectPlatform = descriptor.getPlatform();
                    if (!projectPlatform.equals(platform) && !projectPlatform.equals("*")) { //$NON-NLS-1$
                        obj = null;
                    }
                }
            } catch (CoreException e) {
            }
        }
        if (obj != null) {
            if (programName == null || programName.equals("")) { //$NON-NLS-1$
                return (ICElement) obj;
            }
            ICElement ce = (ICElement) obj;
            IProject project;
            project = (IProject) ce.getCProject().getResource();
            IPath programFile;
            //<CUSTOMIZATION> handle absolute exe paths
            if (new File(programName).isAbsolute()) {
                programFile = new Path(programName);
            }
            //</CUSTOMIZATION>
            else {
                programFile = project.getFile(programName).getLocation();
            }
            ce = CCorePlugin.getDefault().getCoreModel().create(programFile);
            if (ce != null && ce.exists()) {
                return ce;
            }
            return (ICElement) obj;
        }
    }
    if (page != null) {
        IEditorPart part = page.getActiveEditor();
        if (part != null) {
            IEditorInput input = part.getEditorInput();
            return (ICElement) input.getAdapter(ICElement.class);
        }
    }
    return null;
}

From source file:com.arc.cdt.debug.seecode.ui.views.AbstractEngineBasedView.java

License:Open Source License

protected void setEngineSource(final IStructuredSelection selection) {
    if (fIsVisible && !selection.isEmpty()) {
        // At this point, we are NOT in the UI thread.
        final Object element = selection.getFirstElement();
        final EngineInterface engine = Utilities.computeEngineFromSelection(selection);
        if (engine != null) {
            // We may be making calls into the engine to get threads, stackframes, etc.
            // If we're the UI thread and the engine hangs then the whole GUI hangs.
            // Thus, we invoke it from another thread.
            if (Thread.currentThread() == mCards.getDisplay().getThread()) {
                engine.enqueue(new Runnable() {
                    @Override// ww w . j a v a2 s. co  m
                    public void run() {
                        setEngineSourceInternal(element, engine);
                    }
                }, this);
                return;
            }
        }
        setEngineSourceInternal(element, engine);
    }
}

From source file:com.arc.cdt.debug.seecode.ui.views.SeeCodeCommandView.java

License:Open Source License

@Override
protected void setEngineSource(IStructuredSelection selection) {
    super.setEngineSource(selection);
    fSelectedSession = null;//from   w w w.j  a va 2 s  .  co  m
    //If we're actually referencing the Launch (i.e. no particular target), and
    // we have a multi-process session, then send commands to the CMPD controller
    // so that they can be broadcast to every process, subject to focus qualifications.
    if (!selection.isEmpty()) {
        // At this point, we are NOT in the UI thread.
        Object element = selection.getFirstElement();
        if (element instanceof ILaunch) {
            fSelectedSession = computeSessionFrom(element);
        } else {
            fCommandProcs.clear();
            for (Object select : selection.toList()) {
                EngineInterface engine = Utilities.computeEngineFromSelection(select);
                if (engine != null) {
                    ICommandProcessor cp = getCommandProcessor(engine);
                    if (!fCommandProcs.contains(cp))
                        fCommandProcs.add(cp);
                }
            }
        }
    }
}

From source file:com.arc.cdt.debug.seecode.ui.views.SeeCodeErrorLogView.java

License:Open Source License

protected void setEngineSource(final IStructuredSelection selection) {
    if (fIsVisible && !selection.isEmpty()) {
        // At this point, we are NOT in the UI thread.
        final EngineInterface engine = Utilities.computeEngineFromSelection(selection);
        if (engine != null) {
            setEngine(engine);/*from  w  w w . jav a2s  . c  o m*/
        }
    }
}

From source file:com.archimatetool.editor.views.tree.actions.DeleteAction.java

License:Open Source License

@Override
public void run() {
    IStructuredSelection selection = getSelection();
    if (selection == null || selection.isEmpty()) {
        return;//from w  w  w.  j  a  va 2s  .c  om
    }

    DeleteCommandHandler cmdHandler = new DeleteCommandHandler((TreeModelViewer) getSelectionProvider(),
            selection.toArray());

    /*
     * If the objects are referenced in a diagram warn user
     */
    if (cmdHandler.hasDiagramReferences()) {
        if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteAction_1,
                Messages.DeleteAction_2 + "\n\n" + //$NON-NLS-1$
                        Messages.DeleteAction_3)) {
            return;
        }
    }

    cmdHandler.delete();
}

From source file:com.archimatetool.editor.views.tree.actions.DuplicateAction.java

License:Open Source License

@Override
public void run() {
    IStructuredSelection selection = getSelection();
    if (selection == null || selection.isEmpty()) {
        return;/*from  ww w .j  av a  2s .co m*/
    }

    DuplicateCommandHandler cmdHandler = new DuplicateCommandHandler(selection.toArray());
    cmdHandler.duplicate();
}

From source file:com.archimatetool.editor.views.tree.actions.PropertiesAction.java

License:Open Source License

@Override
public void update(IStructuredSelection selection) {
    setEnabled(!selection.isEmpty());
}

From source file:com.archimatetool.editor.views.tree.actions.RenameAction.java

License:Open Source License

@Override
public void run() {
    IStructuredSelection selection = getSelection();
    if (selection == null || selection.isEmpty()) {
        return;//from  w w  w .  j a v a  2 s .  co  m
    }

    Object element = selection.getFirstElement();
    if (RenameCommandHandler.canRename(element)) {
        ((TreeModelViewer) getSelectionProvider()).editElement(element);
    }
}