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:net.refractions.udig.catalog.internal.wmt.ui.view.WMTZoomLevelSwitcher.java

License:Open Source License

private int getSelectedZoomLevel() {
    StructuredSelection selection = (StructuredSelection) cvZoomLevels.getSelection();

    if (selection.isEmpty()) {
        return zoomLevels[0];
    } else {/*  w  w  w.  j  a  v a 2s  .com*/
        return (Integer) selection.getFirstElement();
    }
}

From source file:net.refractions.udig.catalog.internal.wmt.ui.view.WMTZoomLevelSwitcher.java

License:Open Source License

private ILayer getSelectedLayer() {
    StructuredSelection selection = (StructuredSelection) cvLayers.getSelection();

    if (selection.isEmpty()) {
        return null;
    } else {/*from ww  w .j  a  v a 2s .c  o m*/
        return (ILayer) selection.getFirstElement();
    }
}

From source file:net.refractions.udig.catalog.ui.operation.TransformPanel.java

License:Open Source License

protected Definition selectedDefinition() {
    ISelection selectedRow = table.getSelection();
    if (!selectedRow.isEmpty() && selectedRow instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) selectedRow;
        return (Definition) selection.getFirstElement();
    }//w w w  .j  a  v a 2 s .  c  om
    return null; // nothing to see here
}

From source file:net.refractions.udig.document.ui.DocumentDialog.java

License:Open Source License

/**
 * Creates the info (action type) controls.
 *///from w ww.  j a v  a2 s .c  o m
private void createInfoGoActionControls() {

    infoGoActionLbl = new Label(composite, SWT.NONE);
    infoGoActionLbl.setText(getLabel(Messages.DocumentDialog_actionLabel));
    infoGoActionLbl.setLayoutData(""); //$NON-NLS-1$

    infoGoAction = new ComboViewer(composite, SWT.READ_ONLY | SWT.DROP_DOWN);
    infoGoAction.getControl().setLayoutData("split 2"); //$NON-NLS-1$
    infoGoAction.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            final HotlinkDescriptor descriptor = (HotlinkDescriptor) element;
            return descriptor.getLabel();
        }
    });
    infoGoAction.setContentProvider(ArrayContentProvider.getInstance());
    infoGoAction.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            final StructuredSelection selection = (StructuredSelection) event.getSelection();
            final HotlinkDescriptor descriptor = (HotlinkDescriptor) selection.getFirstElement();
            label.setText(descriptor.getLabel());
            final String descriptionStr = descriptor.getDescription();
            if (descriptionStr == null) {
                description.setText(""); //$NON-NLS-1$
            } else {
                description.setText(descriptionStr);
            }
        }
    });
    final List<HotlinkDescriptor> actions = getActions();
    if (actions != null && actions.size() > 0) {
        infoGoAction.setInput(actions.toArray());
    }

    infoGoActionBtn = new Button(composite, SWT.PUSH);
    infoGoActionBtn.setText(Messages.DocumentDialog_goBtn);
    infoGoActionBtn.setLayoutData(""); //$NON-NLS-1$
    infoGoActionBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final StructuredSelection selection = (StructuredSelection) infoGoAction.getSelection();
            final HotlinkDescriptor descriptor = (HotlinkDescriptor) selection.getFirstElement();
            final String action = descriptor.getConfig().replace(DocumentPropertyPage.ACTION_PARAM,
                    info.getText());
            Program.launch(action);
        }
    });

}

From source file:net.refractions.udig.document.ui.DocumentDialog.java

License:Open Source License

/**
 * Gets the selected value of the combo.
 * /*  w w w .j  a va 2  s  .c om*/
 * @param combo
 * @return selected value
 */
private Object getComboValue(ComboViewer combo) {
    final ISelection selection = combo.getSelection();
    if (!selection.isEmpty() && selection instanceof StructuredSelection) {
        final StructuredSelection structSelection = (StructuredSelection) selection;
        return structSelection.getFirstElement();
    }
    return null;
}

From source file:net.refractions.udig.document.ui.DocumentPropertyPage.java

License:Open Source License

private void createHotlinksTable(Composite parent) {

    final Composite tableComposite = new Composite(parent, SWT.NONE);
    final TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);
    tableComposite.setLayoutData("pushy, grow, wmax 85%"); //$NON-NLS-1$

    hotlinkViewer = new TableViewer(tableComposite,
            SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
    hotlinkViewer.setContentProvider(ArrayContentProvider.getInstance());

    TableViewerColumn column = new TableViewerColumn(hotlinkViewer, SWT.NONE);
    column.getColumn().setText(""); //$NON-NLS-1$
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override/*from  w  w w  .j  ava2 s.  c  o m*/
        public String getText(Object element) {
            return ""; //$NON-NLS-1$
        }

        @Override
        public Image getImage(Object element) {
            final HotlinkDescriptor descriptor = (HotlinkDescriptor) element;
            switch (descriptor.getType()) {
            case FILE:
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
            case WEB:
                return InfoPlugin.getDefault().getImageRegistry().get(InfoPlugin.IMG_OBJ_LINK);
            case ACTION:
                return InfoPlugin.getDefault().getImageRegistry().get(InfoPlugin.IMG_OBJ_ACTION);
            default:
                break;
            }
            return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
        }
    });
    columnLayout.setColumnData(column.getColumn(), new ColumnWeightData(8, 0, false));

    column = new TableViewerColumn(hotlinkViewer, SWT.NONE);
    column.getColumn().setText(Messages.Document_Label_Column);
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            final HotlinkDescriptor descriptor = (HotlinkDescriptor) element;
            return descriptor.getLabel();
        }
    });
    columnLayout.setColumnData(column.getColumn(), new ColumnWeightData(25, 0, true));

    column = new TableViewerColumn(hotlinkViewer, SWT.NONE);
    column.getColumn().setText(Messages.Document_Attribute_Column);
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            HotlinkDescriptor descriptor = (HotlinkDescriptor) element;
            return descriptor.getAttributeName();
        }
    });
    columnLayout.setColumnData(column.getColumn(), new ColumnWeightData(25, 0, true));

    column = new TableViewerColumn(hotlinkViewer, SWT.NONE);
    column.getColumn().setText(Messages.Document_Hotlink_Column);
    column.getColumn().setAlignment(SWT.CENTER);
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            HotlinkDescriptor descriptor = (HotlinkDescriptor) element;
            return DocUtils.toCamelCase(descriptor.getType().toString());
        }
    });
    columnLayout.setColumnData(column.getColumn(), new ColumnWeightData(15, 0, true));

    column = new TableViewerColumn(hotlinkViewer, SWT.NONE);
    column.getColumn().setText(Messages.Document_Action_Column);
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            HotlinkDescriptor descriptor = (HotlinkDescriptor) element;
            if (descriptor.getConfig() == null) {
                return Messages.DocumentPropertyPage_Open;
            }
            return descriptor.getConfig();
        }
    });
    columnLayout.setColumnData(column.getColumn(), new ColumnWeightData(30, 0, true));

    hotlinkViewer.getTable().setHeaderVisible(true);
    hotlinkViewer.getTable().setLinesVisible(true);
    hotlinkViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = event.getSelection();
            editHotlink.setEnabled(!sel.isEmpty());
            removeButton.setEnabled(!sel.isEmpty());
        }
    });
    hotlinkViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            final StructuredSelection selection = (StructuredSelection) hotlinkViewer.getSelection();
            final HotlinkDescriptor descriptor = (HotlinkDescriptor) selection.getFirstElement();
            editDescriptor(descriptor);
        }
    });

}

From source file:net.refractions.udig.document.ui.DocumentPropertyPage.java

License:Open Source License

private void createHotlinksButtons(Composite parent) {

    final Composite buttonComposite = new Composite(parent, SWT.NONE);
    final String btnLayoutConst = "fillx, insets 0, wrap 1"; //$NON-NLS-1$
    final String btnColConst = "[fill]"; //$NON-NLS-1$
    final String btnRowConst = "[][]push[]"; //$NON-NLS-1$
    buttonComposite.setLayout(new MigLayout(btnLayoutConst, btnColConst, btnRowConst));
    buttonComposite.setLayoutData("grow"); //$NON-NLS-1$

    addHotlink = new Button(buttonComposite, SWT.CENTER);
    addHotlink.setText(Messages.Document_Add);
    addHotlink.setLayoutData("grow"); //$NON-NLS-1$
    addHotlink.addSelectionListener(new SelectionAdapter() {
        @Override/*from   www .j  ava2 s . co m*/
        public void widgetSelected(SelectionEvent e) {
            ISelection sel = hotlinkViewer.getSelection();
            if (!sel.isEmpty() && sel instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) sel;
                HotlinkDescriptor descriptor = (HotlinkDescriptor) selection.getFirstElement();

                int index = hotlinkList.indexOf(descriptor);
                addDescriptor(index);
            } else {
                addDescriptor(-1);
            }
        }
    });

    editHotlink = new Button(buttonComposite, SWT.CENTER);
    editHotlink.setText(Messages.Document_Edit);
    editHotlink.setLayoutData(""); //$NON-NLS-1$
    editHotlink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection sel = hotlinkViewer.getSelection();
            if (!sel.isEmpty() && sel instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) sel;
                HotlinkDescriptor descriptor = (HotlinkDescriptor) selection.getFirstElement();
                editDescriptor(descriptor);
            }
        }
    });

    removeButton = new Button(buttonComposite, SWT.CENTER);
    removeButton.setText(Messages.Document_Remove);
    removeButton.setLayoutData(""); //$NON-NLS-1$
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection sel = hotlinkViewer.getSelection();
            if (!sel.isEmpty() && sel instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) sel;
                HotlinkDescriptor descriptor = (HotlinkDescriptor) selection.getFirstElement();

                removeDescriptor(descriptor);
            }
        }
    });

}

From source file:net.refractions.udig.document.ui.DocumentView.java

License:Open Source License

/**
 * Handles list double clicks. This will open the document if the selection is a document and if
 * it is not empty./*from w ww . j a  v a  2 s .co m*/
 * 
 * @param selection
 */
private void handleListDoubleClick(ISelection selection) {
    final StructuredSelection structSelection = (StructuredSelection) selection;
    final Object element = structSelection.getFirstElement();
    if (element instanceof IDocument) {
        final IDocument doc = (IDocument) element;
        if (!doc.isEmpty()) {
            open();
        }
    }
}

From source file:net.refractions.udig.project.ui.internal.LegendView.java

License:Open Source License

/**
 * Checks if the current selection allows deletion.
 * /*from   ww w .j  ava 2  s  .c  o  m*/
 * @return true if allowed, otherwise false
 */
private boolean canDelete() {
    final ISelection selection = viewer.getSelection();
    if (!selection.isEmpty() && selection instanceof StructuredSelection) {
        final StructuredSelection structSelection = (StructuredSelection) selection;
        final Object selectedObj = structSelection.getFirstElement();
        if (selectedObj instanceof LayerLegendItem) {
            return true;
        }
    }
    return false;
}

From source file:net.refractions.udig.tutorials.featureeditor.CountryPanelForm.java

License:Open Source License

private void applyChanges() {

    if (!verifyChanges()) {
        try {//from   w  w  w.j a v  a2 s .  c  o m

            // Set feature value for NAME_FORMA
            editedFeature.setAttribute(NAME_FORMA, nameFormal.getText());

            // Set feature value for NAME_SORT
            editedFeature.setAttribute(NAME_SORT, nameSort.getText());

            // Set feature value for POP_EST
            editedFeature.setAttribute(POP_EST, Double.valueOf(population.getText()));

            // Set feature value for TYPE
            editedFeature.setAttribute(TYPE, type.getSelection() ? TYPE_SOV_LBL : TYPE_COU_LBL);

            // Set feature value for COLOR_MAP
            StructuredSelection colorSelection = (StructuredSelection) colorMap.getSelection();
            editedFeature.setAttribute(COLOR_MAP, colorSelection.getFirstElement());

        } catch (IllegalAttributeException e1) {
            // shouldn't happen.
        }

        final CompositeCommand compComm = new CompositeCommand();
        //Sets the feature (with the edited values) used in the view as the editFeature
        compComm.getCommands().add(new SetEditFeatureCommand(editedFeature));
        //Write the changes to the actual dataset
        compComm.getCommands().add(new WriteEditFeatureCommand());
        context.sendASyncCommand(compComm);

        setEnabled(false);
    }

}