Search in sources :

Example 81 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project hale by halestudio.

the class TypeCellSelectionDialog method setupViewer.

/**
 * @see eu.esdihumboldt.hale.ui.util.selector.AbstractViewerSelectionDialog#setupViewer(org.eclipse.jface.viewers.StructuredViewer,
 *      java.lang.Object)
 */
@Override
protected void setupViewer(final GraphViewer viewer, Cell initialSelection) {
    // content and label provider
    viewer.setContentProvider(new ReverseCellGraphContentProvider());
    viewer.setLabelProvider(new GraphLabelProvider(viewer, HaleUI.getServiceProvider()));
    // layout
    final TreeLayoutAlgorithm layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
    viewer.getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            int width = viewer.getControl().getSize().x;
            layout.setNodeSpace(new Dimension((width - 10) / 3, 30));
        }
    });
    viewer.setLayoutAlgorithm(layout, true);
    viewer.applyLayout();
    // input and selection
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    viewer.setInput(as.getAlignment().getTypeCells());
    if (initialSelection != null)
        viewer.setSelection(new StructuredSelection(initialSelection));
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) ReverseCellGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.ReverseCellGraphContentProvider) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Dimension(org.eclipse.draw2d.geometry.Dimension) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 82 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project hale by halestudio.

the class GenericParameterPage method createField.

/**
 * Creates a text field for the given function parameter and given initial
 * value. Does not call updateState!
 *
 * @param parent the composite in which to place the text field
 * @param fp the function parameter
 * @param initialValue initial value or <code>null</code>
 * @param fixed whether the field may never be removed under any
 *            circumstances (-> no remove button)
 * @return the created text field
 */
private Pair<AttributeEditor<?>, Button> createField(Composite parent, final FunctionParameterDefinition fp, ParameterValue initialValue, boolean fixed) {
    // create editor, button and pair
    final AttributeEditor<?> editor = ParameterEditorExtension.getInstance().createEditor(parent, getWizard().getFunctionId(), fp, initialValue);
    // listen to valid changes
    editor.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (AttributeEditor.IS_VALID.equals(event.getProperty()))
                updateState();
        }
    });
    // listen for resizes of the editor
    // needed for the editor chooser editor
    editor.getControl().addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            /*
				 * call layoutAndPack() later as a call now breaks the wizard
				 * dialog sizing (at least on Linux) and makes the button bar
				 * disappear.
				 */
            Display.getCurrent().asyncExec(new Runnable() {

                @Override
                public void run() {
                    layoutAndPack();
                }
            });
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // ignore
        }
    });
    final Pair<AttributeEditor<?>, Button> pair;
    final Button removeButton;
    if (fixed)
        removeButton = null;
    else
        removeButton = new Button(parent, SWT.NONE);
    pair = new Pair<AttributeEditor<?>, Button>(editor, removeButton);
    // configure text
    editor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    // configure button
    if (removeButton != null) {
        removeButton.setImage(removeImage);
        removeButton.setEnabled(false);
        removeButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // remove last text field
                List<Pair<AttributeEditor<?>, Button>> texts = inputFields.get(fp);
                texts.remove(pair);
                updateState();
                removeButton.dispose();
                editor.getControl().dispose();
                addButtons.get(fp).setEnabled(true);
                if (texts.size() == fp.getMinOccurrence())
                    for (Pair<AttributeEditor<?>, Button> otherPair : texts) otherPair.getSecond().setEnabled(false);
                layoutAndPack();
            }
        });
    }
    // add field to map
    inputFields.put(fp, pair);
    return pair;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) List(java.util.List) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 83 with ControlEvent

use of org.eclipse.swt.events.ControlEvent 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 84 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project hale by halestudio.

the class MappingView method createViewControl.

@Override
public void createViewControl(Composite parent) {
    super.createViewControl(parent);
    updateLayout(false);
    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 != MappingView.this) {
                update((SchemaSelection) selection);
            }
        }
    });
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    // update();
    as.addListener(alignmentListener = new AlignmentServiceAdapter() {

        @Override
        public void cellsRemoved(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
            List<Cell> changedCells = new ArrayList<Cell>(2);
            changedCells.addAll(cells.keySet());
            changedCells.addAll(cells.values());
            updateViewWithCurrentSelection(changedCells);
        }

        @Override
        public void customFunctionsChanged() {
            SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
            if (current != null) {
                update(current);
            }
        }

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

        @Override
        public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
            updateViewWithCurrentSelection(cells);
        }
    });
    TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
    taskService.addListener(new TaskServiceListener() {

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

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

        @Override
        public void taskUserDataChanged(ResolvedTask<?> task) {
            updateViewWithCurrentSelection(getAffectedCells(Collections.singleton(task)));
        }

        private List<Cell> getAffectedCells(Iterable<Task<?>> tasks) {
            List<Cell> affectedCells = new ArrayList<>();
            tasks.forEach(t -> {
                if (t.getMainContext() instanceof Cell) {
                    affectedCells.add((Cell) t.getMainContext());
                }
            });
            return affectedCells;
        }
    });
    SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
    if (current != null) {
        update(current);
    }
    // listen on size changes
    getViewer().getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            updateLayout(true);
        }
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Dimension(org.eclipse.draw2d.geometry.Dimension) ListMultimap(com.google.common.collect.ListMultimap) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) HaleUI(eu.esdihumboldt.hale.ui.HaleUI) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) IToolBarManager(org.eclipse.jface.action.IToolBarManager) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) MappingViewPlugin(eu.esdihumboldt.hale.ui.views.mapping.internal.MappingViewPlugin) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) HashSet(java.util.HashSet) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Type(eu.esdihumboldt.hale.common.align.model.Type) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) Pair(eu.esdihumboldt.util.Pair) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) WorkbenchPart(org.eclipse.ui.part.WorkbenchPart) PlatformUI(org.eclipse.ui.PlatformUI) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) Collection(java.util.Collection) Set(java.util.Set) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) Action(org.eclipse.jface.action.Action) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) List(java.util.List) AlignmentServiceListener(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ISelection(org.eclipse.jface.viewers.ISelection) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Task(eu.esdihumboldt.hale.common.tasks.Task) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) SchemaSelectionHelper(eu.esdihumboldt.hale.ui.selection.SchemaSelectionHelper) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) Task(eu.esdihumboldt.hale.common.tasks.Task) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) ArrayList(java.util.ArrayList) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) ControlEvent(org.eclipse.swt.events.ControlEvent) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 85 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project yamcs-studio by yamcs.

the class ContentProposalPopup method createDialogArea.

/*
     * Creates the content area for the proposal popup. This creates a table and places it inside the composite. The
     * table will contain a list of all the proposals.
     *
     * @param parent The parent composite to contain the dialog area; must not be <code>null</code>.
     */
@Override
protected final Control createDialogArea(Composite parent) {
    var wrapper = (Composite) super.createDialogArea(parent);
    wrapper.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    wrapper.setLayout(new GridLayout());
    // Use virtual where appropriate (see flag definition).
    if (USE_VIRTUAL) {
        proposalTable = new Table(wrapper, SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL | SWT.NO_FOCUS);
        proposalTable.addListener(SWT.SetData, this::handleSetData);
        proposalTable.addListener(SWTPaintItem, event -> {
            var item = (TableItem) event.item;
            var index = proposalTable.indexOf(item);
            if (textLayouts != null && index < textLayouts.length && textLayouts[index] != null) {
                textLayouts[index].handlePaintItemEvent(event, 20, 2);
            }
            var p = (Proposal) item.getData();
            var image = getImage(p, index == proposalTable.getSelectionIndex());
            if (image != null) {
                event.gc.drawImage(image, event.x, event.y + 2);
            }
        });
        proposalTable.addListener(SWTMeasureItem, event -> {
            var item = (TableItem) event.item;
            var index = proposalTable.indexOf(item);
            if (textLayouts != null && index < textLayouts.length && textLayouts[index] != null) {
                textLayouts[index].handleMeasureItemEvent(event);
            }
        });
    } else {
        proposalTable = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS);
    }
    footer = new Text(wrapper, SWT.READ_ONLY | SWT.WRAP | SWT.NO_FOCUS);
    var textGridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    textGridData.heightHint = FOOTER_MINIMUM_HEIGHT;
    textGridData.widthHint = 100;
    footer.setLayoutData(textGridData);
    // set the proposals to force population of the table.
    setProposals(proposalList);
    proposalTable.setHeaderVisible(false);
    proposalTable.addListener(SWT.KeyDown, e -> getTargetControlListener().handleEvent(e));
    proposalTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // popup. Otherwise close the popup.
            if (e.item == null) {
                if (infoPopup != null) {
                    infoPopup.close();
                }
            } else {
                var proposal = (Proposal) e.item.getData();
                if (proposal != null) {
                    showProposalDescription();
                    adapter.proposalSelected(proposal);
                } else {
                    if (infoPopup != null) {
                        infoPopup.close();
                    }
                    proposalTable.deselectAll();
                }
            }
        }

        // Default selection was made. Accept the current proposal.
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            var proposal = (Proposal) e.item.getData();
            if (proposal != null) {
                acceptCurrentProposal(true);
            } else {
                proposalTable.deselectAll();
            }
        }
    });
    // Added to solve a item resize bug on windows:
    new TableColumn(proposalTable, SWT.NONE | SWT.NO_FOCUS);
    proposalTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent event) {
            if (proposalTable.getColumnCount() > 0) {
                if (proposalTable.getClientArea().width > maxItemWidth) {
                    proposalTable.getColumn(0).setWidth(proposalTable.getClientArea().width);
                } else {
                    proposalTable.getColumn(0).setWidth(maxItemWidth);
                }
            }
        }
    });
    return proposalTable;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)187 ControlAdapter (org.eclipse.swt.events.ControlAdapter)135 Composite (org.eclipse.swt.widgets.Composite)76 GridData (org.eclipse.swt.layout.GridData)67 ControlListener (org.eclipse.swt.events.ControlListener)54 GridLayout (org.eclipse.swt.layout.GridLayout)50 SelectionEvent (org.eclipse.swt.events.SelectionEvent)49 TableColumn (org.eclipse.swt.widgets.TableColumn)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)41 Point (org.eclipse.swt.graphics.Point)38 Table (org.eclipse.swt.widgets.Table)37 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)36 FillLayout (org.eclipse.swt.layout.FillLayout)35 Tree (org.eclipse.swt.widgets.Tree)35 TreeViewer (org.eclipse.jface.viewers.TreeViewer)33 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)31 AdapterFactoryTreeEditor (org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor)30 AdapterFactoryContentProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider)30 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)30