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

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

Introduction

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

Prototype

public Object getFirstElement();

Source Link

Document

Returns the first element in this selection, or null if the selection is empty.

Usage

From source file:co.turnus.analysis.profiler.orcc.ui.OrccDynamicProfilerLaunchShortcut.java

License:Open Source License

@Override
public IResource getLaunchableResource(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IFile) {
            return (IFile) obj;
        }// w ww.j  a va 2s  .co  m
    }

    return null;
}

From source file:co.turnus.ui.exporter.FileExporterHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get workbench window
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    // set structured selection
    IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();

    File inputFile = null;/*from   w  w w . ja  va2 s .c  o m*/
    // check if it is an IFile
    if (selection.getFirstElement() instanceof IFile) {

        try {
            inputFile = TurnusUtils.getFrom((IFile) selection.getFirstElement());
        } catch (TurnusException e) {
            e.printStackTrace();
        }
    }

    // get only the required extension
    String outExtension = event.getParameter(TurnusUiConstants.COMMAND_OUT_EXTENSION);

    AbstractExporterWizard wizard = null;

    switch (outExtension) {
    case "xml":
        wizard = new XmlExporterWizard();
        wizard.configure(inputFile);
        break;
    case "json":
        wizard = new JsonExporterWizard();
        wizard.configure(inputFile);
        break;
    case "xls":
        wizard = new XlsExporterWizard();
        wizard.configure(inputFile);
        break;
    default:
        break;
    }

    if (wizard != null) {
        new WizardDialog(window.getShell(), wizard).open();
    }
    return null;
}

From source file:co.turnus.ui.exporter.JsonExporterWizard.java

License:Open Source License

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    try {//from   w  w  w  .  j  a v a 2  s.  com
        File file = TurnusUtils.getFrom((IFile) selection.getFirstElement());
        if (file != null) {
            String inExtension = TurnusUtils.getExtension(file);
            for (String ext : SUPPORTED_INPUT_FILES) {
                if (ext.equals(inExtension)) {
                    configure(file);
                    return;
                }
            }
        }

    } catch (TurnusException e) {
    }

}

From source file:co.turnus.ui.exporter.XlsExporterWizard.java

License:Open Source License

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    try {//from  w ww.  j a v  a 2 s .  com
        File file = TurnusUtils.getFrom((IFile) selection.getFirstElement());
        if (file != null) {
            String inExtension = TurnusUtils.getExtension(file);
            for (String ext : SUPPORTED_INPUT_FILES) {
                if (ext.equals(inExtension)) {
                    configure(file);
                    return;
                }
            }
        }

    } catch (TurnusException e) {
    }
}

From source file:co.turnus.ui.profiling.wizard.AbstractWeightsGeneratorHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get workbench window
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    // set structured selection
    IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();

    AbstractWeightsGeneratorWizard wizard = new AbstractWeightsGeneratorWizard();
    // try to configure the input file of the wizard
    try {//from  w ww  . j  a v  a 2s .co  m
        // check if there is an associated file
        if (selection.getFirstElement() instanceof IFile) {
            File file = TurnusUtils.getFrom((IFile) selection.getFirstElement());
            if (file != null && file.exists()
                    && TurnusUtils.getExtension(file).equals(TurnusExtension.PROFILING)) {
                wizard.configure(file);
            }
        }
    } catch (Exception e) { // don't worry! be happy
    }

    // finally, open the dialog
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
    dialog.open();

    return null;
}

From source file:co.turnus.ui.profiling.wizard.AbstractWeightsGeneratorWizard.java

License:Open Source License

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    try {//from  w w  w . j  a v  a  2s  .  co  m
        File file = TurnusUtils.getFrom((IFile) selection.getFirstElement());
        if (file != null) {
            if (TurnusUtils.getExtension(file).equals(TurnusExtension.PROFILING)) {
                configure(file);
            }
        }

    } catch (TurnusException e) {
        e.printStackTrace();
    }

}

From source file:co.turnus.ui.profiling.wizard.TemplateWeightsGeneratorHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get workbench window
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    // set structured selection
    IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();

    TemplateWeightsGeneratorWizard wizard = new TemplateWeightsGeneratorWizard();
    // try to configure the input file of the wizard
    try {//  w ww  .  j av a 2 s .  c  o m
        // check if there is an associated file
        if (selection.getFirstElement() instanceof IFile) {
            File file = TurnusUtils.getFrom((IFile) selection.getFirstElement());
            if (file != null && file.exists()
                    && TurnusUtils.getExtension(file).equals(TurnusExtension.NETWORK)) {
                wizard.configure(file);
            }
        }
    } catch (Exception e) { // don't worry! be happy
    }

    // finally, open the dialog
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
    dialog.open();

    return null;
}

From source file:co.turnus.ui.profiling.wizard.TemplateWeightsGeneratorWizard.java

License:Open Source License

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    try {//  w ww. j a  v  a  2s. c o m
        File file = TurnusUtils.getFrom((IFile) selection.getFirstElement());
        if (file != null) {
            if (TurnusUtils.getExtension(file).equals(TurnusExtension.NETWORK)) {
                configure(file);
            }
        }

    } catch (TurnusException e) {
        e.printStackTrace();
    }

}

From source file:codeshine.utils.TableFieldEditor.java

License:Open Source License

/**
 * <p>//from   w ww .ja  v  a2s  .  c o m
 * Gets the currently selected value of this <code>TableFieldEditor</code>.
 * The value returned by this method depends on the selection column 
 * set up as returned by {@link #getSelectionColumn()}. If the selection
 * column is set to <code>-1</code> the complete row represented as
 * domain object is returned by calling {@link #toString()} on it. 
 * Otherwise the respective column value is queried and returned using
 * the <code>ITableLabelProvider</code> bound to this
 * <code>TableFieldEditor</code>.
 * </p>
 * 
 * @return the currently selected value or an empty <code>String</code> 
 * if no selection 
 * 
 * @see #setSelectionColumn(int)
 * @see #getSelectionColumn()
 */
public String getSelection() {
    IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection();
    if (selection.isEmpty()) {
        /* Empty selection */
        return (StringUtils.EMPTY_STRING);
    } else if (this.selectionColumn == -1) {
        /* Row selection */
        return (selection.getFirstElement().toString());
    } else {
        /* Column selection */
        return (this.labelProvider.getColumnText(selection.getFirstElement(), this.selectionColumn));
    }
}

From source file:codeshine.utils.TableFieldEditor.java

License:Open Source License

/**
 * <p>/*from   w w w  . j av a 2  s.  com*/
 * Informs this field editor's listener, if it has one, about a change to
 * the value (<code>VALUE</code> property) provided that the old and new
 * values are different. This hook is <em>not</em> called when the value is
 * initialized (or reset to the default value) from the preference store.
 * </p>
 */
protected void valueChanged() {

    System.out.println("Invocado ValueChanged");
    this.setPresentsDefaultValue(false);

    final IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection();

    String newValue;
    //        System.out.println("NewVAlue: " + newValue);
    if (selection.isEmpty()) {
        newValue = StringUtils.EMPTY_STRING;
    } else if (this.selectionColumn == -1) {
        newValue = selection.getFirstElement().toString();
    } else {
        newValue = this.labelProvider.getColumnText(selection.getFirstElement(), this.selectionColumn);
    }

    if (newValue.equals(oldValue)) {
        this.fireValueChanged(VALUE, oldValue, newValue);
        oldValue = newValue;
    }
}