Example usage for org.eclipse.jface.viewers IStructuredSelection toArray

List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection toArray.

Prototype

public Object[] toArray();

Source Link

Document

Returns the elements in this selection as an array.

Usage

From source file:org.eclipse.buckminster.generic.ui.actions.ViewInBrowserAction.java

License:Open Source License

@Override
public void run() {
    IStructuredSelection selection = getStructuredSelection();
    Object[] selected;//from   w  w  w . j a  va2s .c  om
    if (selection == null || (selected = selection.toArray()).length < 1) {
        showMessage(Messages.show_in_browser, Messages.nothing_was_selected);
        return;
    }
    Object sel = selected[0];
    IDescribedURL describedURL = null;
    if (sel instanceof IAdaptable) {
        if (feed)
            describedURL = (IDescribedURL) ((IAdaptable) sel).getAdapter(IBrowseableFeed.class);
        else
            describedURL = (IDescribedURL) ((IAdaptable) sel).getAdapter(IBrowseable.class);

    }
    if (describedURL == null) {
        showError(Messages.can_not_open_browser, Messages.no_valid_URL_for_selected_object);
        return;
    }

    IWebBrowser browser;
    try {
        browser = browserSupport.createBrowser(
                internal ? IWorkbenchBrowserSupport.AS_EDITOR : IWorkbenchBrowserSupport.AS_EXTERNAL, null,
                describedURL.getName(), describedURL.getTooltip());
        browser.openURL(describedURL.getBrowseableURL());
    } catch (PartInitException e) {
        e.printStackTrace();
    }

}

From source file:org.eclipse.buildship.ui.taskview.WorkbenchSelectionListener.java

License:Open Source License

private void selectionChanged(IStructuredSelection structuredSelection) {
    ImmutableList<IProject> projects = convertToProjects(ImmutableList.copyOf(structuredSelection.toArray()));
    selectProjectsInTree(projects);/*from w  ww.  j  a va  2s.co m*/
}

From source file:org.eclipse.cdt.internal.autotools.ui.wizards.ConvertToAutotoolsProjectWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    super.createControl(parent);
    IStructuredSelection sel = ((BasicNewResourceWizard) getWizard()).getSelection();
    if (sel != null) {
        tableViewer.setCheckedElements(sel.toArray());
        setPageComplete(validatePage());
    }// w  w  w  . j  a v a  2 s . c  om
}

From source file:org.eclipse.cdt.internal.ui.actions.FormatAllAction.java

License:Open Source License

private ITranslationUnit[] getTranslationUnits(IStructuredSelection selection) {
    HashSet<ICElement> result = new HashSet<ICElement>();
    Object[] selected = selection.toArray();
    for (int i = 0; i < selected.length; i++) {
        try {/*from  w ww.j av  a  2  s .  co  m*/
            if (selected[i] instanceof ICElement) {
                ICElement elem = (ICElement) selected[i];
                if (elem.exists()) {
                    switch (elem.getElementType()) {
                    case ICElement.C_UNIT:
                        result.add(elem);
                        break;
                    case ICElement.C_CCONTAINER:
                        collectTranslationUnits((ICContainer) elem, result);
                        break;
                    case ICElement.C_PROJECT:
                        collectTranslationUnits((ICProject) elem, result);
                        break;
                    }
                }
            } else if (selected[i] instanceof IProject) {
                final IProject project = (IProject) selected[i];
                if (CoreModel.hasCNature(project)) {
                    collectTranslationUnits(CoreModel.getDefault().create(project), result);
                }
            }
        } catch (CModelException e) {
            CUIPlugin.log(e);
        }
    }
    return result.toArray(new ITranslationUnit[result.size()]);
}

From source file:org.eclipse.cdt.internal.ui.actions.FormatAllAction.java

License:Open Source License

private boolean isEnabled(IStructuredSelection selection) {
    Object[] selected = selection.toArray();
    for (int i = 0; i < selected.length; i++) {
        if (selected[i] instanceof ICElement) {
            ICElement elem = (ICElement) selected[i];
            if (elem.exists()) {
                switch (elem.getElementType()) {
                case ICElement.C_UNIT:
                case ICElement.C_CCONTAINER:
                case ICElement.C_PROJECT:
                    return true;
                }/*from www  .j av a 2 s .c  om*/
            }
        } else if (selected[i] instanceof IProject) {
            if (CoreModel.hasCNature((IProject) selected[i])) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.cdt.launch.ui.CEnvironmentTab.java

License:Open Source License

protected void remove() {
    IStructuredSelection selection = (IStructuredSelection) fVariableList.getSelection();
    Object[] elements = selection.toArray();
    for (int i = 0; i < elements.length; ++i)
        fElements.remove(((Map.Entry) elements[i]).getKey());
    fVariableList.refresh();//  w  w  w  . jav a2 s. c o  m
    updateButtons();
    updateLaunchConfigurationDialog();
}

From source file:org.eclipse.cdt.make.ui.wizards.ConvertToMakeProjectWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    IStructuredSelection sel = ((BasicNewResourceWizard) getWizard()).getSelection();
    if (sel != null) {
        tableViewer.setCheckedElements(sel.toArray());
        setPageComplete(validatePage());
    }// ww  w .j  a  v a  2s .co m
}

From source file:org.eclipse.cdt.managedbuilder.internal.ui.commands.RebuildConfigurationsHandler.java

License:Open Source License

/**
 * Returns a list of CDT projects from the selection.
 *//*from   w  ww . j  ava2  s. c o  m*/
public static List<IProject> getSelectedCdtProjects(IStructuredSelection selection) {
    if (selection.isEmpty())
        return Collections.emptyList();

    List<IProject> projects = new ArrayList<>();

    for (Object element : selection.toArray()) {
        IProject project = null;
        if (element instanceof IProject) {
            project = (IProject) element;
        } else if (element instanceof ICProject) {
            project = ((ICProject) element).getProject();
        }

        if (project != null && CoreModel.getDefault().isNewStyleProject(project)) {
            projects.add(project);
        }
    }
    return projects;
}

From source file:org.eclipse.cdt.oprofile.ui.system.SystemProfileView.java

License:Open Source License

private void _saveDisplayInfo(String event) {
    // Save event display info
    DisplayInfo info = new DisplayInfo();

    ScrollBar bar = _viewer.getTree().getVerticalBar();
    info.verticalPosition = (bar == null ? 0 : bar.getSelection());
    info.expandedElements = _viewer.getExpandedElements();
    IStructuredSelection sel = (IStructuredSelection) _viewer.getSelection();
    if (sel.isEmpty())
        info.selection = null;/*w w  w . jav a2  s.  c  o  m*/
    else
        info.selection = sel.toArray();

    _displays.put(event, info);
}

From source file:org.eclipse.cdt.ui.actions.OpenAction.java

License:Open Source License

@Override
public void run(IStructuredSelection selection) {
    if (!checkEnabled(selection))
        return;//from   w  w  w  . ja v a2s.co  m
    run(selection.toArray());
}