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.centurylink.mdw.plugin.designer.properties.editor.ListComposer.java

License:Apache License

private void rem() {
    IStructuredSelection selection = (IStructuredSelection) destViewer.getSelection();
    if (!selection.isEmpty()) {
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            Object item = it.next();
            destMutableCP.remFromDest(item);
        }/*from   w w  w. ja  v  a 2  s  .c om*/
        destViewer.refresh();
        srcViewer.refresh();
    }
}

From source file:com.centurylink.mdw.plugin.designer.properties.editor.ListComposer.java

License:Apache License

private void add() {
    IStructuredSelection selection = (IStructuredSelection) srcViewer.getSelection();
    if (!selection.isEmpty()) {
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            Object item = it.next();
            destMutableCP.addToDest(item);
        }/*from   w  ww.  j a  va 2s  . c  o  m*/
        destViewer.refresh();
        srcViewer.refresh();
    }
}

From source file:com.cloudbees.eclipse.run.ui.launchconfiguration.ProjectSelectionComposite.java

License:Open Source License

private IJavaElement getSelectedJavaElement() {
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return null;
    }/*from   w  w w.j  av  a2  s.  com*/

    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
    if (activePage == null) {
        return null;
    }

    ISelection selection = activePage.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;

        if (!structuredSelection.isEmpty()) {
            Object element = structuredSelection.getFirstElement();

            if (element instanceof IJavaElement) {
                return (IJavaElement) element;
            }

            if (element instanceof IResource) {
                IJavaElement javaElement = JavaCore.create((IResource) element);

                if (javaElement == null) {
                    IProject project = ((IResource) element).getProject();
                    javaElement = JavaCore.create(project);
                }

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

    IEditorPart part = activePage.getActiveEditor();
    if (part != null) {
        IEditorInput input = part.getEditorInput();
        return (IJavaElement) input.getAdapter(IJavaElement.class);
    }

    return null;
}

From source file:com.codenvy.eclipse.ui.launcher.BuildOnCodenvyShortcut.java

License:Open Source License

@Override
public void launch(ISelection selection, String mode) {
    if (selection instanceof IStructuredSelection && RUN_MODE.equalsIgnoreCase(mode)) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (!structuredSelection.isEmpty()) {
            final IAdaptable adaptable = (IAdaptable) structuredSelection.getFirstElement();
            final IResource resource = (IResource) adaptable.getAdapter(IResource.class);

            if (resource != null && resource.getType() != ROOT) {
                buildProjectOnCodenvy(resource.getProject(), mode);
            }/*ww  w .ja v a  2 s . co  m*/
        }
    }
}

From source file:com.codenvy.eclipse.ui.launcher.RunOnCodenvyShortcut.java

License:Open Source License

@Override
public void launch(ISelection selection, String mode) {
    if (selection instanceof IStructuredSelection && RUN_MODE.equalsIgnoreCase(mode)) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (!structuredSelection.isEmpty()) {
            final IAdaptable adaptable = (IAdaptable) structuredSelection.getFirstElement();
            final IResource resource = (IResource) adaptable.getAdapter(IResource.class);

            if (resource != null && resource.getType() != ROOT) {
                runProjectOnCodenvy(resource.getProject(), mode);
            }/*  w w  w .jav a2 s. c  o m*/
        }
    }
}

From source file:com.codenvy.eclipse.ui.wizard.importer.pages.ProjectWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    final Composite wizardContainer = new Composite(parent, SWT.NONE);
    wizardContainer.setLayout(new GridLayout(2, false));
    wizardContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite workspaceSelectionContainer = new Composite(wizardContainer, SWT.NONE);
    workspaceSelectionContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    workspaceSelectionContainer.setLayout(new GridLayout(2, false));

    final Label workspaceLabel = new Label(workspaceSelectionContainer, SWT.NONE);
    workspaceLabel.setText("Workspace:");

    workspaceComboViewer = new ComboViewer(workspaceSelectionContainer, SWT.DROP_DOWN | SWT.READ_ONLY);
    workspaceComboViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    workspaceComboViewer.setContentProvider(new ArrayContentProvider());
    workspaceComboViewer.setLabelProvider(new LabelProvider() {
        @Override//  w  w  w  .j  ava2s  .  c o  m
        public String getText(Object element) {
            return element instanceof WorkspaceReference ? ((WorkspaceReference) element).name()
                    : super.getText(element);
        }
    });
    workspaceComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                loadWorkspaceProjects((WorkspaceReference) selection.getFirstElement());
            }
        }
    });

    final Label projectTableLabel = new Label(wizardContainer, SWT.NONE);
    projectTableLabel.setText("Projects:");
    projectTableLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    projectTableViewer = newCheckList(wizardContainer,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);

    final TableViewerColumn projectNameColumn = new TableViewerColumn(projectTableViewer, SWT.NONE);
    projectNameColumn.getColumn().setWidth(150);
    projectNameColumn.getColumn().setText("Name");
    projectNameColumn.setLabelProvider(new ColumnLabelProviderWithGreyElement() {
        @Override
        public String getText(Object element) {
            return element instanceof ProjectReference ? ((ProjectReference) element).name()
                    : super.getText(element);
        }
    });

    final TableViewerColumn projectTypeNameColumn = new TableViewerColumn(projectTableViewer, SWT.NONE);
    projectTypeNameColumn.getColumn().setWidth(150);
    projectTypeNameColumn.getColumn().setText("Type");
    projectTypeNameColumn.setLabelProvider(new ColumnLabelProviderWithGreyElement() {
        @Override
        public String getText(Object element) {
            return element instanceof ProjectReference ? ((ProjectReference) element).typeName()
                    : super.getText(element);
        }
    });

    final TableViewerColumn projectDescriptionColumn = new TableViewerColumn(projectTableViewer, SWT.NONE);
    projectDescriptionColumn.getColumn().setWidth(150);
    projectDescriptionColumn.getColumn().setText("Description");
    projectDescriptionColumn.setLabelProvider(new ColumnLabelProviderWithGreyElement() {
        @Override
        public String getText(Object element) {
            return element instanceof ProjectReference ? ((ProjectReference) element).description()
                    : super.getText(element);
        }
    });
    projectTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    projectTableViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            setCheckedProjects();
            validatePage();
        }
    });

    final Table projectTable = projectTableViewer.getTable();
    projectTable.getHorizontalBar().setEnabled(true);
    projectTable.setHeaderVisible(true);
    projectTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite projectTableButtonsContainer = new Composite(wizardContainer, SWT.NONE);
    projectTableButtonsContainer.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));
    projectTableButtonsContainer.setLayout(new GridLayout());

    final Button selectAll = new Button(projectTableButtonsContainer, SWT.NONE);
    selectAll.setText("Select All");
    selectAll.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    selectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            projectTableViewer.setAllChecked(true);

            setCheckedProjects();
            validatePage();
        }
    });

    final Button deselectAll = new Button(projectTableButtonsContainer, SWT.NONE);
    deselectAll.setText("Deselect All");
    deselectAll.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    deselectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            projectTableViewer.setAllChecked(false);

            setCheckedProjects();
            validatePage();
        }
    });

    // TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=245106 is fixed
    final WorkingSetDescriptor[] descriptors = WorkbenchPlugin.getDefault().getWorkingSetRegistry()
            .getWorkingSetDescriptors();
    final List<String> workingSetTypes = FluentIterable.from(Arrays.asList(descriptors))
            .transform(new Function<WorkingSetDescriptor, String>() {
                @Override
                public String apply(WorkingSetDescriptor descriptor) {
                    return descriptor.getId();
                }
            }).toList();

    workingSetGroup = new WorkingSetGroup(wizardContainer, null,
            workingSetTypes.toArray(new String[workingSetTypes.size()]));

    setControl(wizardContainer);
}

From source file:com.codesourcery.internal.installer.ui.pages.LicensePage.java

License:Open Source License

@Override
public void setActive(IInstallData data) {
    super.setActive(data);

    // Update licenses
    updateLicenses(data);/*from   w  w  w  .ja va 2s.  com*/

    // Not running in console mode
    if (!isConsoleMode()) {
        // No licenses
        if (getAllLicenses().length == 0) {
            setInformationTitle(InstallMessages.LicensePageNoComponents);
            showStatus(new IStatus[] { new Status(IStatus.OK, Installer.ID, InstallMessages.ClickNext) });
            getMainArea().setVisible(false);
            setPageComplete(true);
        }
        // Licenses
        else {
            hideStatus();
            getMainArea().setVisible(true);
            setPageComplete(acceptLicenseButton.getSelection());

            list.setSelection(lastLicenseSelection);
            IStructuredSelection ns = (IStructuredSelection) list.getSelection();
            if (ns.isEmpty() && firstLicense != null)
                list.setSelection(new StructuredSelection(firstLicense));

            int currentLicenseCount = list.getList().getItemCount();

            // Check if Item count has been changed
            if (currentLicenseCount != lastLicenseCount) {
                Composite comp = list.getControl().getParent();
                boolean hideList = false;
                String acceptButtonText = InstallMessages.AcceptLicenses;
                String pageTitle = InstallMessages.LicenseMessageMultipleLicenses;

                /* If only one license agreement, change button text
                 * and hide List
                 */
                if (currentLicenseCount == 1) {
                    acceptButtonText = InstallMessages.AcceptLicense;
                    pageTitle = InstallMessages.LicenseMessageSingleLicense;
                    hideList = true;
                }

                // Update Accept button text and Page title
                setInformationTitle(pageTitle);
                acceptLicenseButton.setText(acceptButtonText);

                // Update visibility of list viewer
                ((GridData) comp.getLayoutData()).exclude = hideList;
                comp.setVisible(!hideList);
                comp.getParent().layout();

                // Update License count
                lastLicenseCount = currentLicenseCount;
            }
        }
    }
}

From source file:com.cronopista.mapme.handler.Map.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    Shell shell = HandlerUtil.getActiveShell(event);
    boolean force = event.getCommand().getId().equals("com.cronopista.mapme.mapForce");
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    IStructuredSelection selection = (IStructuredSelection) sel;

    // sanity check
    if (selection.isEmpty()) {
        MessageDialog.openInformation(shell, "Info", "Select two Java files!");
    } else {//  w  w w.  j a va2s  .  c o m
        ArrayList sels = new ArrayList();

        Iterator iterator = selection.iterator();
        while (iterator.hasNext()) {
            sels.add(iterator.next());
        }

        if (sels.size() != 2 || !(sels.get(0) instanceof ICompilationUnit)
                || !(sels.get(1) instanceof ICompilationUnit)) {
            MessageDialog.openInformation(shell, "Info", "Select two Java files!");
        } else {

            // start actual mapping
            mapClasses((ICompilationUnit) sels.get(0), (ICompilationUnit) sels.get(1), force);
        }
    }

    return null;
}

From source file:com.drgarbage.bytecode.jdi.dialogs.SelectDebugTargetDialog.java

License:Apache License

/**
 * Updates the enablement of the dialog's ok button based
 * on the current choices in the dialog.
 *//*from w w  w.  j  av  a2 s.c om*/
protected void updateEnablement() {

    Object newSel = null;
    if (displayCandidates != null) {
        if (tableViewer != null) {
            IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
            if (sel != null && !sel.isEmpty()) {
                newSel = sel.getFirstElement();
            }
        }
    }

    if (newSel instanceof IJavaType[]) {
        selection = (IJavaType[]) newSel;
    } else {
        selection = null;
    }

    boolean enabled = selection != null;
    getButton(OK).setEnabled(enabled);
}

From source file:com.drgarbage.bytecode.jdi.dialogs.SelectJavaTypeDialog.java

License:Apache License

/**
 * Updates the enablement of the dialog's ok button based
 * on the current choices in the dialog.
 *///from  ww  w .  jav a 2 s.  c o m
protected void updateEnablement() {

    Object newSel = null;
    if (displayCandidates != null) {
        if (tableViewer != null) {
            IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
            if (sel != null && !sel.isEmpty()) {
                newSel = sel.getFirstElement();
            }
        }
    }

    if (newSel instanceof IJavaType) {
        selection = (IJavaType) newSel;
    } else {
        selection = null;
    }

    boolean enabled = selection != null;
    getButton(OK).setEnabled(enabled);
}