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

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

Introduction

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

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.nextep.designer.sqlgen.ui.editors.sql.SQLContentOutlinePage.java

License:Open Source License

/**
 * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
 *///from w  ww.ja va2  s.  co m
@Override
public void createControl(Composite parent) {
    outlineTree = new Tree(parent, SWT.NONE);
    selProvider = TreeSelectionProvider.handle(outlineTree, false);
    addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection sel = (StructuredSelection) selProvider.getSelection();
            if (!sel.isEmpty() && packageConnector.getModel() instanceof IPackage) {
                IParseable pkg = (IParseable) packageConnector.getModel();
                setInternalSelection(pkg, sel.getFirstElement());
            }
        }
    });
    Object model = ((ISQLEditorInput) editor.getEditorInput()).getModel();
    if (model != null) {
        packageConnector = UIControllerFactory.getController(model).initializeNavigator(model);
        packageConnector.setTree(outlineTree);
        packageConnector.create(null, -1);
        //        if(packageConnector instanceof PackageNavigator) {
        //           ((PackageNavigator)packageConnector).dedicatedChildInit();
        //        }
        packageConnector.initialize();
        packageConnector.refreshConnector();
        packageConnector.getSWTConnector().setExpanded(true);
    }
}

From source file:com.nextep.designer.sqlgen.ui.editors.sql.SQLContentOutlinePage.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
 *//*w ww . j  a va 2  s. com*/
@Override
public ISelection getSelection() {
    StructuredSelection sel = (StructuredSelection) selProvider.getSelection();
    if (!sel.isEmpty() && packageConnector.getModel() instanceof IPackage) {
        IParseable pkg = (IParseable) packageConnector.getModel();
        setInternalSelection(pkg, sel.getFirstElement());
    }
    return sel;
}

From source file:com.nokia.cdt.internal.debug.launch.ui.ChooseProcessDialog.java

License:Open Source License

@Override
protected void okPressed() {
    StructuredSelection selectedItems = (StructuredSelection) viewer.getSelection();
    Check.checkState(!selectedItems.isEmpty());
    Object object = selectedItems.getFirstElement();
    Check.checkState(object instanceof ParsedProcess);
    selectedProcess = parsedProcessMap.get(object);
    super.okPressed();
}

From source file:com.nokia.tools.s60.editor.dnd.S60BaseDropListener.java

License:Open Source License

public static Object getDropData(DropTargetEvent evt) {
    Transfer t = null;//from w  ww  .  j a v a2s  .co  m

    if (FileTransfer.getInstance().isSupportedType(evt.currentDataType))
        t = FileTransfer.getInstance();
    else if (TextTransfer.getInstance().isSupportedType(evt.currentDataType))
        t = TextTransfer.getInstance();
    else if (LocalSelectionTransfer.getInstance().isSupportedType(evt.currentDataType))
        t = LocalSelectionTransfer.getInstance();

    if (t.isSupportedType(evt.currentDataType)) {

        if (t instanceof LocalSelectionTransfer) {

            // this is just for dropping colors
            LocalSelectionTransfer tempT = (LocalSelectionTransfer) t;

            StructuredSelection selection = (StructuredSelection) tempT.getSelection();
            if (selection != null && !selection.isEmpty()) {
                Object data = selection.getFirstElement();
                if (data instanceof DraggedColorObject) {
                    return data;
                }
            }
            // end for dropping color

            Object data = evt.data;
            if (data == null) {
                data = ((LocalSelectionTransfer) t).nativeToJava(evt.currentDataType);
            }
            if (data != null) {
                Object imageData = ((IStructuredSelection) data).getFirstElement();
                return imageData;
            }
        }

        if (t instanceof FileTransfer) {
            Object data = evt.data;
            if (data == null) {
                data = ((FileTransfer) t).nativeToJava(evt.currentDataType);
            }
            return (String[]) data;
        }

        if (t instanceof TextTransfer) {
            Object data = evt.data;
            if (data == null) {
                data = ((TextTransfer) t).nativeToJava(evt.currentDataType);
            }
            String text = (String) data;
            return text;
        }

    }

    return null;
}

From source file:com.nokia.tools.s60.views.ResourceView2.java

License:Open Source License

/**
 * synchronizes selection to element that contains item in
 * <i>selection</i>./*from w  w w .  j  a v a  2s  .com*/
 * 
 * @param selection
 */
public void showSelection(StructuredSelection selection) {
    if (null != selection && !selection.isEmpty() && getCurrentPage() instanceof ResourceViewPage) {
        ((ResourceViewPage) getCurrentPage()).showSelection(selection);
    }
}

From source file:com.nokia.tools.screen.ui.views.ResourceViewPart.java

License:Open Source License

/**
 * added synchronizes selection to element that contains item in
 * <i>selection</i>.//from ww w.j av a 2s  .c  o  m
 * 
 * @param selection
 */
public void showSelection(StructuredSelection selection) {
    if (null != selection && !selection.isEmpty() && getCurrentPage() instanceof ResourcePage) {
        ((ResourcePage) getCurrentPage()).showSelection(selection);
    }
}

From source file:com.redhat.ceylon.eclipse.code.open.FilteredItemsSelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite dialogArea = (Composite) super.createDialogArea(parent);

    final Composite content = new Composite(dialogArea, SWT.NONE);
    content.setLayoutData(new GridData(GridData.FILL_BOTH));

    GridLayout layout = new GridLayout();
    layout.numColumns = 1;//ww w.j  a  va2s.com
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    content.setLayout(layout);

    createPatternInput(content);

    final Label listLabel = createLabels(content);

    sash = new SashForm(content, SWT.HORIZONTAL | SWT.SMOOTH);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite composite = new Composite(sash, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(GridLayoutFactory.fillDefaults().create());
    list = new TableViewer(composite,
            (multi ? SWT.MULTI : SWT.SINGLE) | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
    list.getTable().getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                e.result = LegacyActionTools.removeMnemonics(listLabel.getText());
            }
        }
    });
    list.setContentProvider(contentProvider);
    list.setLabelProvider(itemsListLabelProvider);
    list.setInput(new Object[0]);
    list.setItemCount(contentProvider.getNumberOfElements());
    applyDialogFont(list.getTable());
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = list.getTable().getItemHeight() * 15;
    list.getTable().setLayoutData(gd);

    if (enableDocArea()) {
        browser = new DocBrowser(sash, SWT.BORDER);
        browser.addLocationListener(new LocationListener() {
            @Override
            public void changing(LocationEvent event) {
                String location = event.location;
                //necessary for windows environment (fix for blank page)
                //somehow related to this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=129236
                if (!"about:blank".equals(location) && !location.startsWith("http:")) {
                    event.doit = false;
                    handleLink(event.location, browser);
                }
            }

            @Override
            public void changed(LocationEvent event) {
            }
        });
        refreshBrowserContent(browser, null);
        setDocAreaVisible(toggleDocAction == null || toggleDocAction.isChecked());
    }

    createPopupMenu();

    pattern.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            applyFilter();
        }
    });

    pattern.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                if (list.getTable().getItemCount() > 0) {
                    list.getTable().setFocus();
                }
            }
        }
    });

    list.addSelectionChangedListener(new ISelectionChangedListener() {
        boolean first = true;

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            handleSelected(selection);
            //we need to re-layout the status area *only* the 
            //very first time an icon is displayed!
            if (first && selection != null && !selection.isEmpty()) {
                statusArea.getParent().layout();
                first = false;
            }
        }
    });

    list.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            handleDoubleClick();
        }
    });

    list.getTable().addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {

            if (e.keyCode == SWT.DEL) {

                List selectedElements = ((StructuredSelection) list.getSelection()).toList();

                Object item = null;
                boolean isSelectedHistory = true;

                for (Iterator it = selectedElements.iterator(); it.hasNext();) {
                    item = it.next();
                    if (item instanceof ItemsListSeparator || !isHistoryElement(item)) {
                        isSelectedHistory = false;
                        break;
                    }
                }
                if (isSelectedHistory)
                    removeSelectedItems(selectedElements);

            }

            if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) {
                StructuredSelection selection = (StructuredSelection) list.getSelection();

                if (selection.size() == 1) {
                    Object element = selection.getFirstElement();
                    if (element.equals(list.getElementAt(0))) {
                        pattern.setFocus();
                    }
                    if (list.getElementAt(
                            list.getTable().getSelectionIndex() - 1) instanceof ItemsListSeparator)
                        list.getTable().setSelection(list.getTable().getSelectionIndex() - 1);
                    list.getTable().notifyListeners(SWT.Selection, new Event());

                }
            }

            if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0
                    && (e.stateMask & SWT.CTRL) != 0) {

                if (list.getElementAt(list.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator)
                    list.getTable().setSelection(list.getTable().getSelectionIndex() + 1);
                list.getTable().notifyListeners(SWT.Selection, new Event());
            }

        }
    });

    createStatusArea(content);

    applyDialogFont(content);

    restoreDialog(getDialogSettings());

    if (initialPatternText != null) {
        pattern.setText(initialPatternText);
    }

    switch (selectionMode) {
    case CARET_BEGINNING:
        pattern.setSelection(0, 0);
        break;
    case FULL_SELECTION:
        pattern.setSelection(0, initialPatternText.length());
        break;
    }

    // apply filter even if pattern is empty (display history)
    applyFilter();

    return dialogArea;
}

From source file:com.toubassi.filebunker.ui.restore.RestoreController.java

License:Open Source License

private void explorerSelectionChanged() {
    StructuredSelection selection = explorer.getSelection();

    spec.clear();/*  ww  w .  jav a  2s. c o m*/
    Iterator i = selection.iterator();
    while (i.hasNext()) {
        Revision revision = (Revision) i.next();

        if (revision.isDirectory()) {
            spec.add((DirectoryRevision) revision, dateChooser.selectedDate());
        } else {
            spec.add((FileRevision) revision);
        }
    }

    restoreButton.setEnabled(!selection.isEmpty());
    descriptionController.update(spec);
}

From source file:com.toubassi.filebunker.ui.restore.ShowHistoryAction.java

License:Open Source License

public void run() {
    StructuredSelection selection = explorer.getSelection();

    if (selection.isEmpty()) {
        return;/*from w w w  .ja  v  a 2  s.  co  m*/
    }

    Revision revision = (Revision) selection.getFirstElement();

    /*
    if (revision.isDirectory()) {
    return;
    }
    */

    String infoTitle = "History of " + revision.node().name();
    TreeSet datesSet = new TreeSet(Collections.reverseOrder());
    String description;

    if (revision.isDirectory()) {
        description = "Below are all dates that files inside this folder "
                + "were backed up.  You can select one and click the Restore "
                + "button to retrieve the contents of the folder as of that " + "date.";

        revision.node().collectDescendantFileRevisionDates(datesSet);
    } else {
        description = "Below are all backed up versions of " + revision.node().name()
                + ".  You can select one and click the Restore button " + "to retrieve that version.";

        revision.node().collectFileRevisionDates(datesSet);
    }

    ObjectChooserDialog dialog = new ObjectChooserDialog(explorer.getShell(), datesSet.toArray(), "History",
            infoTitle, description, "Restore");
    dialog.setFormat(LabelUtil.shortDateTimeSecondsFormat);

    Date date = (Date) dialog.run();

    if (date != null) {
        RestoreSpecification spec = new RestoreSpecification();
        Revision restoreRevision = vault.findRevision(revision.node().file(), date);
        if (restoreRevision.isDirectory()) {
            spec.add((DirectoryRevision) restoreRevision, date);
        } else {
            spec.add((FileRevision) restoreRevision);
        }

        controller.restore(spec);
    }
}

From source file:com.toubassi.filebunker.ui.restore.ShowHistoryAction.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    StructuredSelection selection = (StructuredSelection) event.getSelection();

    boolean enabled = false;
    if (!selection.isEmpty()) {
        Revision revision = (Revision) selection.getFirstElement();

        enabled = !revision.isDirectory();
    }//  ww  w  .  j a v a  2 s. com
    setEnabled(enabled);
}