Search in sources :

Example 96 with ISelection

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;
}
Also used : AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 97 with ISelection

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;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 98 with ISelection

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;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 99 with ISelection

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Sampler(eu.esdihumboldt.hale.ui.service.instance.sample.Sampler) Value(eu.esdihumboldt.hale.common.core.io.Value) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 100 with ISelection

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;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor) FunctionWizardFactory(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardFactory) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) TypeFunction(eu.esdihumboldt.hale.common.align.extension.function.TypeFunction) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

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