Search in sources :

Example 46 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project hale by halestudio.

the class ClassificationMappingParameterPage method createManualTabControl.

private Control createManualTabControl(Composite tabParent) {
    // TODO load occurring value sources
    Composite tabContent = new Composite(tabParent, SWT.NONE);
    tabContent.setLayout(new GridLayout(1, true));
    ToolBar toolBar = new ToolBar(tabContent, SWT.NONE);
    toolBar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    Composite tableContainer = new Composite(tabContent, SWT.NONE);
    tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    TableViewerColumn sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    sourceColumn.getColumn().setText("Source value");
    layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
    sourceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
            return entry.getKey().getStringRepresentation();
        }
    });
    TableViewerColumn targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    targetColumn.getColumn().setText("Target value");
    layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
    targetColumn.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
            if (entry.getValue() == null) {
                StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
                cell.setText(styledString.getString());
                cell.setStyleRanges(styledString.getStyleRanges());
            } else {
                cell.setText(entry.getValue().getStringRepresentation());
                cell.setStyleRanges(null);
            }
            super.update(cell);
        }
    });
    tableViewer.setInput(lookupTable.entrySet());
    tableViewer.getTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            ViewerCell cell = tableViewer.getCell(new Point(e.x, e.y));
            if (cell != null) {
                @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
                Value oldValue;
                Value newValue;
                if (cell.getColumnIndex() == 0) {
                    oldValue = entry.getKey();
                    newValue = selectValue(sourceProperty, sourceEntity, "Edit source value", "Enter a new source value", oldValue.getStringRepresentation());
                } else {
                    oldValue = entry.getValue();
                    String initialValue = oldValue == null ? null : oldValue.getStringRepresentation();
                    newValue = selectValue(targetProperty, targetEntity, "Edit target value", "Enter a target value", initialValue);
                }
                if (newValue == null)
                    return;
                if (cell.getColumnIndex() == 0) {
                    if (!newValue.equals(oldValue) && lookupTable.containsKey(newValue)) {
                        showDuplicateSourceWarning(newValue.getStringRepresentation());
                    } else {
                        lookupTable.put(newValue, entry.getValue());
                        lookupTable.remove(oldValue);
                        tableViewer.refresh();
                    }
                } else {
                    entry.setValue(newValue);
                    tableViewer.update(entry, null);
                }
            }
        }
    });
    final ToolItem valueAdd = new ToolItem(toolBar, SWT.PUSH);
    final ToolItem fillValues = new ToolItem(toolBar, SWT.PUSH);
    new ToolItem(toolBar, SWT.SEPARATOR);
    final ToolItem loadButton = new ToolItem(toolBar, SWT.PUSH);
    saveButton = new ToolItem(toolBar, SWT.PUSH);
    new ToolItem(toolBar, SWT.SEPARATOR);
    final ToolItem valueRemove = new ToolItem(toolBar, SWT.PUSH);
    removeAllButton = new ToolItem(toolBar, SWT.PUSH);
    valueAdd.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_ADD));
    valueAdd.setToolTipText("Add source value");
    valueAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Value newSource = selectValue(sourceProperty, sourceEntity, "Add source value", "Enter a new source value", null);
            if (newSource != null) {
                if (lookupTable.containsKey(newSource))
                    showDuplicateSourceWarning(newSource.getStringRepresentation());
                else {
                    lookupTable.put(newSource, null);
                    removeAllButton.setEnabled(true);
                    saveButton.setEnabled(true);
                    tableViewer.refresh();
                }
            }
        }
    });
    loadButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_OPEN));
    loadButton.setToolTipText("Load classification from file");
    loadButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            LookupTableLoadWizard wizard = new LookupTableLoadWizard();
            LookupLoadAdvisor advisor = new LookupLoadAdvisor();
            wizard.setAdvisor(advisor, null);
            Shell shell = Display.getCurrent().getActiveShell();
            HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
            dialog.open();
            if (advisor.getLookupTable() != null) {
                lookupTable.putAll(advisor.getLookupTable().getTable().asMap());
                tableViewer.refresh();
                removeAllButton.setEnabled(!lookupTable.isEmpty());
                saveButton.setEnabled(!lookupTable.isEmpty());
            }
        }
    });
    fillValues.setImage(fillValuesIcon);
    fillValues.setToolTipText("Attempt to fill source values with enumerations and occurring values.");
    fillValues.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // first try enumeration
            Enumeration<?> enumeration = sourceProperty.getPropertyType().getConstraint(Enumeration.class);
            if (enumeration.getValues() != null) {
                addSourceValuesIfNew(enumeration.getValues());
            }
            // then try occurring values
            if (!ovs.updateOccurringValues(sourceEntity)) {
                // values already there or not possible
                addOccurringSourceValues(ovs.getOccurringValues(sourceEntity));
            } else {
            // job is running, listener will be notified
            }
            removeAllButton.setEnabled(!lookupTable.isEmpty());
            saveButton.setEnabled(!lookupTable.isEmpty());
        }
    });
    saveButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SAVE));
    saveButton.setToolTipText("Save classification to file");
    saveButton.setEnabled(false);
    saveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            LookupTableExportWizard wizard = new LookupTableExportWizard();
            LookupExportAdvisor advisor = new LookupExportAdvisor(new LookupTableInfoImpl(new LookupTableImpl(lookupTable), "current", "not set"));
            wizard.setAdvisor(advisor, null);
            Shell shell = Display.getCurrent().getActiveShell();
            HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
            dialog.open();
        }
    });
    valueRemove.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REMOVE));
    valueRemove.setToolTipText("Remove classification entry");
    valueRemove.setEnabled(false);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            valueRemove.setEnabled(!event.getSelection().isEmpty());
            saveButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    valueRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (tableViewer.getSelection().isEmpty())
                return;
            Object element = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
            lookupTable.remove(entry.getKey());
            tableViewer.refresh();
            removeAllButton.setEnabled(!lookupTable.isEmpty());
            saveButton.setEnabled(!lookupTable.isEmpty());
        }
    });
    removeAllButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TRASH));
    removeAllButton.setEnabled(false);
    removeAllButton.setToolTipText("Remove complete classification");
    removeAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            lookupTable.clear();
            tableViewer.refresh();
            removeAllButton.setEnabled(false);
            saveButton.setEnabled(false);
        }
    });
    Label desc = new Label(tabContent, SWT.NONE);
    desc.setText("Double click on a table cell to change its value.");
    return tabContent;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) LookupLoadAdvisor(eu.esdihumboldt.hale.common.lookup.internal.LookupLoadAdvisor) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) Shell(org.eclipse.swt.widgets.Shell) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) LookupTableLoadWizard(eu.esdihumboldt.hale.ui.lookup.LookupTableLoadWizard) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ToolItem(org.eclipse.swt.widgets.ToolItem) LookupTableExportWizard(eu.esdihumboldt.hale.io.csv.ui.LookupTableExportWizard) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) MouseEvent(org.eclipse.swt.events.MouseEvent) Enumeration(eu.esdihumboldt.hale.common.schema.model.constraint.type.Enumeration) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) LookupTableInfoImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableInfoImpl) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) TableViewer(org.eclipse.jface.viewers.TableViewer) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) LookupExportAdvisor(eu.esdihumboldt.hale.common.lookup.internal.LookupExportAdvisor) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Example 47 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project tbd-studio-se by Talend.

the class HadoopContextConfConfigDialog method createTable.

private Composite createTable(Composite parent) {
    Composite tableComposite = new Composite(parent, SWT.NONE);
    tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);
    viewer = new TableViewer(tableComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ViewerContentProvider());
    table = viewer.getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableViewerColumn contextColumn = createTableViewerColumn(Messages.getString("HadoopContextConfConfigDialog.table.contextColumn"), // $NON-NLS-1$
    0);
    contextColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Map.Entry<String, String> entry = (Map.Entry<String, String>) element;
            return entry.getKey();
        }
    });
    tableColumnLayout.setColumnData(contextColumn.getColumn(), new ColumnWeightData(35, 80, true));
    TableViewerColumn jarNameColumn = createTableViewerColumn(Messages.getString("HadoopContextConfConfigDialog.table.jarNameColumn"), // $NON-NLS-1$
    1);
    jarNameColumn.setEditingSupport(new JarNameEditingSupport(viewer));
    jarNameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Map.Entry<String, String> entry = (Map.Entry<String, String>) element;
            return entry.getValue();
        }
    });
    tableColumnLayout.setColumnData(jarNameColumn.getColumn(), new ColumnWeightData(65, 120, true));
    viewer.setInput(context2Jar);
    return tableComposite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) HashMap(java.util.HashMap) Map(java.util.Map) EMap(org.eclipse.emf.common.util.EMap) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 48 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class CommandStackView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level0s.png"));
    level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
    level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
    level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
    level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
    level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
    var gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.verticalSpacing = 1;
    parent.setLayout(gl);
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    errorBackgroundColor = resourceManager.createColor(new RGB(255, 221, 221));
    bracketStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
        }
    };
    argNameStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
        }
    };
    numberStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
        }
    };
    errorStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
            textStyle.underline = true;
            textStyle.underlineColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
            textStyle.underlineStyle = SWT.UNDERLINE_ERROR;
        }
    };
    issuedStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
        }
    };
    skippedStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
            textStyle.strikeout = true;
            textStyle.strikeoutColor = textStyle.foreground;
        }
    };
    var tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    commandTableViewer = new CommandStackTableViewer(tableWrapper, tcl, this);
    commandTableViewer.addDoubleClickListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            var cmd = (StackedCommand) sel.getFirstElement();
            if (cmd.getStackedState() != StackedState.ISSUED && cmd.getStackedState() != StackedState.SKIPPED) {
                var dialog = new EditStackedCommandDialog(parent.getShell(), cmd);
                if (dialog.open() == Window.OK) {
                    refreshState();
                }
            }
        }
    });
    var controls = new Composite(parent, SWT.NONE);
    var gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 30;
    controls.setLayoutData(gd);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    controls.setLayout(gl);
    controls.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    bottomLeft = new Composite(controls, SWT.NONE);
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.CENTER;
    bottomLeft.setLayoutData(gd);
    gl = new GridLayout(4, false);
    gl.marginWidth = 0;
    gl.marginHeight = 0;
    bottomLeft.setLayout(gl);
    clearanceLabel = new Label(bottomLeft, SWT.NONE);
    clearanceLabel.setVisible(false);
    clearanceImageLabel = new Label(bottomLeft, SWT.NONE);
    clearanceImageLabel.setVisible(false);
    clearanceSeparator = new Label(bottomLeft, SWT.SEPARATOR);
    gd = new GridData();
    gd.heightHint = 15;
    clearanceSeparator.setLayoutData(gd);
    clearanceSeparator.setVisible(false);
    messageLabel = new Label(bottomLeft, SWT.NONE);
    messageLabel.setText("");
    messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    var bottomRight = new Composite(controls, SWT.NONE);
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.CENTER;
    gd.horizontalAlignment = SWT.RIGHT;
    bottomRight.setLayoutData(gd);
    gl = new GridLayout(4, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    bottomRight.setLayout(gl);
    // Stack parameters (manual/auto stack)
    var stackParameters = new Composite(bottomRight, SWT.NONE);
    gl = new GridLayout(5, false);
    gl.marginHeight = 0;
    gl.marginWidth = 50;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    stackParameters.setLayout(gl);
    // Group stackTypeGroup = new Group(stackParameters, SWT.NONE);
    // stackTypeGroup.setLayout(new RowLayout(SWT.HORIZONTAL));
    stackModeLabel = new Label(stackParameters, SWT.NONE);
    stackModeLabel.setText("Stack mode: ");
    advanceModeCombo = new Combo(stackParameters, SWT.DROP_DOWN | SWT.READ_ONLY);
    var items = new String[] { "Manual", "Automatic" };
    advanceModeCombo.setItems(items);
    advanceModeCombo.select(0);
    autoOptionsCombo = new Combo(stackParameters, SWT.DROP_DOWN | SWT.READ_ONLY);
    var items2 = new String[] { "AFAP (no delay)", "Fixed Delay", "Stack Delay" };
    autoOptionsCombo.setItems(items2);
    autoOptionsCombo.select(0);
    autoOptionsCombo.setVisible(false);
    fixDelaySpinner = new Spinner(stackParameters, SWT.BORDER);
    fixDelaySpinner.setMinimum(0);
    fixDelaySpinner.setMaximum(Integer.MAX_VALUE);
    fixDelaySpinner.setSelection(200);
    fixDelaySpinner.setIncrement(1);
    fixDelaySpinner.setPageIncrement(100);
    fixDelaySpinner.setVisible(false);
    fixDelaySpinner.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        stack.fixDelayMs = fixDelaySpinner.getSelection();
    });
    var labelUnit = new Label(stackParameters, SWT.NONE);
    labelUnit.setText("ms");
    labelUnit.setVisible(false);
    advanceModeCombo.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        var index = advanceModeCombo.getSelectionIndex();
        if (index == StackMode.MANUAL.index()) {
            // Manual
            stack.stackMode = StackMode.MANUAL;
            autoOptionsCombo.setVisible(false);
            fixDelaySpinner.setVisible(false);
            labelUnit.setVisible(false);
            commandTableViewer.hideDelayColumn();
        } else {
            // Automatic
            stack.stackMode = StackMode.AUTOMATIC;
            autoOptionsCombo.setVisible(true);
            if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
                // fix delay
                fixDelaySpinner.setVisible(true);
                labelUnit.setVisible(true);
                commandTableViewer.hideDelayColumn();
            } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
                // stack delays
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.showDelayColumn();
            } else {
                // afap
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.hideDelayColumn();
            }
        }
        // disarm the stack
        issueButton.setEnabled(false);
        armButton.setSelection(false);
        stack.disarmArmed();
        refreshState();
    });
    autoOptionsCombo.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        if (stack.stackMode == StackMode.AUTOMATIC) {
            if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
                // fix delay
                fixDelaySpinner.setVisible(true);
                labelUnit.setVisible(true);
                commandTableViewer.hideDelayColumn();
            } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
                // stack delay
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.showDelayColumn();
            } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.AFAP.index()) {
                // fix delay
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.hideDelayColumn();
            }
        } else {
            // manual mode
            fixDelaySpinner.setVisible(false);
            labelUnit.setVisible(false);
            commandTableViewer.hideDelayColumn();
        }
        if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
            stack.autoMode = AutoMode.FIX_DELAY;
        } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
            stack.autoMode = AutoMode.STACK_DELAYS;
        } else {
            stack.autoMode = AutoMode.AFAP;
        }
    });
    armButton = new Button(bottomRight, SWT.TOGGLE);
    armButton.setText("1. Arm");
    armButton.setToolTipText("Arm the selected command");
    armButton.setEnabled(false);
    armButton.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        if (armButton.getSelection()) {
            var commandService = getViewSite().getService(ICommandService.class);
            var evaluationService = getViewSite().getService(IEvaluationService.class);
            if (stack.stackMode == StackMode.AUTOMATIC) {
                // automatic stack, arm all commands
                var cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.armAll");
                try {
                    cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
                } catch (Exception e) {
                    log.log(Level.SEVERE, "Could not execute command", e);
                }
            } else {
                // manual stack, individual arm
                var cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.arm");
                try {
                    cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
                } catch (Exception e) {
                    log.log(Level.SEVERE, "Could not execute command", e);
                }
            }
        } else {
            if (stack.getActiveCommand() != null && stack.getActiveCommand().isArmed()) {
                stack.getActiveCommand().setStackedState(StackedState.DISARMED);
                clearArm();
                refreshState();
            }
        }
    });
    issueButton = new Button(bottomRight, SWT.NONE);
    issueButton.setText("2. Issue");
    issueButton.setToolTipText("Issue the selected command");
    issueButton.setEnabled(false);
    issueButton.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        var commandService = getViewSite().getService(ICommandService.class);
        var evaluationService = getViewSite().getService(IEvaluationService.class);
        org.eclipse.core.commands.Command cmd = null;
        if (stack.stackMode == StackMode.AUTOMATIC) {
            // automatic stack - issue all commands
            cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issueAll");
        } else {
            // manual stack - issue one command
            cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issue");
        }
        try {
            cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
        } catch (Exception e) {
            log.log(Level.SEVERE, "Could not execute command", e);
        }
    });
    commandTableViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        updateMessagePanel(sel);
        var stack = CommandStack.getInstance();
        armButton.setSelection(false);
        stack.disarmArmed();
        if (sel.isEmpty() || !stack.isValid() || !sel.getFirstElement().equals(stack.getActiveCommand())) {
            armButton.setEnabled(false);
            issueButton.setEnabled(false);
        } else if (stack.hasRemaining() && YamcsPlugin.hasAnyObjectPrivilege("Command")) {
            armButton.setEnabled(true);
        }
        refreshState();
    });
    getViewSite().setSelectionProvider(commandTableViewer);
    // Set up connection state, and listen to changes
    connectionStateProvider = RCPUtils.findSourceProvider(getViewSite(), ConnectionStateProvider.STATE_KEY_CONNECTED, ConnectionStateProvider.class);
    connectionStateProvider.addSourceProviderListener(sourceProviderListener);
    // Add the popup menu for pasting commands
    addPopupMenu();
    // Set initial state
    refreshState();
    YamcsPlugin.addListener(this);
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) HashMap(java.util.HashMap) ConnectionStateProvider(org.yamcs.studio.core.ui.connections.ConnectionStateProvider) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TextStyle(org.eclipse.swt.graphics.TextStyle) Button(org.eclipse.swt.widgets.Button) Composite(org.eclipse.swt.widgets.Composite) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) RGB(org.eclipse.swt.graphics.RGB) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) GridData(org.eclipse.swt.layout.GridData) Styler(org.eclipse.jface.viewers.StyledString.Styler)

Example 49 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class AddParameterPage method createControl.

@Override
public void createControl(Composite parent) {
    var composite = new Composite(parent, SWT.NONE);
    setControl(composite);
    var gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.numColumns = 2;
    gl.makeColumnsEqualWidth = false;
    composite.setLayout(gl);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tableWrapper1 = new Composite(composite, SWT.NONE);
    contentProvider = new ParameterContentProvider();
    trcl = new TreeColumnLayout();
    tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper1.setLayout(trcl);
    treeViewer = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.getTree().setLinesVisible(true);
    // column container
    var pathColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
    pathColumn.getColumn().setText(COL_NAMESPACE);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var namespace = (String) element;
            return namespace.substring(namespace.lastIndexOf("/") + 1);
        }
    });
    trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    treeViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            contentProvider.setNamespace(null);
            return;
        }
        contentProvider.setNamespace((String) sel.getFirstElement());
    });
    treeViewer.setContentProvider(new NamespaceContentProvider());
    treeViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            var n1 = (String) o1;
            var n2 = (String) o2;
            return n1.compareTo(n2);
        }
    });
    var tableWrapper2 = new Composite(composite, SWT.NONE);
    tcl = new TableColumnLayout();
    tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper2.setLayout(tcl);
    tableViewer = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    var nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    nameColumn.getColumn().setText(COL_NAME);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var obj = (ParameterInfo) element;
            return obj.getQualifiedName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    tableViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setParameter(new ArrayList<>());
            return;
        }
        var parameters = new ArrayList<ParameterInfo>();
        for (var obj : sel.toArray()) {
            parameters.add((ParameterInfo) obj);
        }
        setParameter(parameters);
        setPageComplete(true);
    });
    tableViewer.setContentProvider(contentProvider);
    tableViewer.setInput(contentProvider);
    YamcsPlugin.getMissionDatabase().getParameters().forEach(pmtr -> {
        for (var alias : pmtr.getAliasList()) {
            var namespace = alias.getNamespace();
            if (!namespace.startsWith("/")) {
                return;
            }
            if (!parameterInfos.containsKey(namespace)) {
                parameterInfos.put(namespace, new ArrayList<>());
            }
            parameterInfos.get(namespace).add(pmtr);
            var parentns = namespace.substring(0, namespace.lastIndexOf("/"));
            while (!parentns.isEmpty()) {
                if (!parameterInfos.containsKey(parentns)) {
                    parameterInfos.put(parentns, new ArrayList<>());
                }
                parentns = parentns.substring(0, parentns.lastIndexOf("/"));
            }
        }
    });
    treeViewer.setInput(parameterInfos.keySet());
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            var n1 = (ParameterInfo) o1;
            var n2 = (ParameterInfo) o2;
            return n1.getQualifiedName().compareTo(n2.getQualifiedName());
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 50 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class ConnectionsDialog method createServerPanel.

private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
    var serverPanel = new Composite(parent, SWT.NONE);
    var gd = new GridData(GridData.FILL_BOTH);
    serverPanel.setLayoutData(gd);
    var tcl = new TableColumnLayout();
    serverPanel.setLayout(tcl);
    var serverImage = resourceManager.createImage(getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
    connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    connViewer.getTable().setHeaderVisible(true);
    connViewer.getTable().setLinesVisible(true);
    var urlColumn = new TableViewerColumn(connViewer, SWT.NONE);
    urlColumn.getColumn().setText("Server URL");
    urlColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return serverImage;
        }

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            return conf.getURL();
        }
    });
    tcl.setColumnData(urlColumn.getColumn(), new ColumnPixelData(200));
    var instanceColumn = new TableViewerColumn(connViewer, SWT.NONE);
    instanceColumn.getColumn().setText("Instance");
    instanceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            return conf.getInstance();
        }
    });
    tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(90));
    var userColumn = new TableViewerColumn(connViewer, SWT.NONE);
    userColumn.getColumn().setText("User");
    userColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            if (conf.getAuthType() != AuthType.KERBEROS) {
                return conf.getUser();
            } else {
                return null;
            }
        }
    });
    tcl.setColumnData(userColumn.getColumn(), new ColumnPixelData(90));
    var nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
    nameColumn.getColumn().setText("Comment");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            return conf.getComment();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(200));
    IContentProvider contentProvider = (IStructuredContentProvider) inputElement -> connections.toArray();
    connViewer.setContentProvider(contentProvider);
    connViewer.setInput(contentProvider);
    connViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            var conf = (YamcsConfiguration) sel.getFirstElement();
            yamcsInstanceText.setText(forceString(conf.getInstance()));
            yamcsURLText.setText(forceString(conf.getURL()));
            // / caCertFileText.setText(forceString(conf.getCaCertFile()));
            commentText.setText(forceString(conf.getComment()));
            var authType = (conf.getAuthType() == null) ? AuthType.STANDARD : conf.getAuthType();
            if (authType == AuthType.STANDARD) {
                authTypeCombo.select(0);
                yamcsUserText.setText(forceString(conf.getUser()));
            } else if (authType == AuthType.KERBEROS) {
                authTypeCombo.select(1);
                yamcsUserText.setText("");
            } else {
                throw new IllegalArgumentException("Unexpected auth type " + authType);
            }
            updateState();
        }
    });
    connViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            var c1 = (YamcsConfiguration) o1;
            var c2 = (YamcsConfiguration) o2;
            if (c1.getURL() != null && c2.getURL() != null) {
                return c1.getURL().compareTo(c2.getURL());
            } else {
                return 0;
            }
        }
    });
    return serverPanel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)105 Composite (org.eclipse.swt.widgets.Composite)94 TableViewer (org.eclipse.jface.viewers.TableViewer)78 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)62 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)51 GridData (org.eclipse.swt.layout.GridData)46 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)44 Table (org.eclipse.swt.widgets.Table)38 GridLayout (org.eclipse.swt.layout.GridLayout)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)31 Image (org.eclipse.swt.graphics.Image)28 Label (org.eclipse.swt.widgets.Label)27 Viewer (org.eclipse.jface.viewers.Viewer)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)23 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 Button (org.eclipse.swt.widgets.Button)21 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)18 TableColumn (org.eclipse.swt.widgets.TableColumn)18 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)17