Search in sources :

Example 31 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.

the class MapOptions method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (NetworkMap) getElement().getAdapter(NetworkMap.class);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    /**
     ** object display ***
     */
    Group objectDisplayGroup = new Group(dialogArea, SWT.NONE);
    objectDisplayGroup.setText(Messages.get().MapOptions_DefaultDispOptions);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    objectDisplayGroup.setLayoutData(gd);
    layout = new GridLayout();
    objectDisplayGroup.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    objectDisplayMode = WidgetHelper.createLabeledCombo(objectDisplayGroup, SWT.READ_ONLY, Messages.get().MapOptions_DisplayObjectsAs, gd);
    objectDisplayMode.add(Messages.get().MapOptions_Icons);
    objectDisplayMode.add(Messages.get().MapOptions_SmallLabels);
    objectDisplayMode.add(Messages.get().MapOptions_LargeLabels);
    objectDisplayMode.add(Messages.get().MapOptions_StatusIcons);
    objectDisplayMode.add("Floor plan");
    objectDisplayMode.select(object.getObjectDisplayMode().getValue());
    checkShowStatusIcon = new Button(objectDisplayGroup, SWT.CHECK);
    checkShowStatusIcon.setText(Messages.get().MapOptions_ShowStatusIcon);
    checkShowStatusIcon.setSelection((object.getFlags() & NetworkMap.MF_SHOW_STATUS_ICON) != 0);
    checkShowStatusFrame = new Button(objectDisplayGroup, SWT.CHECK);
    checkShowStatusFrame.setText(Messages.get().MapOptions_ShowStatusFrame);
    checkShowStatusFrame.setSelection((object.getFlags() & NetworkMap.MF_SHOW_STATUS_FRAME) != 0);
    checkShowStatusBkgnd = new Button(objectDisplayGroup, SWT.CHECK);
    checkShowStatusBkgnd.setText(Messages.get().MapOptions_ShowStatusBkgnd);
    checkShowStatusBkgnd.setSelection((object.getFlags() & NetworkMap.MF_SHOW_STATUS_BKGND) != 0);
    checkShowLinkDirection = new Button(objectDisplayGroup, SWT.CHECK);
    checkShowLinkDirection.setText("Show link direction");
    checkShowLinkDirection.setSelection((object.getFlags() & NetworkMap.MF_SHOW_LINK_DIRECTION) != 0);
    /**
     ** default link appearance ***
     */
    Group linkGroup = new Group(dialogArea, SWT.NONE);
    linkGroup.setText(Messages.get().MapOptions_DefaultConnOptions);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    linkGroup.setLayoutData(gd);
    layout = new GridLayout();
    linkGroup.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    routingAlgorithm = WidgetHelper.createLabeledCombo(linkGroup, SWT.READ_ONLY, Messages.get().MapOptions_RoutingAlg, gd);
    routingAlgorithm.add(Messages.get().MapOptions_Direct);
    routingAlgorithm.add(Messages.get().MapOptions_Manhattan);
    routingAlgorithm.select(object.getDefaultLinkRouting() - 1);
    final SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            linkColor.setEnabled(radioColorCustom.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    };
    radioColorDefault = new Button(linkGroup, SWT.RADIO);
    radioColorDefault.setText(Messages.get().MapOptions_DefColor);
    radioColorDefault.setSelection(object.getDefaultLinkColor() < 0);
    radioColorDefault.addSelectionListener(listener);
    gd = new GridData();
    gd.verticalIndent = WidgetHelper.OUTER_SPACING * 2;
    radioColorDefault.setLayoutData(gd);
    radioColorCustom = new Button(linkGroup, SWT.RADIO);
    radioColorCustom.setText(Messages.get().MapOptions_CustColor);
    radioColorCustom.setSelection(object.getDefaultLinkColor() >= 0);
    radioColorCustom.addSelectionListener(listener);
    linkColor = new ColorSelector(linkGroup);
    linkColor.setColorValue(ColorConverter.rgbFromInt(object.getDefaultLinkColor()));
    linkColor.setEnabled(object.getDefaultLinkColor() >= 0);
    gd = new GridData();
    gd.horizontalIndent = 20;
    linkColor.getButton().setLayoutData(gd);
    /**
     ** topology options ***
     */
    if (object.getMapType() != NetworkMap.TYPE_CUSTOM) {
        Group topoGroup = new Group(dialogArea, SWT.NONE);
        topoGroup.setText(Messages.get().MapOptions_TopologyOptions);
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        gd.horizontalSpan = 2;
        topoGroup.setLayoutData(gd);
        layout = new GridLayout();
        topoGroup.setLayout(layout);
        checkIncludeEndNodes = new Button(topoGroup, SWT.CHECK);
        checkIncludeEndNodes.setText(Messages.get().MapOptions_IncludeEndNodes);
        checkIncludeEndNodes.setSelection((object.getFlags() & NetworkMap.MF_SHOW_END_NODES) != 0);
        checkCustomRadius = new Button(topoGroup, SWT.CHECK);
        checkCustomRadius.setText(Messages.get().MapOptions_CustomDiscoRadius);
        checkCustomRadius.setSelection(object.getDiscoveryRadius() > 0);
        checkCustomRadius.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                topologyRadius.setEnabled(checkCustomRadius.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        topologyRadius = WidgetHelper.createLabeledSpinner(topoGroup, SWT.BORDER, Messages.get().MapOptions_TopoDiscoRadius, 1, 255, WidgetHelper.DEFAULT_LAYOUT_DATA);
        topologyRadius.setSelection(object.getDiscoveryRadius());
        topologyRadius.setEnabled(object.getDiscoveryRadius() > 0);
    }
    /**
     ** advanced options ***
     */
    Group advGroup = new Group(dialogArea, SWT.NONE);
    advGroup.setText(Messages.get().MapOptions_AdvOptions);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    advGroup.setLayoutData(gd);
    layout = new GridLayout();
    advGroup.setLayout(layout);
    checkCalculateStatus = new Button(advGroup, SWT.CHECK);
    checkCalculateStatus.setText(Messages.get().MapOptions_CalcStatusFromObjects);
    checkCalculateStatus.setSelection((object.getFlags() & NetworkMap.MF_CALCULATE_STATUS) != 0);
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 32 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.

the class MapBackground method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    final IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    // $NON-NLS-1$
    disableGeolocationBackground = ps.getBoolean("DISABLE_GEOLOCATION_BACKGROUND");
    object = (NetworkMap) getElement().getAdapter(NetworkMap.class);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 1;
    dialogArea.setLayout(layout);
    Group typeGroup = new Group(dialogArea, SWT.NONE);
    typeGroup.setText(Messages.get().MapBackground_BkgndType);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    typeGroup.setLayoutData(gd);
    layout = new GridLayout();
    typeGroup.setLayout(layout);
    final SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            enableControls(radioTypeImage.getSelection(), disableGeolocationBackground ? false : radioTypeGeoMap.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    };
    radioTypeNone = new Button(typeGroup, SWT.RADIO);
    radioTypeNone.setText(Messages.get().MapBackground_None);
    radioTypeNone.setSelection(object.getBackground().equals(NXCommon.EMPTY_GUID));
    radioTypeNone.addSelectionListener(listener);
    radioTypeImage = new Button(typeGroup, SWT.RADIO);
    radioTypeImage.setText(Messages.get().MapBackground_Image);
    radioTypeImage.setSelection(!object.getBackground().equals(NXCommon.EMPTY_GUID) && !object.getBackground().equals(NetworkMap.GEOMAP_BACKGROUND));
    radioTypeImage.addSelectionListener(listener);
    if (!disableGeolocationBackground) {
        radioTypeGeoMap = new Button(typeGroup, SWT.RADIO);
        radioTypeGeoMap.setText(Messages.get().MapBackground_GeoMap);
        radioTypeGeoMap.setSelection(object.getBackground().equals(NetworkMap.GEOMAP_BACKGROUND));
        radioTypeGeoMap.addSelectionListener(listener);
    } else {
        if (object.getBackground().equals(NetworkMap.GEOMAP_BACKGROUND))
            radioTypeNone.setSelection(true);
    }
    image = new ImageSelector(dialogArea, SWT.NONE);
    image.setLabel(Messages.get().MapBackground_BkgndImage);
    if (radioTypeImage.getSelection())
        image.setImageGuid(object.getBackground(), true);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    image.setLayoutData(gd);
    if (!disableGeolocationBackground) {
        Group geomapGroup = new Group(dialogArea, SWT.NONE);
        geomapGroup.setText(Messages.get().MapBackground_GroupGeoMap);
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        geomapGroup.setLayoutData(gd);
        layout = new GridLayout();
        geomapGroup.setLayout(layout);
        GeoLocation gl = object.getBackgroundLocation();
        latitude = new LabeledText(geomapGroup, SWT.NONE);
        latitude.setLabel(Messages.get().MapBackground_Lat);
        latitude.setText(gl.getLatitudeAsString());
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        latitude.setLayoutData(gd);
        longitude = new LabeledText(geomapGroup, SWT.NONE);
        longitude.setLabel(Messages.get().MapBackground_Lon);
        longitude.setText(gl.getLongitudeAsString());
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        longitude.setLayoutData(gd);
        Composite zoomGroup = new Composite(geomapGroup, SWT.NONE);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.marginTop = WidgetHelper.OUTER_SPACING;
        zoomGroup.setLayout(layout);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        zoomGroup.setLayoutData(gd);
        zoomLabel = new Label(zoomGroup, SWT.NONE);
        zoomLabel.setText(Messages.get().MapBackground_ZoomLevel);
        gd = new GridData();
        gd.horizontalAlignment = SWT.LEFT;
        gd.horizontalSpan = 2;
        zoomLabel.setLayoutData(gd);
        zoomScale = new Scale(zoomGroup, SWT.HORIZONTAL);
        zoomScale.setMinimum(1);
        zoomScale.setMaximum(18);
        zoomScale.setSelection(object.getBackgroundZoom());
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        zoomScale.setLayoutData(gd);
        zoomScale.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                zoomSpinner.setSelection(zoomScale.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        zoomSpinner = new Spinner(zoomGroup, SWT.BORDER);
        zoomSpinner.setMinimum(1);
        zoomSpinner.setMaximum(18);
        zoomSpinner.setSelection(object.getBackgroundZoom());
        zoomSpinner.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                zoomScale.setSelection(zoomSpinner.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    Composite colorArea = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    colorArea.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    colorArea.setLayoutData(gd);
    Label label = new Label(colorArea, SWT.NONE);
    label.setText(Messages.get().MapBackground_BkgndColor);
    backgroundColor = new ColorSelector(colorArea);
    backgroundColor.setColorValue(ColorConverter.rgbFromInt(object.getBackgroundColor()));
    enableControls(radioTypeImage.getSelection(), disableGeolocationBackground ? false : radioTypeGeoMap.getSelection());
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) Scale(org.eclipse.swt.widgets.Scale) ImageSelector(org.netxms.ui.eclipse.imagelibrary.widgets.ImageSelector) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GeoLocation(org.netxms.base.GeoLocation) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ColorSelector(org.eclipse.jface.preference.ColorSelector) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 33 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.

the class DataSourceEditDlg method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    GridData gd = new GridData();
    if (!graphIsTemplate) {
        dciSelector = new DciSelector(dialogArea, SWT.NONE, false);
        dciSelector.setLabel(Messages.get().DataSourceEditDlg_DCI);
        dciSelector.setDciId(dci.nodeId, dci.dciId);
        dciSelector.setDcObjectType(dci.type);
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        gd.widthHint = 400;
        gd.horizontalSpan = 2;
        dciSelector.setLayoutData(gd);
    }
    name = new LabeledText(dialogArea, SWT.NONE);
    name.setLabel(Messages.get().DataSourceEditDlg_DispName);
    name.setText(dci.name);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    name.setLayoutData(gd);
    displayFormat = new LabeledText(dialogArea, SWT.NONE);
    displayFormat.setLabel(Messages.get().DataSourceEditDlg_DisplayFormat);
    displayFormat.setText(dci.displayFormat);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    displayFormat.setLayoutData(gd);
    if (graphIsTemplate) {
        dciName = new LabeledText(dialogArea, SWT.NONE);
        dciName.setLabel("DCI Name");
        dciName.setText(dci.dciName);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalSpan = 2;
        dciName.setLayoutData(gd);
        dciDescription = new LabeledText(dialogArea, SWT.NONE);
        dciDescription.setLabel("DCI Description");
        dciDescription.setText(dci.dciDescription);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalSpan = 2;
        dciDescription.setLayoutData(gd);
    }
    if (dci.type == ChartDciConfig.TABLE) {
        Group tableGroup = new Group(dialogArea, SWT.NONE);
        tableGroup.setText(Messages.get().DataSourceEditDlg_TableCell);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalSpan = 2;
        tableGroup.setLayoutData(gd);
        layout = new GridLayout();
        tableGroup.setLayout(layout);
        dataColumn = new LabeledText(tableGroup, SWT.NONE);
        dataColumn.setLabel(Messages.get().DataSourceEditDlg_DataColumn);
        dataColumn.setText(dci.column);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        dataColumn.setLayoutData(gd);
        instance = new LabeledText(tableGroup, SWT.NONE);
        instance.setLabel(Messages.get().DataSourceEditDlg_Instance);
        instance.setText(dci.instance);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        instance.setLayoutData(gd);
    }
    /**
     * Display type **
     */
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.TOP;
    displayType = WidgetHelper.createLabeledCombo(dialogArea, SWT.READ_ONLY | SWT.BORDER, "Display type", gd);
    displayType.add("Default");
    displayType.add("Line");
    displayType.add("Area");
    displayType.select(dci.getDisplayType());
    /**
     * Options group **
     */
    Group optionsGroup = new Group(dialogArea, SWT.NONE);
    optionsGroup.setText(Messages.get().DataSourceEditDlg_Options);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.TOP;
    gd.verticalSpan = 2;
    optionsGroup.setLayoutData(gd);
    layout = new GridLayout();
    optionsGroup.setLayout(layout);
    checkShowThresholds = new Button(optionsGroup, SWT.CHECK);
    checkShowThresholds.setText(Messages.get().DataSourceEditDlg_ShowThresholds);
    checkShowThresholds.setSelection(dci.showThresholds);
    checkInvertValues = new Button(optionsGroup, SWT.CHECK);
    checkInvertValues.setText(Messages.get().DataSourceEditDlg_InvertValues);
    checkInvertValues.setSelection(dci.invertValues);
    if (graphIsTemplate) {
        checkMultipeMatch = new Button(optionsGroup, SWT.CHECK);
        checkMultipeMatch.setText("Multiple match");
        checkMultipeMatch.setSelection(dci.multiMatch);
    }
    /**
     * Color group **
     */
    Group colorGroup = new Group(dialogArea, SWT.NONE);
    colorGroup.setText(Messages.get().DataSourceEditDlg_Color);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    colorGroup.setLayoutData(gd);
    layout = new GridLayout();
    layout.numColumns = 2;
    colorGroup.setLayout(layout);
    colorAuto = new Button(colorGroup, SWT.RADIO);
    colorAuto.setText(Messages.get().DataSourceEditDlg_AutoColor);
    colorAuto.setSelection(dci.color.equalsIgnoreCase(ChartDciConfig.UNSET_COLOR));
    gd = new GridData();
    gd.horizontalSpan = 2;
    colorAuto.setLayoutData(gd);
    colorAuto.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            colorSelector.setEnabled(false);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    colorCustom = new Button(colorGroup, SWT.RADIO);
    colorCustom.setText(Messages.get().DataSourceEditDlg_CustomColor);
    colorCustom.setSelection(!dci.color.equalsIgnoreCase(ChartDciConfig.UNSET_COLOR));
    colorCustom.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            colorSelector.setEnabled(true);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    colorSelector = new ColorSelector(colorGroup);
    colorSelector.setColorValue(ColorConverter.rgbFromInt(dci.getColorAsInt()));
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    gd.grabExcessHorizontalSpace = true;
    colorSelector.getButton().setLayoutData(gd);
    colorSelector.setEnabled(!dci.color.equalsIgnoreCase(ChartDciConfig.UNSET_COLOR));
    return dialogArea;
}
Also used : DciSelector(org.netxms.ui.eclipse.datacollection.widgets.DciSelector) Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 34 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project dbeaver by serge-rider.

the class ColorSettingsDialog method createAttributeSettingsArea.

private void createAttributeSettingsArea(Composite composite) {
    Composite mainGroup = UIUtils.createComposite(composite, 1);
    mainGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
    {
        Composite colorsGroup = UIUtils.createComposite(mainGroup, 2);
        colorsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
        // UIUtils.createControlLabel(colorsGroup, "Cell conditions");
        colorsTable = new Table(colorsGroup, SWT.BORDER | SWT.FULL_SELECTION);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 300;
        gd.heightHint = 100;
        colorsTable.setLayoutData(gd);
        colorsTable.addListener(SWT.EraseItem, event -> {
            if ((event.detail & SWT.SELECTED) != 0) {
                // event.detail &= ~SWT.SELECTED;
                Color bgColor = getColorTableBackground((DBVColorOverride) event.item.getData());
                if (bgColor != null) {
                    event.gc.setBackground(bgColor);
                } else {
                    event.gc.setBackground(colorsTable.getBackground());
                }
                event.gc.fillRectangle(event.x, event.y, event.width, event.height);
                event.gc.drawRectangle(event.x, event.y, event.width - 1, event.height - 1);
            }
        });
        /*
            colorsTable.addListener(SWT.PaintItem, event -> {
                if ((event.detail & SWT.SELECTED) == 0) {
                    return;
                }
                event.gc.drawText(((TableItem) event.item).getText(), event.x, event.y);
            });
*/
        // UIUtils.createTableColumn(colorsTable, SWT.LEFT, "Operator");
        UIUtils.createTableColumn(colorsTable, SWT.RIGHT, "Value(s)");
        UIUtils.executeOnResize(colorsTable, () -> UIUtils.packColumns(colorsTable, true));
        colorsTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = colorsTable.getSelectionIndex();
                curOverride = selectionIndex < 0 ? null : (DBVColorOverride) colorsTable.getItem(selectionIndex).getData();
                btnDelete.setEnabled(selectionIndex >= 0);
                updateControlsState();
            }
        });
        {
            ToolBar buttonsPanel = new ToolBar(colorsGroup, SWT.FLAT | SWT.VERTICAL);
            buttonsPanel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
            UIUtils.createToolItem(buttonsPanel, "Add", UIIcon.ROW_ADD, new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    curOverride = new DBVColorOverride(attribute.getName(), DBCLogicalOperator.EQUALS, null, null, null);
                    vEntity.addColorOverride(curOverride);
                    TableItem tableItem = new TableItem(colorsTable, SWT.NONE);
                    tableItem.setData(curOverride);
                    colorsTable.setSelection(tableItem);
                    updateColorItem(tableItem);
                    updateControlsState();
                }
            });
            btnDelete = UIUtils.createToolItem(buttonsPanel, "Delete", UIIcon.ROW_DELETE, new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (curOverride != null) {
                        colorsTable.getItem(colorsTable.getSelectionIndex()).dispose();
                        vEntity.removeColorOverride(curOverride);
                        curOverride = null;
                        updateControlsState();
                    }
                }
            });
            btnDelete.setEnabled(false);
        }
    }
    {
        settingsGroup = new Composite(mainGroup, SWT.NONE);
        settingsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
        settingsGroup.setLayout(new GridLayout(3, false));
        GridData gd = new GridData();
        gd.horizontalSpan = 3;
        UIUtils.createControlLabel(settingsGroup, "Settings").setLayoutData(gd);
        rangeCheck = UIUtils.createCheckbox(settingsGroup, "Range / gradient", "Use value range / color gradient", false, 3);
        rangeCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (curOverride != null) {
                    curOverride.setRange(rangeCheck.getSelection());
                }
                updateControlsState();
            }
        });
        singleColumnCheck = UIUtils.createCheckbox(settingsGroup, "Apply colors to this column only", "Apply colors to this column only, otherwise color full row", false, 3);
        singleColumnCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (curOverride != null) {
                    curOverride.setSingleColumn(singleColumnCheck.getSelection());
                }
            }
        });
        UIUtils.createControlLabel(settingsGroup, "Value(s)");
        editorPlaceholder1 = new Composite(settingsGroup, SWT.NONE);
        editorPlaceholder1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorPlaceholder1.setLayout(new FillLayout());
        editorPlaceholder2 = new Composite(settingsGroup, SWT.NONE);
        editorPlaceholder2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorPlaceholder2.setLayout(new FillLayout());
        valueEditor1 = createValueEditor(editorPlaceholder1, 0);
        valueEditor2 = createValueEditor(editorPlaceholder2, 1);
        UIUtils.createControlLabel(settingsGroup, "Background");
        bgColorSelector1 = new ColorSelector(settingsGroup);
        bgColorSelector1.addListener(event -> {
            curOverride.setColorBackground(StringConverter.asString(bgColorSelector1.getColorValue()));
            updateCurrentTreeItem();
        });
        bgColorSelector2 = new ColorSelector(settingsGroup);
        bgColorSelector2.addListener(event -> {
            curOverride.setColorBackground2(StringConverter.asString(bgColorSelector2.getColorValue()));
            updateCurrentTreeItem();
        });
        UIUtils.createControlLabel(settingsGroup, "Foreground");
        fgColorSelector1 = new ColorSelector(settingsGroup);
        fgColorSelector1.addListener(event -> {
            curOverride.setColorForeground(StringConverter.asString(fgColorSelector1.getColorValue()));
            updateCurrentTreeItem();
        });
        fgColorSelector2 = new ColorSelector(settingsGroup);
        fgColorSelector2.addListener(event -> {
            curOverride.setColorForeground2(StringConverter.asString(fgColorSelector2.getColorValue()));
            updateCurrentTreeItem();
        });
        UIUtils.createInfoLabel(settingsGroup, "To use gradient set minimum and maximum\ncolumn values and two\ncolors for gradient range. ", GridData.FILL_HORIZONTAL, 3);
    }
}
Also used : Arrays(java.util.Arrays) SashForm(org.eclipse.swt.custom.SashForm) IValueManager(org.jkiss.dbeaver.ui.data.IValueManager) ControlEnableState(org.eclipse.jface.dialogs.ControlEnableState) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) Nullable(org.jkiss.code.Nullable) Point(org.eclipse.swt.graphics.Point) NotNull(org.jkiss.code.NotNull) ColorSelector(org.eclipse.jface.preference.ColorSelector) ArrayList(java.util.ArrayList) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBDDisplayFormat(org.jkiss.dbeaver.model.data.DBDDisplayFormat) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) Log(org.jkiss.dbeaver.Log) RGB(org.eclipse.swt.graphics.RGB) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) ResultSetUtils(org.jkiss.dbeaver.ui.controls.resultset.ResultSetUtils) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) DBCLogicalOperator(org.jkiss.dbeaver.model.exec.DBCLogicalOperator) DBValueFormatting(org.jkiss.dbeaver.model.DBValueFormatting) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ArrayUtils(org.jkiss.utils.ArrayUtils) List(java.util.List) Color(org.eclipse.swt.graphics.Color) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) StringConverter(org.eclipse.jface.resource.StringConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ValueManagerRegistry(org.jkiss.dbeaver.ui.data.registry.ValueManagerRegistry) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride)

Example 35 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project yamcs-studio by yamcs.

the class NamedColorDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    var fieldArea = new Composite((Composite) super.createDialogArea(parent), SWT.NONE);
    var noName = name == null;
    var title = noName ? "Add Color" : "Edit Color";
    getShell().setText(title);
    setTitle(title);
    setMessage(noName ? "Enter color details." : "Edit color details.");
    fieldArea.setLayoutData(new GridData(GridData.FILL_BOTH));
    var gl = new GridLayout(2, false);
    fieldArea.setLayout(gl);
    var label = new Label(fieldArea, SWT.NONE);
    label.setText("Name:");
    label.setLayoutData(new GridData());
    nameText = new Text(fieldArea, SWT.BORDER);
    if (name != null) {
        nameText.setText(name);
    }
    nameText.setLayoutData(new GridData());
    nameText.addModifyListener(e -> updatePageComplete());
    nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    label = new Label(fieldArea, SWT.NONE);
    label.setText("Color:");
    label.setLayoutData(new GridData());
    rgbSelector = new ColorSelector(fieldArea);
    rgbSelector.setColorValue(rgb);
    var backgroundColorButton = rgbSelector.getButton();
    backgroundColorButton.setLayoutData(new GridData());
    Dialog.applyDialogFont(fieldArea);
    return fieldArea;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) ColorSelector(org.eclipse.jface.preference.ColorSelector)

Aggregations

ColorSelector (org.eclipse.jface.preference.ColorSelector)39 GridData (org.eclipse.swt.layout.GridData)37 Composite (org.eclipse.swt.widgets.Composite)31 GridLayout (org.eclipse.swt.layout.GridLayout)27 Label (org.eclipse.swt.widgets.Label)27 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 Button (org.eclipse.swt.widgets.Button)20 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)14 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)14 SelectionListener (org.eclipse.swt.events.SelectionListener)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12 Group (org.eclipse.swt.widgets.Group)11 Link (org.eclipse.swt.widgets.Link)10 SashForm (org.eclipse.swt.custom.SashForm)9 RGB (org.eclipse.swt.graphics.RGB)8 Iterator (java.util.Iterator)7 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7