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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:com.dtsworkshop.flextools.search.ui.SearchResultPage.java

License:Open Source License

private void handleDoubleClick(DoubleClickEvent event) {
    //TODO: Handle search result double click - show result in viewer
    Assert.isTrue(event.getSelection() instanceof StructuredSelection);
    StructuredSelection selection = (StructuredSelection) event.getSelection();
    if (selection.getFirstElement() instanceof SearchReference) {
        showReferenceInEditor((SearchReference) selection.getFirstElement());
    } else if (selection.getFirstElement() instanceof IFile) {
        IFile selectedFile = (IFile) selection.getFirstElement();
        try {/*from  w  ww.j a  v a 2s  .c  om*/

            opener.open(selectedFile, true);
        } catch (PartInitException e) {
            e.printStackTrace();
            FlexToolsLog.logError(
                    String.format("Error initialising editor for file %s", selectedFile.getName()), e);
        }
    } else {
        //TODO: Throw exception on invalid double click selection
    }
}

From source file:com.foglyn.helpers.FBStatusesComboViewer.java

License:Open Source License

public Set<StatusID> getSelectedStatuses() {
    StructuredSelection ssel = (StructuredSelection) getSelection();
    if (ssel.isEmpty()) {
        return null;
    }//from ww  w . j a  va 2 s.  c  o m

    Assert.isTrue(ssel.size() == 1);

    Object obj = ssel.getFirstElement();
    if (HelperConstants.NULL_VALUE.equals(obj)) {
        return null;
    }

    FBStatusItem fbsi = (FBStatusItem) obj;
    return fbsi.getStatuses();
}

From source file:com.google.dart.tools.ui.actions.ShowInFinderAction.java

License:Open Source License

public void updateEnablement() {

    boolean enabled = false;

    ISelection selection = getSelection();
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (!structuredSelection.isEmpty() && structuredSelection.getFirstElement() instanceof IResource) {
            enabled = true;/*from w  w w  .  jav a2 s.com*/
        }
    }

    setEnabled(enabled);
}

From source file:com.google.dart.tools.ui.actions.ShowInFinderAction.java

License:Open Source License

@Override
protected void doRun(Event event, UIInstrumentationBuilder instrumentation) {
    ISelection selection = getSelection();
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (structuredSelection.isEmpty()) {
            return;
        }/*from  ww  w  .jav  a  2s .  com*/
        Object element = structuredSelection.getFirstElement();
        if (!(element instanceof IResource)) {
            return;
        }
        IResource resource = (IResource) element;
        instrumentation.data("path", resource.getLocation().toOSString());
        String path = resource.getLocation().toOSString();
        try {
            if (SystemUtils.IS_OS_LINUX) {
                try {
                    new ProcessBuilder("/usr/bin/nautilus", path).start();
                } catch (IOException e) {
                    // no Nautilus, try generic xdg-open
                    if (resource instanceof IFile) {
                        path = resource.getParent().getLocation().toOSString();
                    }
                    new ProcessBuilder("/usr/bin/xdg-open", path).start();
                }
                return;
            }
            if (SystemUtils.IS_OS_MAC) {
                new ProcessBuilder("/usr/bin/open", "-R", path).start();
                return;
            }
            if (SystemUtils.IS_OS_WINDOWS) {
                new ProcessBuilder("Explorer.exe", "/select,", path).start();
                return;
            }
        } catch (IOException e) {
            instrumentation.record(e);
            ErrorDialog.openError(window.getShell(), null, null,
                    DartToolsPlugin.createErrorStatus("Cannot " + getText(), e));
        }
    }
}

From source file:com.google.eclipse.protobuf.ui.util.IProjects.java

License:Open Source License

public IProject activeProject() {
    for (IViewReference reference : viewReferencesInActivePage()) {
        IViewPart part = reference.getView(false);
        if (part instanceof ResourceNavigator) {
            ResourceNavigator navigator = (ResourceNavigator) part;
            StructuredSelection selection = (StructuredSelection) navigator.getTreeViewer().getSelection();
            IResource resource = (IResource) selection.getFirstElement();
            return resource.getProject();
        }//from  w  w w.  j  a v a  2  s . c om
    }
    return null;
}

From source file:com.google.gwt.eclipse.core.launch.ui.GWTJUnitSettingsTab.java

License:Open Source License

public void performApply(ILaunchConfigurationWorkingCopy config) {
    StructuredSelection logLevelSelection = (StructuredSelection) logLevelComboViewer.getSelection();
    config.setAttribute(GWTLaunchConstants.ATTR_LOG_LEVEL, logLevelSelection.getFirstElement().toString());

    StructuredSelection outputStyleSelection = (StructuredSelection) outputStyleComboViewer.getSelection();
    config.setAttribute(GWTLaunchConstants.ATTR_OBFUSCATION, outputStyleSelection.getFirstElement().toString());

    config.setAttribute(GWTLaunchConstants.ATTR_NOT_HEADLESS, notHeadlessButton.getSelection());

    config.setAttribute(GWTLaunchConstants.ATTR_WEB_MODE, Boolean.toString(webModeButton.getSelection()));

    config.setAttribute(GWTLaunchConstants.ATTR_STANDARDS_MODE, standardsModeButton.getSelection());

    config.setAttribute(GWTLaunchConstants.ATTR_OUT_DIR, outputDirectoryField.getText());
}

From source file:com.google.gwt.eclipse.oophm.views.hierarchical.BreadcrumbNavigationView.java

License:Open Source License

private IModelNode getFirstElementInSelection() {
    StructuredSelection currentSelection = (StructuredSelection) getSelection();
    if (currentSelection == null || currentSelection.isEmpty()) {
        return null;
    }/*from  w w w  .jav  a2 s .c o  m*/

    return (IModelNode) currentSelection.getFirstElement();
}

From source file:com.google.gwt.eclipse.oophm.views.hierarchical.EnterKeyTreeToggleKeyAdapter.java

License:Open Source License

private Object getSelectedElement() {
    ISelection selection = treeViewer.getSelection();
    if (selection == null || selection.isEmpty()) {
        return null;
    }/*  w ww.  ja va2  s  .c o  m*/
    StructuredSelection structuredSelection = (StructuredSelection) (selection);
    return structuredSelection.getFirstElement();
}

From source file:com.google.gwt.eclipse.oophm.views.hierarchical.LaunchConfigurationContent.java

License:Open Source License

private String getSelectedUrl() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    return selection != null && !selection.isEmpty() ? (String) selection.getFirstElement() : null;
}

From source file:com.google.gwt.eclipse.oophm.views.hierarchical.LogContent.java

License:Open Source License

private void updateDetailsPane(SelectionChangedEvent event) {
    StructuredSelection structuredSelection = (StructuredSelection) event.getSelection();
    if (structuredSelection == null || structuredSelection.isEmpty()) {
        scrolledFormDetailsText.setText("");
        return;/*from  w  w  w .ja  v a2  s.  com*/
    }

    LogEntry<?> logEntry = (LogEntry<?>) (structuredSelection.getFirstElement());
    Color foregroundColor = logLabelProvider.getForeground(logEntry);
    scrolledFormDetailsText.setForeground(foregroundColor);

    LogEntry.Data data = logEntry.getLogData();

    StringBuffer buf = new StringBuffer();
    buf.append("<p>");

    Date logEntryDate = new Date(data.getTimestamp());
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
    buf.append(simpleDateFormat.format(logEntryDate));

    // Add the log level
    // FIXME: Need coloring here, for error entries.
    buf.append(" [");
    buf.append(logEntry.getLogData().getLogLevel());
    buf.append("]");

    // Add the module name
    buf.append(" [");
    buf.append(logEntry.getModuleHandle().getName());
    buf.append("] ");

    buf.append(buildLabelHtml(logEntry));
    buf.append("<br/>");

    // Add the detailed information, if available
    String details = buildDetailsHtml(logEntry.getLogData().getDetails());
    if (details.length() > 0) {
        buf.append("<br/>");
        buf.append(details);
        buf.append("<br/>");
    }

    /*
     * Add help information, if available.
     */
    String helpInfoURL = logEntry.getLogData().getHelpInfoURL();
    if (helpInfoURL.length() > 0) {
        String escapedHelpInfoURL = convertToHtmlContent(helpInfoURL);
        buf.append("<br/>");
        buf.append("See the following URL for additional information:<br/>");
        buf.append("<br/>");
        buf.append("<a href='");
        buf.append(escapedHelpInfoURL);
        buf.append("'>");
        buf.append(escapedHelpInfoURL);
        buf.append("</a>");
        buf.append("<br/>");
    } else {
        /*
         * TODO: We always defer to the Help Info URL, as the Help Info text is in
         * HTML, and we're not rendering HTML in this region as yet.
         */
    }
    buf.append("</p>");
    String text = buf.toString();
    scrolledFormDetailsTextContents = collapseHtmlFormatting(text);
    scrolledFormDetailsText.setText(text);
}