Search in sources :

Example 86 with ISelection

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

the class SpatialJoinParameterPage 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 87 with ISelection

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

the class SetDefaultGeometryHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    /*
		 * Set the defaut geometry to the first valid child entity definition
		 * from the selection (for the type the entity definition is associated
		 * to)
		 */
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toList()) {
            if (element instanceof EntityDefinition) {
                EntityDefinition def = (EntityDefinition) element;
                if (!def.getPropertyPath().isEmpty()) {
                    // path must not be empty
                    // XXX is this true? we could set the default geometry
                    // to the type to use all geometries
                    List<QName> path = new ArrayList<QName>(def.getPropertyPath().size());
                    for (ChildContext child : def.getPropertyPath()) {
                        path.add(child.getChild().getName());
                    }
                    GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
                    gss.setDefaultGeometry(def.getType(), path);
                }
            }
        }
    }
    // otherwise does nothing
    return null;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) QName(javax.xml.namespace.QName) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)

Example 88 with ISelection

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

the class RootElementPage method updateConfiguration.

/**
 * @see IOWizardPage#updateConfiguration(IOProvider)
 */
@Override
public boolean updateConfiguration(XmlWriterBase provider) {
    ISelection sel = list.getSelection();
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof XmlElement) {
            QName name = ((XmlElement) selected).getName();
            provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(name.getNamespaceURI()));
            provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME, Value.of(name.getLocalPart()));
            return true;
        }
    }
    provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE, null);
    provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME, null);
    return false;
}
Also used : QName(javax.xml.namespace.QName) ISelection(org.eclipse.jface.viewers.ISelection) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 89 with ISelection

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

the class AbstractViewerSelectionDialog method updateState.

private void updateState() {
    Button ok = getButton(IDialogConstants.OK_ID);
    if (ok != null) {
        ISelection selection = viewer.getSelection();
        if (selection.isEmpty())
            ok.setEnabled(false);
        else {
            boolean valid = true;
            if (selection instanceof IStructuredSelection) {
                if (!acceptObject(viewer, filters, ((IStructuredSelection) selection).getFirstElement()))
                    valid = false;
            }
            ok.setEnabled(valid);
        }
    }
}
Also used : Button(org.eclipse.swt.widgets.Button) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 90 with ISelection

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

the class AbstractMappingView method createViewControl.

@Override
public void createViewControl(Composite parent) {
    viewer = new GraphViewer(parent, SWT.BORDER);
    viewer.setContentProvider(createContentProvider());
    // viewer.setContentProvider(new CellRelationshipContentProvider());
    // viewer.setContentProvider(new NestedCellRelationshipContentProvider());
    viewer.setLabelProvider(createLabelProvider(viewer));
    viewer.setInput(null);
    LayoutAlgorithm layout = createLayout();
    viewer.setLayoutAlgorithm(layout, true);
    viewer.applyLayout();
    fillToolBar();
    // set selection provider
    selectionFacade = new SelectionProviderFacade();
    selectionFacade.setSelectionProvider(getViewer());
    getSite().setSelectionProvider(new PostSelectionSupport(selectionFacade));
    viewer.getControl().addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == 'a' && (e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
                // XXX even though getSelection returns the current state, a
                // selection update is not triggered by the control
                // -> force selection change event after Ctrl+A
                ISelection sel = viewer.getSelection();
                selectionFacade.setSelection(sel);
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        // nothing to do
        }
    });
    // create context menu
    new ViewerMenu(getSite(), getViewer()) {

        /**
         * @see eu.esdihumboldt.hale.ui.util.ViewContextMenu#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
         */
        @Override
        public void menuAboutToShow(IMenuManager manager) {
            super.menuAboutToShow(manager);
            AbstractMappingView.this.menuAboutToShow(manager);
        }
    };
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) SelectionProviderFacade(eu.esdihumboldt.hale.ui.util.selection.SelectionProviderFacade) ISelection(org.eclipse.jface.viewers.ISelection) KeyListener(org.eclipse.swt.events.KeyListener) IMenuManager(org.eclipse.jface.action.IMenuManager) PostSelectionSupport(eu.esdihumboldt.hale.ui.util.viewer.PostSelectionSupport) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu)

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