Search in sources :

Example 1 with PassiveRackElement

use of org.netxms.client.objects.configs.PassiveRackElement in project netxms by netxms.

the class RackPassiveElementComparator method compare.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
    */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    TableColumn sortColumn = ((TableViewer) viewer).getTable().getSortColumn();
    if (sortColumn == null)
        return 0;
    int rc;
    switch((Integer) sortColumn.getData("ID")) {
        case RackPassiveElements.COLUMN_NAME:
            rc = ((PassiveRackElement) e1).getName().compareToIgnoreCase(((PassiveRackElement) e2).getName());
            break;
        case RackPassiveElements.COLUMN_POSITION:
            rc = Integer.signum(((PassiveRackElement) e1).getPosition() - ((PassiveRackElement) e2).getPosition());
            break;
        case RackPassiveElements.COLUMN_TYPE:
            rc = Integer.signum(((PassiveRackElement) e1).getType().getValue() - ((PassiveRackElement) e2).getType().getValue());
            break;
        case RackPassiveElements.COLUMN_ORIENTATION:
            rc = Integer.signum(((PassiveRackElement) e1).getOrientation().getValue() - ((PassiveRackElement) e2).getOrientation().getValue());
        default:
            rc = 0;
            break;
    }
    int dir = ((TableViewer) viewer).getTable().getSortDirection();
    return (dir == SWT.UP) ? rc : -rc;
}
Also used : TableColumn(org.eclipse.swt.widgets.TableColumn) PassiveRackElement(org.netxms.client.objects.configs.PassiveRackElement)

Example 2 with PassiveRackElement

use of org.netxms.client.objects.configs.PassiveRackElement in project netxms by netxms.

the class RackWidget method paintControl.

/* (non-Javadoc)
    * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
    */
@Override
public void paintControl(PaintEvent e) {
    final GC gc = e.gc;
    gc.setAntialias(SWT.ON);
    // gc.setInterpolation(SWT.HIGH);
    // Calculate bounding box for rack picture
    Rectangle rect = getClientArea();
    rect.x += MARGIN_WIDTH + UNIT_NUMBER_WIDTH;
    rect.y += MARGIN_HEIGHT + MARGIN_HEIGHT / 2 + TITLE_HEIGHT;
    rect.height -= MARGIN_HEIGHT * 2 + MARGIN_HEIGHT / 2 + TITLE_HEIGHT;
    // Estimated unit width/height and calculate border width
    double unitHeight = (double) rect.height / (double) rack.getHeight();
    int unitWidth = (int) (unitHeight * UNIT_WH_RATIO);
    int borderWidth = unitWidth / BORDER_WIDTH_RATIO;
    if (borderWidth < 3)
        borderWidth = 3;
    rect.height -= borderWidth;
    // precise unit width and height taking borders into consideration
    unitHeight = (double) (rect.height - ((borderWidth + 1) / 2) * 2) / (double) rack.getHeight();
    unitWidth = (int) (unitHeight * UNIT_WH_RATIO);
    rect.width = unitWidth + borderWidth * 2;
    // Title
    // $NON-NLS-1$
    gc.setFont(WidgetHelper.getBestFittingFont(gc, titleFonts, VIEW_LABELS[0], rect.width, TITLE_HEIGHT));
    Point titleSize = gc.textExtent(VIEW_LABELS[view.getValue() - 1]);
    gc.drawText(VIEW_LABELS[view.getValue() - 1], (rect.width / 2 - titleSize.x / 2) + UNIT_NUMBER_WIDTH + MARGIN_WIDTH, rect.y - TITLE_HEIGHT - MARGIN_HEIGHT / 2);
    // Rack itself
    gc.setBackground(SharedColors.getColor(SharedColors.RACK_EMPTY_SPACE, getDisplay()));
    gc.fillRoundRectangle(rect.x, rect.y, rect.width, rect.height, 3, 3);
    gc.setLineWidth(borderWidth);
    gc.setForeground(SharedColors.getColor(SharedColors.RACK_BORDER, getDisplay()));
    gc.drawRoundRectangle(rect.x, rect.y, rect.width, rect.height, 3, 3);
    // Rack bottom
    gc.setBackground(SharedColors.getColor(SharedColors.RACK_BORDER, getDisplay()));
    gc.fillRectangle(rect.x + borderWidth * 2 - (borderWidth + 1) / 2, rect.y + rect.height, borderWidth * 2, (int) (borderWidth * 1.5));
    gc.fillRectangle(rect.x + rect.width - borderWidth * 3 - (borderWidth + 1) / 2, rect.y + rect.height, borderWidth * 2, (int) (borderWidth * 1.5));
    // Draw unit numbers
    int[] unitBaselines = new int[rack.getHeight() + 1];
    // $NON-NLS-1$
    gc.setFont(WidgetHelper.getBestFittingFont(gc, labelFonts, "00", UNIT_NUMBER_WIDTH, (int) unitHeight - 2));
    gc.setForeground(SharedColors.getColor(SharedColors.RACK_TEXT, getDisplay()));
    gc.setBackground(SharedColors.getColor(SharedColors.RACK_BACKGROUND, getDisplay()));
    gc.setLineWidth(1);
    double dy = rack.isTopBottomNumbering() ? rect.y + unitHeight + (borderWidth + 1) / 2 : rect.y + rect.height - (borderWidth + 1) / 2;
    if (rack.isTopBottomNumbering())
        unitBaselines[0] = (int) (dy - unitHeight);
    for (int u = 1; u <= rack.getHeight(); u++) {
        int y = (int) dy;
        gc.drawLine(MARGIN_WIDTH, y, UNIT_NUMBER_WIDTH, y);
        String label = Integer.toString(u);
        Point textExtent = gc.textExtent(label);
        gc.drawText(label, UNIT_NUMBER_WIDTH - textExtent.x, y - (int) unitHeight / 2 - textExtent.y / 2);
        if (rack.isTopBottomNumbering()) {
            unitBaselines[u] = y;
            dy += unitHeight;
        } else {
            unitBaselines[u - 1] = y;
            dy -= unitHeight;
        }
    }
    if (!rack.isTopBottomNumbering())
        unitBaselines[rack.getHeight()] = (int) dy;
    // Draw attributes
    List<PassiveRackElement> attributes = rack.getPassiveElements().getElements();
    for (PassiveRackElement c : attributes) {
        if ((c.getPosition() < 1) || (c.getPosition() > rack.getHeight()) || (c.getOrientation() != view) && (c.getOrientation() != RackOrientation.FILL))
            continue;
        int topLine, bottomLine;
        if (rack.isTopBottomNumbering()) {
            // lower border
            bottomLine = unitBaselines[c.getPosition()];
            // upper border
            topLine = unitBaselines[c.getPosition() - 1];
        } else {
            // lower border
            bottomLine = unitBaselines[c.getPosition() - 1];
            // upper border
            topLine = unitBaselines[c.getPosition()];
        }
        final Rectangle unitRect = new Rectangle(rect.x + (borderWidth + 1) / 2, topLine + 1, rect.width - borderWidth, bottomLine - topLine);
        if ((unitRect.width <= 0) || (unitRect.height <= 0))
            break;
        Image image;
        switch(c.getType()) {
            case FILLER_PANEL:
                image = imageFillerPanel;
                break;
            case PATCH_PANEL:
                image = imagePatchPanel;
                break;
            case ORGANISER:
                image = imageOrganiserPanel;
                break;
            default:
                continue;
        }
        Rectangle r = image.getBounds();
        gc.drawImage(image, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
    }
    // Draw units
    objects.clear();
    List<RackElement> units = rack.getUnits();
    for (RackElement n : units) {
        if ((n.getRackPosition() < 1) || (n.getRackPosition() > rack.getHeight()) || (rack.isTopBottomNumbering() && (n.getRackPosition() + n.getRackHeight() > rack.getHeight() + 1)) || (!rack.isTopBottomNumbering() && (n.getRackPosition() - n.getRackHeight() < 0)) || ((n.getRackOrientation() != view) && (n.getRackOrientation() != RackOrientation.FILL)))
            continue;
        int topLine, bottomLine;
        if (rack.isTopBottomNumbering()) {
            // lower border
            bottomLine = unitBaselines[n.getRackPosition() + n.getRackHeight() - 1];
            // upper border
            topLine = unitBaselines[n.getRackPosition() - 1];
        } else {
            // lower border
            bottomLine = unitBaselines[n.getRackPosition() - n.getRackHeight()];
            // upper border
            topLine = unitBaselines[n.getRackPosition()];
        }
        final Rectangle unitRect = new Rectangle(rect.x + (borderWidth + 1) / 2, topLine + 1, rect.width - borderWidth, bottomLine - topLine);
        if ((unitRect.width <= 0) || (unitRect.height <= 0))
            break;
        objects.add(new ObjectImage(n, unitRect));
        // draw status indicator
        gc.setBackground(StatusDisplayInfo.getStatusColor(n.getStatus()));
        gc.fillRectangle(unitRect.x - borderWidth + borderWidth / 4 + 1, unitRect.y + 1, borderWidth / 2 - 1, Math.min(borderWidth, (int) unitHeight - 2));
        if ((n.getRearRackImage() != null) && !n.getRearRackImage().equals(NXCommon.EMPTY_GUID) && view == RackOrientation.REAR) {
            Image image = ImageProvider.getInstance().getImage(n.getRearRackImage());
            Rectangle r = image.getBounds();
            gc.drawImage(image, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
        } else if ((n.getFrontRackImage() != null) && !n.getFrontRackImage().equals(NXCommon.EMPTY_GUID) && view == RackOrientation.FRONT) {
            Image image = ImageProvider.getInstance().getImage(n.getFrontRackImage());
            Rectangle r = image.getBounds();
            gc.drawImage(image, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
        } else // Draw default representation
        {
            Image imageTop = (view == RackOrientation.REAR && n.getRackOrientation() == RackOrientation.FILL) ? imageDefaultRear : imageDefaultTop;
            Rectangle r = imageTop.getBounds();
            if (n.getRackHeight() == 1) {
                gc.drawImage(imageTop, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
            } else {
                Image imageMiddle = (view == RackOrientation.REAR && n.getRackOrientation() == RackOrientation.FILL) ? imageDefaultRear : imageDefaultMiddle;
                Image imageBottom = (view == RackOrientation.REAR && n.getRackOrientation() == RackOrientation.FILL) ? imageDefaultRear : imageDefaultBottom;
                if (rack.isTopBottomNumbering()) {
                    unitRect.height = unitBaselines[n.getRackPosition()] - topLine;
                    gc.drawImage(imageTop, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
                    r = imageMiddle.getBounds();
                    int u = n.getRackPosition() + 1;
                    for (int i = 1; i < n.getRackHeight() - 1; i++, u++) {
                        unitRect.y = unitBaselines[u - 1];
                        unitRect.height = unitBaselines[u] - unitRect.y;
                        gc.drawImage(imageMiddle, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
                    }
                    r = imageBottom.getBounds();
                    unitRect.y = unitBaselines[u - 1];
                    unitRect.height = unitBaselines[u] - unitRect.y;
                    gc.drawImage(imageBottom, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
                } else {
                    unitRect.height = unitBaselines[n.getRackPosition() - 1] - topLine;
                    gc.drawImage(imageTop, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
                    r = imageMiddle.getBounds();
                    int u = n.getRackPosition() - 1;
                    for (int i = 1; i < n.getRackHeight() - 1; i++, u--) {
                        unitRect.y = unitBaselines[u];
                        unitRect.height = unitBaselines[u - 1] - unitRect.y;
                        gc.drawImage(imageMiddle, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
                    }
                    r = imageBottom.getBounds();
                    unitRect.y = unitBaselines[u];
                    unitRect.height = unitBaselines[u - 1] - unitRect.y;
                    gc.drawImage(imageBottom, 0, 0, r.width, r.height, unitRect.x, unitRect.y, unitRect.width, unitRect.height);
                }
            }
        }
    }
}
Also used : RackElement(org.netxms.client.objects.RackElement) PassiveRackElement(org.netxms.client.objects.configs.PassiveRackElement) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) PassiveRackElement(org.netxms.client.objects.configs.PassiveRackElement)

Example 3 with PassiveRackElement

use of org.netxms.client.objects.configs.PassiveRackElement in project netxms by netxms.

the class RackPassiveElements 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);
    rack = (Rack) getElement().getAdapter(Rack.class);
    if (// Paranoid check
    rack == null)
        return dialogArea;
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { "Name", "Type", "Position", "Orientation" };
    final int[] columnWidths = { 150, 100, 70, 30 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new RackPassiveElementLabelProvider());
    viewer.setComparator(new RackPassiveElementComparator());
    passiveElements = new PassiveRackElementGroup(rack.getPassiveElements());
    viewer.setInput(passiveElements.getElements());
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    viewer.getControl().setLayoutData(gridData);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    buttons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gridData);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText("&Add...");
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            RackPassiveElementEditDialog dlg = new RackPassiveElementEditDialog(getShell(), null);
            if (dlg.open() == Window.OK) {
                passiveElements.add(dlg.getElement());
                viewer.setInput(passiveElements.getElements());
                isModified = true;
            }
        }
    });
    editButton = new Button(buttons, SWT.PUSH);
    editButton.setText("&Edit...");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    editButton.setLayoutData(rd);
    editButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection.size() == 1) {
                RackPassiveElementEditDialog dlg = new RackPassiveElementEditDialog(getShell(), (PassiveRackElement) selection.getFirstElement());
                if (dlg.open() == Window.OK) {
                    viewer.setInput(passiveElements.getElements());
                    isModified = true;
                }
            }
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText("&Delete...");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            passiveElements.getElements().removeAll(selection.toList());
            viewer.setInput(passiveElements.getElements());
            isModified = true;
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editButton.notifyListeners(SWT.Selection, new Event());
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            editButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
        }
    });
    return dialogArea;
}
Also used : RackPassiveElementComparator(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.RackPassiveElementComparator) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RackPassiveElementLabelProvider(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.RackPassiveElementLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PassiveRackElement(org.netxms.client.objects.configs.PassiveRackElement) RackPassiveElementEditDialog(org.netxms.ui.eclipse.objectmanager.dialogs.RackPassiveElementEditDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) PassiveRackElementGroup(org.netxms.client.objects.configs.PassiveRackElementGroup) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

PassiveRackElement (org.netxms.client.objects.configs.PassiveRackElement)3 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Event (org.eclipse.swt.widgets.Event)1