use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.
the class RemoveCellHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect cells from selection
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (MessageDialog.openQuestion(HandlerUtil.getActiveShell(event), "Delete cells", "Do you really want to delete the selected cells?")) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
if (selection instanceof IStructuredSelection) {
List<?> list = ((IStructuredSelection) selection).toList();
List<Cell> cells = new ArrayList<Cell>();
for (Object object : list) {
if (object instanceof Cell) {
// FIXME sanity checks for cell deletion? (e.g. don't
// allow remove type mapping if there are properties
// mapped?) where to do it?
// For now only done in activeWhen defined for handler
cells.add((Cell) object);
}
}
as.removeCells(cells.toArray(new Cell[cells.size()]));
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.
the class AddIndexContextHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
// TODO configure index
eds.addIndexContext((EntityDefinition) element, null);
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.
the class PurgeConditionContextHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
Condition condition = AlignmentUtil.getContextCondition(entityDef);
if (condition != null && condition.getFilter() != null) {
EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
eds.editConditionContext((EntityDefinition) element, null);
}
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.
the class InstanceViewPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
Composite page = new Composite(parent, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(1).applyTo(page);
GridDataFactory.fillDefaults().grab(true, true).applyTo(page);
// current sampler settings
samplerSettings.clear();
for (Entry<String, Sampler> entry : InstanceViewPreferences.SAMPLERS.entrySet()) {
Value settings = ps.getConfigurationService().getProperty(InstanceViewPreferences.KEY_SETTINGS_PREFIX + entry.getKey());
if (settings.isEmpty()) {
settings = entry.getValue().getDefaultSettings();
}
samplerSettings.put(entry.getKey(), settings);
}
// sampler group
samplerGroup = new Group(page, SWT.NONE);
samplerGroup.setText("Instance sampling");
GridDataFactory.fillDefaults().grab(true, false).applyTo(samplerGroup);
GridLayoutFactory.swtDefaults().applyTo(samplerGroup);
// enabled button
enabled = new Button(samplerGroup, SWT.CHECK);
enabled.setText("Use a sub-set of the imported source data as specified below:");
enabled.setSelection(ps.getConfigurationService().getBoolean(InstanceViewPreferences.KEY_ENABLED, InstanceViewPreferences.ENABLED_DEFAULT));
enabled.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changed = true;
}
});
// sampler selector
samplers = new ComboViewer(samplerGroup);
samplers.setContentProvider(ArrayContentProvider.getInstance());
samplers.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Sampler) {
return ((Sampler) element).getDisplayName(Value.NULL);
}
return super.getText(element);
}
});
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
samplers.setInput(InstanceViewPreferences.SAMPLERS.values());
samplers.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty()) {
updateEditor(null);
} else {
if (selection instanceof IStructuredSelection) {
updateEditor((Sampler) ((IStructuredSelection) selection).getFirstElement());
}
}
changed = true;
}
});
// restore the selected sampler
String samplerId = ps.getConfigurationService().get(InstanceViewPreferences.KEY_SAMPLER, InstanceViewPreferences.SAMPLER_FIRST);
Sampler selectedSampler = InstanceViewPreferences.SAMPLERS.get(samplerId);
if (selectedSampler != null) {
samplers.setSelection(new StructuredSelection(selectedSampler));
changed = false;
}
// occurring values group
Group ovGroup = new Group(page, SWT.NONE);
ovGroup.setText("Occurring values");
GridDataFactory.fillDefaults().grab(true, false).applyTo(ovGroup);
GridLayoutFactory.swtDefaults().applyTo(ovGroup);
// occurring values button
occurringValuesComplete = new Button(ovGroup, SWT.CHECK);
occurringValuesComplete.setText("Always use complete source data to determine occurring values (ignore sampling)");
occurringValuesComplete.setSelection(ps.getConfigurationService().getBoolean(InstanceViewPreferences.KEY_OCCURRING_VALUES_USE_EXTERNAL, InstanceViewPreferences.OCCURRING_VALUES_EXTERNAL_DEFAULT));
occurringValuesComplete.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ov_changed = true;
}
});
return page;
}
use of org.eclipse.jface.viewers.ISelection in project hale by halestudio.
the class EditRelationHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof Cell) {
final Cell originalCell = (Cell) selected;
FunctionWizard wizard = null;
List<FunctionWizardDescriptor<?>> factories = FunctionWizardExtension.getInstance().getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {
@Override
public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
return factory.getFunctionId().equals(originalCell.getTransformationIdentifier());
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
return true;
}
});
if (!factories.isEmpty()) {
// create registered wizard
FunctionWizardDescriptor<?> fwd = factories.get(0);
wizard = fwd.createEditWizard(originalCell);
}
if (wizard == null) {
FunctionDefinition<?> function = FunctionUtil.getFunction(originalCell.getTransformationIdentifier(), HaleUI.getServiceProvider());
if (function == null) {
log.userError(MessageFormat.format("Function with identifier ''{0}'' is unknown.", originalCell.getTransformationIdentifier()));
return null;
}
// create generic wizard
if (function instanceof TypeFunction) {
wizard = new GenericTypeFunctionWizard(originalCell);
} else {
wizard = new GenericPropertyFunctionWizard(originalCell);
}
}
// initialize wizard
wizard.init();
HaleWizardDialog dialog = new HaleWizardDialog(HandlerUtil.getActiveShell(event), wizard);
if (dialog.open() == WizardDialog.OK) {
MutableCell cell = wizard.getResult();
AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
// remove the original cell
// and add the new cell
alignmentService.replaceCell(originalCell, cell);
}
}
}
return null;
}
Aggregations