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.foglyn.ui.FoglynAdvancedSearchPage.java

License:Open Source License

private void refreshViewer(StructuredViewer viewer) {
    IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();

    viewer.refresh();//from   w w  w.ja va2s .c  o  m
    viewer.setSelection(sel);

    IStructuredSelection after = (IStructuredSelection) viewer.getSelection();
    if (after.isEmpty()) {
        viewer.setSelection(HelperConstants.NULL_VALUE_SELECTION);
    }
}

From source file:com.foglyn.ui.FoglynFilterQueryPage.java

License:Open Source License

private FogBugzFilter getSelectedFilter() {
    IStructuredSelection selection = (IStructuredSelection) filtersList.getSelection();
    if (selection.isEmpty()) {
        return null;
    }//from  w  ww  .  ja va  2 s. co m

    if (selection.size() != 1) {
        return null;
    }

    return (FogBugzFilter) selection.getFirstElement();
}

From source file:com.foosbar.mailsnag.commands.DeleteMessage.java

License:Open Source License

/**
 * Main execution/*w  w  w.  j a va2 s  .co m*/
 */
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchPart part = HandlerUtil.getActivePart(event);

    if (part instanceof MessagesView) {

        final MessagesView viewer = (MessagesView) part;

        viewer.showLogo();

        IStructuredSelection iss = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);

        if (!iss.isEmpty()) {
            String message = getConfirmationMessage(iss.size());

            ResourceBundle BUNDLE = Activator.getResourceBundle();
            boolean confirm = MessageDialog.openConfirm(viewer.getViewer().getControl().getShell(),
                    BUNDLE.getString("action.delete.confirm"), message);

            if (confirm) {
                deleteMessages(iss, viewer);
            }
        }
    }
    return null;
}

From source file:com.freescale.deadlockpreventer.agent.LauncherView.java

License:Open Source License

private IStructuredSelection getSelection() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (!selection.isEmpty()) {
        if (selection instanceof IStructuredSelection)
            return (IStructuredSelection) selection;
    }/*from w  ww . ja va  2  s.c o m*/
    return new StructuredSelection();
}

From source file:com.gcsf.pcm.gui.views.ContactsSearchBar.java

License:Open Source License

private void createRefreshJob() {
    fRefreshJob = new WorkbenchJob("") {//$NON-NLS-1$
        @Override/*from w  ww. j  a  va  2  s  . c o m*/
        public IStatus runInUIThread(IProgressMonitor monitor) {

            /* Tree Disposed */
            if (fViewer.getControl().isDisposed())
                return Status.CANCEL_STATUS;

            /* Get the Filter Pattern */
            String text = fFilterText != null ? fFilterText.getText() : null;
            if (text == null)
                return Status.OK_STATUS;

            /* Check if the Initial Text was set */
            boolean initial = fInitialText != null && fInitialText.equals(text);

            try {
                fViewer.getControl().getParent().setRedraw(false);

                /* Remember Expanded Elements if not yet done */
                if (fExpandedElements == null)
                    fExpandedElements = fViewer.getExpandedElements();

                /* Remember Selected Elements if present */
                IStructuredSelection sel = (IStructuredSelection) fViewer.getSelection();
                if (!sel.isEmpty())
                    fSelectedElements = sel.toArray();

                /* Refresh Tree */
                BusyIndicator.showWhile(getDisplay(), new Runnable() {
                    public void run() {
                        fViewer.refresh(false);
                    }
                });

                /* Restore Expanded Elements and Selection when Filter is disabled */
                if (text.length() == 0) {

                    /* Restore Expansion */
                    fViewer.collapseAll();
                    for (Object element : fExpandedElements) {
                        fViewer.setExpandedState(element, true);
                    }

                    /* Restore Selection */
                    if (fSelectedElements != null)
                        fViewer.setSelection(new StructuredSelection(fSelectedElements), true);

                    /* Clear Fields */
                    fExpandedElements = null;
                    fSelectedElements = null;
                }

                /*
                 * Expand elements one at a time. After each is expanded, check to see
                 * if the filter text has been modified. If it has, then cancel the
                 * refresh job so the user doesn't have to endure expansion of all the
                 * nodes.
                 */
                if (text.length() > 0 && !initial) {
                    IStructuredContentProvider provider = (IStructuredContentProvider) fViewer
                            .getContentProvider();
                    Object[] elements = provider.getElements(fViewer.getInput());
                    for (Object element : elements) {
                        if (monitor.isCanceled())
                            return Status.CANCEL_STATUS;

                        fViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
                    }

                    /* Make Sure to show the First Item */
                    TreeItem[] items = fViewer.getTree().getItems();
                    if (items.length > 0)
                        fViewer.getTree().showItem(items[0]);

                    /* Enable Toolbar to allow resetting the Filter */
                    setToolBarVisible(true);
                }

                /* Disable Toolbar - No Filter is currently activated */
                else {
                    setToolBarVisible(false);
                }
            }

            /* Done updating the tree - set redraw back to true */
            finally {
                fViewer.getControl().getParent().setRedraw(true);
            }

            return Status.OK_STATUS;
        }
    };
    fRefreshJob.setSystem(true);

    /* Cancel the Job once the Tree got disposed */
    fViewer.getControl().addDisposeListener(new DisposeListener() {
        public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
            fRefreshJob.cancel();
        };
    });
}

From source file:com.github.fengtan.sophie.dialogs.EditListValueDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new RowLayout());

    // Create list widget.
    listViewer = new ListViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
    for (Object value : defaultValue) {
        listViewer.add(Objects.toString(value, StringUtils.EMPTY));
    }//from w  w w  . j a  v a  2 s  .co m

    // Create add/remove buttons.
    Composite buttonsComposite = new Composite(composite, SWT.NULL);
    buttonsComposite.setLayout(new FillLayout(SWT.VERTICAL));

    Button buttonAdd = new Button(buttonsComposite, SWT.PUSH);
    buttonAdd.setText("Add");
    buttonAdd.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            InputDialog input = new InputDialog(parent.getShell(), "Add value", "Add value:", null, null);
            input.open();
            if (input.getReturnCode() == IDialogConstants.OK_ID) {
                listViewer.add(input.getValue());
            }
        }
    });

    Button buttonRemove = new Button(buttonsComposite, SWT.PUSH);
    buttonRemove.setText("Remove");
    buttonRemove.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
            if (!selection.isEmpty()) {
                listViewer.remove(selection.toArray());
            }
        }
    });

    return composite;
}

From source file:com.github.sdbg.debug.ui.internal.util.LaunchUtils.java

License:Open Source License

public static IResource getSelectedResource(IWorkbenchWindow window) {
    IWorkbenchPage page = window.getActivePage();

    if (page == null) {
        return null;
    }//from  w w w.j a  va 2s  .c o m

    IWorkbenchPart part = page.getActivePart();

    if (part instanceof IEditorPart) {
        IEditorPart epart = (IEditorPart) part;

        return (IResource) epart.getEditorInput().getAdapter(IResource.class);
    } else if (part != null) {
        IWorkbenchPartSite site = part.getSite();

        if (site != null) {
            ISelectionProvider provider = site.getSelectionProvider();

            if (provider != null) {
                ISelection selection = provider.getSelection();

                if (selection instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) selection;

                    if (!ss.isEmpty()) {
                        Iterator<?> iterator = ss.iterator();

                        while (iterator.hasNext()) {
                            Object next = iterator.next();

                            //&&&                
                            //                if (next instanceof DartElement) {
                            //                  next = ((DartElement) next).getResource();
                            //                }
                            //
                            if (next instanceof IResource) {
                                return (IResource) next;
                            } else if (next != null) {
                                IResource resource = (IResource) Platform.getAdapterManager().getAdapter(next,
                                        IResource.class);

                                if (resource != null) {
                                    return resource;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if (page.getActiveEditor() != null) {
        return (IResource) page.getActiveEditor().getEditorInput().getAdapter(IResource.class);
    }

    return null;
}

From source file:com.github.sdbg.debug.ui.internal.view.ShowInspectorAction.java

License:Open Source License

@Override
public synchronized void run() {
    try {/*  w  w w .  j  av a  2s  .c  om*/
        IStructuredSelection sel = selectionProvider.getCurrentSelection();

        if (sel != null && !sel.isEmpty()) {
            Object obj = sel.getFirstElement();

            if (obj instanceof IVariable) {
                try {
                    obj = ((IVariable) obj).getValue();
                } catch (DebugException e) {

                }
            }

            if (obj instanceof IValue) {
                //&&&ObjectInspectorView.inspect((IValue) obj);
                return;
            }
        }

        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .showView("com.github.sdbg.debug.objectInspectorView");
    } catch (PartInitException e) {
        DartUtil.logError(e);
    }
}

From source file:com.google.cloud.tools.eclipse.appengine.deploy.ui.internal.ProjectSelectorSelectionChangedListener.java

License:Apache License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    try {/*from w  ww . j  ava 2s. co  m*/
        if (!selection.isEmpty()) {
            GcpProject project = (GcpProject) selection.getFirstElement();
            boolean hasAppEngineApplication = hasAppEngineApplication(project);
            if (!hasAppEngineApplication) {
                String link = MessageFormat.format(CREATE_APP_LINK, project.getId());
                projectSelector.setStatusLink(
                        Messages.getString("projectselector.missing.appengine.application.link", link), link);
            } else {
                projectSelector.clearStatusLink();
            }
        } else {
            projectSelector.clearStatusLink();
        }
    } catch (ProjectRepositoryException ex) {
        projectSelector.setStatusLink(Messages.getString("projectselector.retrieveapplication.error.message",
                ex.getLocalizedMessage()), null /* tooltip */);
    }
}

From source file:com.google.cloud.tools.eclipse.projectselector.ProjectSelector.java

License:Apache License

public void setStatusLink(String linkText, String tooltip) {
    statusLink.setText(linkText);// w w  w.  j av a2 s.  c  o m
    setTooltip(tooltip);
    boolean hide = Strings.isNullOrEmpty(linkText);
    ((GridData) statusLink.getLayoutData()).exclude = hide;
    statusLink.setVisible(!hide);
    layout();
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    if (!selection.isEmpty()) {
        tableViewer.reveal(selection.getFirstElement());
    }
}