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