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);
}
}
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;
}
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;
}
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);
}
}
}
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);
}
};
}
Aggregations