Search in sources :

Example 81 with ISelection

use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.

the class AbstractWFSCapabilitiesPage method createContent.

@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));
    // capabilities field
    location = new WFSCapabilitiesFieldEditor("location", "GetCapabilities URL", page) {

        @Override
        protected WFSVersion getWFSVersion() {
            if (versionSelect != null) {
                ISelection sel = versionSelect.getSelection();
                if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                    Object selected = ((IStructuredSelection) sel).getFirstElement();
                    if (NoObject.NONE.equals(selected)) {
                        return null;
                    }
                    return (WFSVersion) selected;
                }
            }
            return super.getWFSVersion();
        }
    };
    location.setPage(this);
    location.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                update();
            }
        }
    });
    String currentValue = getCapabilitiesURL(getWizard().getConfiguration());
    if (currentValue != null) {
        location.setValue(currentValue);
    }
    // version field
    Label vLabel = new Label(page, SWT.NONE);
    vLabel.setText("WFS version");
    versionSelect = new ComboViewer(page, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(versionSelect.getControl());
    versionSelect.setContentProvider(new EnumContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            Object[] values = super.getElements(inputElement);
            // add a NoObject
            values = Arrays.copyOf(values, values.length + 1, Object[].class);
            values[values.length - 1] = NoObject.NONE;
            return values;
        }
    });
    versionSelect.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof NoObject) {
                return "Based on URL / server default";
            }
            return super.getText(element);
        }
    });
    versionSelect.setInput(WFSVersion.class);
    versionSelect.setSelection(new StructuredSelection(NoObject.NONE));
    versionSelect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            location.revalidate();
        }
    });
    setControl(page);
    update();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WFSVersion(eu.esdihumboldt.hale.io.wfs.WFSVersion) EnumContentProvider(eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 82 with ISelection

use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.

the class SelectionContextProvider method getContext.

/**
 * @see IContextProvider#getContext(Object)
 */
@Override
public IContext getContext(Object target) {
    // provide a context based on the selection
    ISelection selection = selectionProvider.getSelection();
    IContext defaultContext = null;
    if (defaultContextId != null) {
        defaultContext = HelpSystem.getContext(defaultContextId);
    }
    List<IContext> contexts = new ArrayList<IContext>();
    if (selection instanceof IStructuredSelection) {
        for (Object object : ((IStructuredSelection) selection).toList()) {
            IContext context = getSelectionContext(object);
            if (context != null) {
                contexts.add(context);
            }
        }
    }
    if (contexts.size() == 1) {
        if (defaultContext == null) {
            return contexts.get(0);
        } else {
            // create context enhanced with default topics
            return new ContextWrapper(contexts.get(0), Arrays.asList(defaultContext.getRelatedTopics()));
        }
    } else if (!contexts.isEmpty()) {
        LinkedHashSet<IHelpResource> topics = new LinkedHashSet<IHelpResource>();
        Set<String> hrefs = new HashSet<String>();
        // collect topics
        for (IContext context : contexts) {
            for (IHelpResource topic : context.getRelatedTopics()) {
                if (!hrefs.contains(topic.getHref())) {
                    // ensure that the
                    // same topic is
                    // only added once
                    topics.add(topic);
                    hrefs.add(topic.getHref());
                }
            }
        }
        if (!topics.isEmpty()) {
            if (defaultContext == null) {
                return new ContextImpl(// XXX
                "Multiple selected objects, see below for related topics.", // improve?!
                topics.toArray(new IHelpResource[topics.size()]));
            } else {
                // create a context enhanced with the selection topics
                return new ContextWrapper(defaultContext, topics);
            }
        }
    }
    // by default, get the view context
    return defaultContext;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IContext(org.eclipse.help.IContext) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ContextImpl(eu.esdihumboldt.hale.ui.common.help.internal.ContextImpl) ISelection(org.eclipse.jface.viewers.ISelection) IHelpResource(org.eclipse.help.IHelpResource) ContextWrapper(eu.esdihumboldt.hale.ui.common.help.internal.ContextWrapper)

Example 83 with ISelection

use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.

the class JoinParameterPage method getCurrentSelection.

/**
 * Returns the currently selected index or -1.
 *
 * @return the currently selected index or -1
 */
private int getCurrentSelection() {
    ISelection selection = table.getSelection();
    if (selection.isEmpty())
        return -1;
    else {
        IStructuredSelection sel = (IStructuredSelection) selection;
        TypeEntityDefinition type = (TypeEntityDefinition) sel.getFirstElement();
        return types.indexOf(type);
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 84 with ISelection

use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.

the class SourceListParameterPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    GridLayout layout = GridLayoutFactory.swtDefaults().create();
    // Add margin to leave space for control decorations
    layout.marginLeft = 5;
    layout.marginRight = 5;
    page.setLayout(layout);
    // input field
    textField = createAndLayoutTextField(page);
    // let subclasses for example add validation
    configure(textField);
    addContentProposalProvider(projectVariablesProposalsProvider);
    setText(textField, initialValue);
    // variables
    Label label = new Label(page, SWT.NONE);
    label.setText("Available variables (double click to insert)");
    label.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(4, 12).create());
    // variables table
    Composite tableComposite = new Composite(page, SWT.NONE);
    tableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 100).create());
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);
    varTable = new TableViewer(tableComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    varTable.getTable().setHeaderVisible(true);
    TableViewerColumn entityColumn = new TableViewerColumn(varTable, SWT.NONE);
    columnLayout.setColumnData(entityColumn.getColumn(), new ColumnWeightData(2, true));
    entityColumn.getColumn().setText("Entity");
    varTable.setContentProvider(ArrayContentProvider.getInstance());
    varTable.setLabelProvider(new StyledDefinitionLabelProvider(varTable) {

        @Override
        protected Object extractElement(Object element) {
            if (element instanceof Entry) {
                return ((Entry<?, ?>) element).getKey();
            }
            return super.extractElement(element);
        }
    });
    varTable.getTable().addMouseListener(new MouseAdapter() {

        /**
         * @see MouseAdapter#mouseDoubleClick(MouseEvent)
         */
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            ISelection sel = varTable.getSelection();
            if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                Object selected = ((IStructuredSelection) sel).getFirstElement();
                if (selected instanceof Entry) {
                    selected = ((Entry<?, ?>) selected).getValue();
                }
                insertTextAtCurrentPos(textField, selected.toString());
            }
        }
    });
    // variable name column
    TableViewerColumn varColumn = new TableViewerColumn(varTable, SWT.NONE);
    columnLayout.setColumnData(varColumn.getColumn(), new ColumnWeightData(1, true));
    varColumn.getColumn().setText("Variable");
    varColumn.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            if (element instanceof Entry) {
                element = ((Entry<?, ?>) element).getValue();
            }
            cell.setText(element.toString());
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) ISelection(org.eclipse.jface.viewers.ISelection) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 85 with ISelection

use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.

the class InterpolationSettingPage method updateState.

/**
 * Update the page state.
 */
private void updateState() {
    boolean complete = true;
    // enable/disable move to grid setting
    ISelection sel = algorithms.getSelection();
    boolean isGridSelected = false;
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof InterpolationAlgorithmFactory) {
            if (GridInterpolation.EXTENSION_ID.equals(((InterpolationAlgorithmFactory) selected).getIdentifier())) {
                isGridSelected = true;
            }
        }
    }
    moveToGrid.setEnabled(isGridSelected);
    if (!sel.isEmpty() && !isGridSelected) {
        // disable setting when other algorithm than grid interpolation is
        // selected
        moveToGrid.setSelection(false);
    }
    // state of maximum positional error
    if (!validateMaxError()) {
        setErrorMessage("The maximum positional error must be a floating point number.");
        complete = false;
    } else {
        setErrorMessage(null);
    }
    setPageComplete(complete);
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)951 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)595 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)173 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)113 ArrayList (java.util.ArrayList)102 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)101 IResource (org.eclipse.core.resources.IResource)89 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)88 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)85 IFile (org.eclipse.core.resources.IFile)84 GridData (org.eclipse.swt.layout.GridData)80 Composite (org.eclipse.swt.widgets.Composite)67 PartInitException (org.eclipse.ui.PartInitException)66 ITextSelection (org.eclipse.jface.text.ITextSelection)65 IEditorPart (org.eclipse.ui.IEditorPart)65 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)65 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)58 SelectionEvent (org.eclipse.swt.events.SelectionEvent)57 GridLayout (org.eclipse.swt.layout.GridLayout)57 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)52