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:ca.mcgill.sable.soot.editors.JimpleContentOutlinePage.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        Object elem = selection.getFirstElement();
        if (elem instanceof JimpleOutlineObject) {
            String toHighlight = ((JimpleOutlineObject) elem).getLabel();
            int start = getJimpleFileParser().getStartOfSelected(toHighlight);
            int length = getJimpleFileParser().getLength(toHighlight);
            getEd().selectAndReveal(start, length);
        }//from  ww w. j  a v  a  2 s  .c  o  m
    }
}

From source file:ca.mcgill.sable.soot.ui.AbstractOptionsDialog.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        Object elem = selection.getFirstElement();
        if (elem instanceof SootOption) {
            SootOption sel = (SootOption) elem;
            Control[] children = getPageContainer().getChildren();
            String childTitle = null;
            for (int i = 0; i < children.length; i++) {

                if (children[i] instanceof Composite) {
                    if (children[i] instanceof Group) {
                        childTitle = (String) ((Group) children[i]).getData("id");

                    }//w w  w. j a va 2  s  . c om
                    if (childTitle.compareTo(sel.getAlias()) == 0) {
                        ((StackLayout) getPageContainer().getLayout()).topControl = children[i];
                        getPageContainer().layout();

                    } else {
                        children[i].setVisible(false);
                    }
                }
            }
        }
    }
}

From source file:ca.mcgill.sable.soot.ui.AnalysisVisManipDialog.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (selection.isEmpty()) {
        checkTypes.setInput(getCheckInput(""));
    } else {/*from   w w w  . j  a va  2s  . com*/
        Object elem = selection.getFirstElement();
        if (!(elem instanceof IFile))
            return;
        ArrayList list = (ArrayList) getCheckInput(elem);
        handleLast();
        checkTypes.setInput(list);
        Object[] checkElems;
        if ((currentSettingsMap != null) && (currentSettingsMap.containsKey(elem))) {
            checkElems = (Object[]) currentSettingsMap.get(elem);
            checkTypes.setCheckedElements(checkElems);
        } else {
            SootAttributesHandler handler = getHandlerForFile((IFile) elem);
            if (handler != null) {
                if (handler.isShowAllTypes()) {
                    if (list != null) {
                        Object[] elems = new Object[list.size()];

                        for (int i = 0; i < list.size(); i++) {
                            elems[i] = checkTypes.getElementAt(i);

                        }
                        checkTypes.setCheckedElements(elems);
                    }
                } else {
                    Iterator it = handler.getTypesToShow().iterator();
                    Object[] elems = new Object[handler.getTypesToShow().size()];
                    int i = 0;
                    while (it.hasNext()) {
                        elems[i] = it.next();
                        i++;
                    }
                    checkTypes.setCheckedElements(elems);

                }
            }
        }
        if (getAllSelected() == null) {
            setAllSelected(new ArrayList());
        }
        getAllSelected().add(elem);
    }
}

From source file:ca.mcgill.sable.soot.ui.SootConfigManagerDialog.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        Object elem = selection.getFirstElement();
        if (elem instanceof SootConfiguration) {
            SootConfiguration sel = (SootConfiguration) elem;
            setSelected(sel.getLabel());
        }//from ww w.  j av  a  2  s. c  o m
        enableButtons();
    }
}

From source file:ca.uvic.chisel.diver.mylyn.logger.logging.PageSelectionListener.java

License:Open Source License

/**
 * @param selection//ww  w  .j  a  v  a2  s .c o m
 * @return
 */
private Object getSelectionObject(IWorkbenchPart part, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (!ss.isEmpty()) {
            Object o = ss.getFirstElement();
            if (o instanceof IJavaElement) {
                return o;
            } else if (o instanceof ITraceModel) {
                return o;
            }
        }
    } else if (selection instanceof ITextSelection) {
        ITextSelection ts = (ITextSelection) selection;
        if (part instanceof ITextEditor) {
            ITextEditor editor = (ITextEditor) part;
            ITypeRoot typeRoot = null;
            IEditorInput input = editor.getEditorInput();
            //using internal stuff, but I don't care
            if (input instanceof IClassFileEditorInput) {
                typeRoot = ((IClassFileEditorInput) input).getClassFile();
            } else if (input instanceof IFileEditorInput) {
                IFile file = ((IFileEditorInput) input).getFile();
                IJavaElement element = JavaCore.create(file);
                if (element instanceof ITypeRoot) {
                    typeRoot = (ITypeRoot) element;
                }
            }
            if (typeRoot != null) {
                IType type = typeRoot.findPrimaryType();
                if (type != null) {
                    try {
                        IJavaElement je = typeRoot.getElementAt(ts.getOffset());
                        return je;
                    } catch (JavaModelException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    return null;
}

From source file:ca.uvic.chisel.javasketch.ui.internal.search.TraceSearchResultPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    page = new Composite(parent, SWT.NULL);
    page.setLayout(new GridLayout());
    fViewer = new TreeViewer(page, SWT.NONE);
    fViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableLayout tl = new TableLayout();
    fViewer.getTree().setLayout(tl);/*w  w  w  . jav  a  2s .  c om*/
    // create columns for the viewer
    TreeViewerColumn c = new TreeViewerColumn(fViewer, SWT.NONE);
    c.getColumn().setText("Search Result");
    c.setLabelProvider(new TraceSearchResultLabelProvider());
    GC gc = new GC(fViewer.getTree());
    tl.addColumnData(new ColumnPixelData(Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 60)));
    gc.dispose();

    c = new TreeViewerColumn(fViewer, SWT.NONE);
    c.getColumn().setText("Kind");
    c.setLabelProvider(new TraceSearchResultLabelProvider());
    tl.addColumnData(new ColumnPixelData(50));

    c = new TreeViewerColumn(fViewer, SWT.NONE);
    c.getColumn().setText("Trace");
    c.setLabelProvider(new TraceSearchResultLabelProvider());

    tl.addColumnData(new ColumnPixelData(50));
    resultsListener = new TraceSearchResultListener();

    fViewer.getTree().setHeaderVisible(true);

    fViewer.setContentProvider(new TraceSearchResultContentProvider());
    //create a context menu for the viewer so that results can be 
    //linked to
    MenuManager manager = new MenuManager("TraceSearchResultsPage", "#TraceSearchResults");
    Menu menu = manager.createContextMenu(fViewer.getTree());
    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
            IStructuredSelection ss = (IStructuredSelection) getSite().getSelectionProvider().getSelection();
            if (!ss.isEmpty()) {
                Object o = ss.getFirstElement();
                if (o instanceof IActivation || o instanceof IMessage) {
                    IAction action = new CommandAction(RevealActivationHandler.COMMAND_ID, null);
                    action.setText("Reveal");
                    manager.add(action);
                }
            }
        }
    });
    getSite().registerContextMenu("#TraceSearchResults", manager, fViewer);
    fViewer.getTree().setMenu(menu);
    SelectionForward forward = new SelectionForward();
    fViewer.addSelectionChangedListener(forward);
    getSite().setSelectionProvider(forward);

}

From source file:ca.uvic.chisel.logging.eclipse.internal.ui.UploadWizardPage1.java

License:Open Source License

private Composite createCategoriesArea(Composite parent) {
    Composite categoriesArea = new Composite(parent, SWT.NONE);
    categoriesArea.setLayout(new GridLayout(2, false));

    //create a list viewer that will display all of the 
    //different loggers

    viewer = CheckboxTableViewer.newCheckList(categoriesArea, SWT.BORDER | SWT.SINGLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LoggingCategoryLabelProvider());
    viewer.setInput(WorkbenchLoggingPlugin.getDefault().getCategoryManager().getCategories());
    //set all of the enabled categories to the checked state
    for (ILoggingCategory category : WorkbenchLoggingPlugin.getDefault().getCategoryManager().getCategories()) {
        selectedCategories.add(category.getCategoryID());
    }/*from  www  .j  a  v a 2 s.  c o  m*/
    viewer.setAllChecked(true);
    viewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof ILoggingCategory) {
                ILoggingCategory category = (ILoggingCategory) event.getElement();
                if (event.getChecked()) {
                    selectedCategories.add(category.getCategoryID());
                } else {
                    selectedCategories.remove(category.getCategoryID());
                }
            }
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (aboutButton != null && !aboutButton.isDisposed()) {
                aboutButton.setEnabled(!event.getSelection().isEmpty());
            }
        }
    });

    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    //create a button area
    Composite buttonArea = new Composite(categoriesArea, SWT.NONE);
    buttonArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    buttonArea.setLayout(new GridLayout());

    GridDataFactory gdf = GridDataFactory.createFrom(new GridData(SWT.FILL, SWT.FILL, true, false));
    Button selectAll = new Button(buttonArea, SWT.PUSH);
    selectAll.setText("Select All");
    selectAll.setLayoutData(gdf.create());
    selectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.setAllChecked(true);
            for (ILoggingCategory category : WorkbenchLoggingPlugin.getDefault().getCategoryManager()
                    .getCategories()) {
                selectedCategories.add(category.getCategoryID());
            }
        }
    });

    Button selectNone = new Button(buttonArea, SWT.PUSH);
    selectNone.setText("Select None");
    selectNone.setLayoutData(gdf.create());
    selectNone.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.setAllChecked(false);
            selectedCategories.clear();
        }
    });

    Control spacer = new Composite(buttonArea, SWT.NONE);
    GridData d = gdf.create();
    d.heightHint = 40;
    spacer.setLayoutData(d);

    aboutButton = new Button(buttonArea, SWT.PUSH);
    aboutButton.setText("Disclaimer...");
    aboutButton.setLayoutData(gdf.create());
    aboutButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                if (!ss.isEmpty() && ss.getFirstElement() instanceof ILoggingCategory) {
                    AboutCategoryDialog dialog = new AboutCategoryDialog(getShell(),
                            (ILoggingCategory) ss.getFirstElement());
                    dialog.open();
                }
            }
        }
    });
    aboutButton.setEnabled(false);
    return categoriesArea;
}

From source file:ca.uvic.chisel.logging.eclipse.internal.ui.WorkbenchLoggerPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));

    // create a list viewer that will display all of the
    // different loggers

    viewer = CheckboxTableViewer.newCheckList(page, SWT.BORDER | SWT.SINGLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LoggingCategoryLabelProvider());
    viewer.setInput(WorkbenchLoggingPlugin.getDefault().getCategoryManager().getCategories());
    // set all of the enabled categories to the checked state
    boolean stale = false;
    for (ILoggingCategory category : WorkbenchLoggingPlugin.getDefault().getCategoryManager().getCategories()) {
        if (category.isEnabled()) {
            enabledCategories.add(category.getCategoryID());
            viewer.setChecked(category, true);
        }/*from w w  w  . ja  v a2 s.co m*/
        // also set the stale state... used for enabling the upload button.
        stale |= ((LoggingCategory) category).isStale();
    }
    viewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof ILoggingCategory) {
                ILoggingCategory category = (ILoggingCategory) event.getElement();
                if (event.getChecked()) {
                    enabledCategories.add(category.getCategoryID());
                } else {
                    enabledCategories.remove(category.getCategoryID());
                }
            }
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (aboutButton != null && !aboutButton.isDisposed()) {
                aboutButton.setEnabled(!event.getSelection().isEmpty());
            }
        }
    });

    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // create a button area
    Composite buttonArea = new Composite(page, SWT.NONE);
    buttonArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    buttonArea.setLayout(new GridLayout());

    GridDataFactory gdf = GridDataFactory.createFrom(new GridData(SWT.FILL, SWT.FILL, true, false));
    Button selectAll = new Button(buttonArea, SWT.PUSH);
    selectAll.setText("Select All");
    selectAll.setLayoutData(gdf.create());
    selectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.setAllChecked(true);
            for (ILoggingCategory category : WorkbenchLoggingPlugin.getDefault().getCategoryManager()
                    .getCategories()) {
                enabledCategories.add(category.getCategoryID());
            }
        }
    });

    Button selectNone = new Button(buttonArea, SWT.PUSH);
    selectNone.setText("Select None");
    selectNone.setLayoutData(gdf.create());
    selectNone.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.setAllChecked(false);
            enabledCategories.clear();
        }
    });

    Control spacer = new Composite(buttonArea, SWT.NONE);
    GridData d = gdf.create();
    d.heightHint = 40;
    spacer.setLayoutData(d);

    aboutButton = new Button(buttonArea, SWT.PUSH);
    aboutButton.setText("About...");
    aboutButton.setLayoutData(gdf.create());
    aboutButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                if (!ss.isEmpty() && ss.getFirstElement() instanceof ILoggingCategory) {
                    AboutCategoryDialog dialog = new AboutCategoryDialog(getShell(),
                            (ILoggingCategory) ss.getFirstElement());
                    dialog.open();
                }
            }
        }
    });
    aboutButton.setEnabled(false);

    spacer = new Composite(buttonArea, SWT.NONE);
    d = gdf.create();
    d.heightHint = 40;
    spacer.setLayoutData(d);

    Button uploadButton = new Button(buttonArea, SWT.PUSH);
    uploadButton.setText("Upload Now...");
    uploadButton.setLayoutData(gdf.create());
    uploadButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            WizardDialog dialog = new WizardDialog(getShell(), new UploadWizard());
            dialog.open();
        }
    });
    uploadButton.setEnabled(stale);
    Composite intervalComposite = new Composite(page, SWT.NONE);
    GridData gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = true;
    intervalComposite.setLayoutData(gd);
    intervalComposite.setLayout(new GridLayout(2, false));
    Label intervalLabel = new Label(intervalComposite, SWT.NONE);
    intervalLabel.setText("Upload Interval: ");
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    intervalLabel.setLayoutData(gd);
    intervalViewer = new ComboViewer(intervalComposite, SWT.BORDER | SWT.SINGLE);
    Long[] intervals = new Long[] { UploadJob.UPLOAD_INTERVAL_DAILY, UploadJob.UPLOAD_INTERVAL_WEEKLY,
            UploadJob.UPLOAD_INTERVAL_MONTHLY };
    intervalViewer.setContentProvider(new ArrayContentProvider());
    intervalViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Long) {
                long interval = (Long) element;
                if (interval == UploadJob.UPLOAD_INTERVAL_DAILY) {
                    return "Daily";
                } else if (interval == UploadJob.UPLOAD_INTERVAL_WEEKLY) {
                    return "Every Seven Days";
                } else if (interval == UploadJob.UPLOAD_INTERVAL_MONTHLY) {
                    return "Every Thirty Days";
                }
            }
            return super.getText(element);
        }
    });
    intervalViewer.setInput(intervals);
    long interval = WorkbenchLoggingPlugin.getDefault().getPreferenceStore()
            .getLong(UploadJob.UPLOAD_INTERVAL_KEY);
    if (interval <= 0) {
        interval = WorkbenchLoggingPlugin.getDefault().getPreferenceStore()
                .getDefaultLong(UploadJob.UPLOAD_INTERVAL_KEY);
    }
    intervalViewer.setSelection(new StructuredSelection(interval));
    intervalViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    spacer = new Composite(page, SWT.NONE);
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    gd.heightHint = 2;
    spacer.setLayoutData(gd);
    Composite uidComposite = new Composite(page, SWT.NONE);
    uidComposite.setLayout(new GridLayout(2, false));
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    gd.horizontalSpan = 2;
    uidComposite.setLayoutData(gd);
    Label uidLabel = new Label(uidComposite, SWT.NONE);
    uidLabel.setText("User ID:");
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    uidLabel.setLayoutData(gd);
    final Text uidText = new Text(uidComposite, SWT.SINGLE | SWT.READ_ONLY);
    uidText.setText(WorkbenchLoggingPlugin.getDefault().getLocalUser());
    uidText.addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
         */
        @Override
        public void mouseUp(MouseEvent e) {
            uidText.selectAll();
        }
    });
    MenuManager manager = new MenuManager();
    Menu menu = manager.createContextMenu(uidText);
    uidText.setMenu(menu);
    CommandContributionItemParameter parameters = new CommandContributionItemParameter(
            WorkbenchLoggingPlugin.getDefault().getWorkbench(), null, EDIT_COPY, SWT.PUSH);
    manager.add(new CommandContributionItem(parameters));
    return page;
}

From source file:ca.uvic.cs.tagsea.actions.GoToTagAction.java

License:Open Source License

/**
 * Grabs the currently selected waypoint from the viewer and navigates to
 * that waypoint's marker position in the editor.
 *//*from   www . j  av a  2s.c o m*/
public void run() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (!selection.isEmpty()) {
        Object obj = selection.getFirstElement();
        IMarker marker = null;
        if (obj instanceof Waypoint) {
            // Waypoints TableViewer
            marker = ((Waypoint) obj).getMarker();
        }
        if ((marker != null) && marker.exists()) {
            IResource resource = marker.getResource();
            if (marker.exists() && resource instanceof IFile) {
                try {
                    IDE.openEditor(page, marker, OpenStrategy.activateOnOpen());
                    Monitoring.getDefault().fireEvent(new TagSEANavigationEvent((Waypoint) obj));
                } catch (PartInitException e) {
                    TagSEAPlugin.log("Couldn't open editor to show the tag", e);
                }
            }
        }
    }
}

From source file:ca.uvic.cs.tagsea.core.WaypointProvider.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    selectedTags.clear();//from   w w w . j  a  va  2s. c  o m
    if (!selection.isEmpty()) {
        for (Iterator iter = selection.iterator(); iter.hasNext();) {
            Object obj = iter.next();
            if (obj instanceof Tag) {
                selectedTags.add((Tag) obj);
            }
        }
    }
    tableViewer.refresh();
}