Search in sources :

Example 66 with ISelectionChangedListener

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

the class AbstractSelectionProvider method fireSelectionChange.

/**
 * Fires a selection change and sets the last selection to the given
 * selection.
 *
 * @param newSelection the new selection
 */
protected void fireSelectionChange(ISelection newSelection) {
    this.lastSelection = newSelection;
    SelectionChangedEvent event = new SelectionChangedEvent(this, newSelection);
    for (ISelectionChangedListener listener : listeners) {
        listener.selectionChanged(event);
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 67 with ISelectionChangedListener

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

the class ViewerWizardSelectionPage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    Font font = parent.getFont();
    // create composite for page.
    Composite outerContainer = new Composite(parent, SWT.NONE);
    outerContainer.setLayout(new GridLayout());
    outerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    outerContainer.setFont(font);
    Pair<StructuredViewer, Control> viewerControl = createViewer(outerContainer);
    viewer = viewerControl.getFirst();
    viewerControl.getSecond().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, getViewerHeightHint()).create());
    // wire viewer
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            viewerSelectionChanged(event.getSelection());
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            doubleClicked(event);
        }
    });
    Dialog.applyDialogFont(outerContainer);
    // apply the initial selection
    viewerSelectionChanged(viewer.getSelection());
    setControl(outerContainer);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Font(org.eclipse.swt.graphics.Font)

Example 68 with ISelectionChangedListener

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

the class AlignmentView method createViewControl.

/**
 * @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#createViewControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createViewControl(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(GridLayoutFactory.fillDefaults().create());
    // create type relation selection control
    sourceTargetSelector = new SourceTargetTypeSelector(page);
    sourceTargetSelector.getControl().setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
    sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            getViewer().setInput(sourceTargetSelector.getSelectedCell());
            if (deactivatedCellFilterAction != null) {
                deactivatedCellFilterAction.setEnabled(sourceTargetSelector.isCellSelected());
                if (!sourceTargetSelector.isCellSelected())
                    deactivatedCellFilterAction.setChecked(true);
            }
            refreshGraph();
        }
    });
    // typeRelations = new ComboViewer(page, SWT.DROP_DOWN | SWT.READ_ONLY);
    // typeRelations.setContentProvider(ArrayContentProvider.getInstance());
    // typeRelations.setLabelProvider(new LabelProvider() {
    // 
    // @Override
    // public Image getImage(Object element) {
    // if (element instanceof Cell) {
    // // use function image if possible
    // Cell cell = (Cell) element;
    // String functionId = cell.getTransformationIdentifier();
    // AbstractFunction<?> function = FunctionUtil.getFunction(functionId);
    // if (function != null) {
    // return functionLabels.getImage(function);
    // }
    // return null;
    // }
    // 
    // return super.getImage(element);
    // }
    // 
    // @Override
    // public String getText(Object element) {
    // if (element instanceof Cell) {
    // Cell cell = (Cell) element;
    // 
    // return CellUtil.getCellDescription(cell);
    // }
    // 
    // return super.getText(element);
    // }
    // 
    // });
    // typeRelations.addSelectionChangedListener(new ISelectionChangedListener() {
    // 
    // @Override
    // public void selectionChanged(SelectionChangedEvent event) {
    // updateGraph();
    // }
    // });
    // typeRelations.getControl().setLayoutData(
    // GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
    // .create());
    // create viewer
    Composite viewerContainer = new Composite(page, SWT.NONE);
    viewerContainer.setLayout(new FillLayout());
    viewerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    super.createViewControl(viewerContainer);
    updateLayout(false);
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    // update();
    as.addListener(alignmentListener = new AlignmentServiceAdapter() {

        @Override
        public void alignmentCleared() {
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
                }
            });
        }

        @Override
        public void cellsRemoved(Iterable<Cell> cells) {
            if (sourceTargetSelector.isCellSelected() && Iterables.contains(cells, sourceTargetSelector.getSelectedCell()))
                sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
            refreshGraph();
        }

        @Override
        public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
            if (sourceTargetSelector.isCellSelected() && cells.keySet().contains(sourceTargetSelector.getSelectedCell()))
                sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
            refreshGraph();
        }

        @Override
        public void cellsAdded(Iterable<Cell> cells) {
            refreshGraph();
        }

        @Override
        public void alignmentChanged() {
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
                }
            });
        }

        @Override
        public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
            refreshGraph();
        }

        @Override
        public void customFunctionsChanged() {
            refreshGraph();
        }
    });
    TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
    taskService.addListener(tasksListener = new TaskServiceListener() {

        @Override
        public void tasksRemoved(Iterable<Task<?>> tasks) {
            refreshGraph();
        }

        @Override
        public void tasksAdded(Iterable<Task<?>> tasks) {
            refreshGraph();
        }

        @Override
        public void taskUserDataChanged(ResolvedTask<?> task) {
            refreshGraph();
        }
    });
    // initialize compatibility checkup and display
    CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
    cs.addListener(compListener = new ExclusiveExtensionListener<CompatibilityMode, CompatibilityModeFactory>() {

        @Override
        public void currentObjectChanged(final CompatibilityMode arg0, final CompatibilityModeFactory arg1) {
            refreshGraph();
        }
    });
    // listen on SchemaSelections
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!(selection instanceof SchemaSelection)) {
                // only react on schema selections
                return;
            }
            if (part != AlignmentView.this) {
                updateRelation((SchemaSelection) selection);
            }
        }
    });
    // select type cell, if it is double clicked
    getViewer().addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() == 1) {
                Object selected = selection.getFirstElement();
                if (selected instanceof Cell && AlignmentUtil.isTypeCell((Cell) selected))
                    sourceTargetSelector.setSelection(selection);
            }
        }
    });
    // listen on size changes
    getViewer().getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            updateLayout(true);
        }
    });
    getViewer().setInput(new DefaultCell());
}
Also used : CompatibilityModeFactory(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityModeFactory) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SourceTargetTypeSelector(eu.esdihumboldt.hale.ui.function.common.SourceTargetTypeSelector) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) CompatibilityService(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Composite(org.eclipse.swt.widgets.Composite) CompatibilityMode(eu.esdihumboldt.hale.common.align.compatibility.CompatibilityMode) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ExclusiveExtensionListener(de.fhg.igd.eclipse.util.extension.exclusive.ExclusiveExtension.ExclusiveExtensionListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) ControlEvent(org.eclipse.swt.events.ControlEvent) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map)

Example 69 with ISelectionChangedListener

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

the class URLTarget method createControls.

/**
 * @see eu.esdihumboldt.hale.ui.io.ExportTarget#createControls(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(3, false));
    // source file
    targetURL = new URLTargetURIFieldEditor("targetURL", "Target URL", parent) {

        @Override
        protected void onHistorySelected(URI location) {
            updateState();
        }
    };
    targetURL.setPage(getPage());
    targetURL.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState();
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState();
            }
        }
    });
    // content type selection
    // label
    Label typesLabel = new Label(parent, SWT.NONE);
    typesLabel.setText("Content type");
    // types combo
    Composite group = new Composite(parent, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    group.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
    types = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    types.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    types.setContentProvider(ArrayContentProvider.getInstance());
    types.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IContentType) {
                return ((IContentType) element).getName();
            }
            return super.getText(element);
        }
    });
    // process selection changes
    types.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // update content type
            ISelection sel = event.getSelection();
            if (sel.isEmpty() || !(sel instanceof IStructuredSelection)) {
                setContentType(null);
            } else {
                setContentType((IContentType) ((IStructuredSelection) sel).getFirstElement());
            }
        }
    });
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) IContentType(org.eclipse.core.runtime.content.IContentType) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(java.net.URI) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 70 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener 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)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)774 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)755 GridData (org.eclipse.swt.layout.GridData)419 Composite (org.eclipse.swt.widgets.Composite)333 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)302 GridLayout (org.eclipse.swt.layout.GridLayout)247 SelectionEvent (org.eclipse.swt.events.SelectionEvent)187 Label (org.eclipse.swt.widgets.Label)157 TableViewer (org.eclipse.jface.viewers.TableViewer)151 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)147 Button (org.eclipse.swt.widgets.Button)141 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)139 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)131 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)121 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)120 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)116 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)116 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)116 Table (org.eclipse.swt.widgets.Table)93 ISelection (org.eclipse.jface.viewers.ISelection)87