Search in sources :

Example 31 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.

the class DefaultColumnHeaderRenderer method getControlBounds.

/**
	 * @return the bounds reserved for the control
	 */
protected Rectangle getControlBounds(Object value, boolean preferred) {
    Rectangle bounds = getBounds();
    GridColumn column = (GridColumn) value;
    Point controlSize = computeControlSize(column);
    int y = getBounds().y + getBounds().height - bottomMargin - controlSize.y;
    return new Rectangle(bounds.x + 3, y, bounds.width - 6, controlSize.y);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 32 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.

the class TerminologyViewPart method createPartControl.

/**
	 * 创建控件。
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    createAction();
    GridLayout parentGl = new GridLayout(1, false);
    parentGl.marginWidth = 0;
    parentGl.marginHeight = 0;
    parent.setLayout(parentGl);
    final Composite contentPanel = new Composite(parent, SWT.NONE);
    GridLayout secondPageCompositeGl = new GridLayout(1, false);
    secondPageCompositeGl.marginBottom = -1;
    secondPageCompositeGl.marginLeft = -1;
    secondPageCompositeGl.marginRight = -1;
    secondPageCompositeGl.marginTop = -1;
    secondPageCompositeGl.marginWidth = 0;
    secondPageCompositeGl.marginHeight = 0;
    contentPanel.setLayout(secondPageCompositeGl);
    contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    contentPanel.setLayout(secondPageCompositeGl);
    contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // firstPageComposite = new Composite(contentPanel, SWT.NONE);
    // firstPageComposite.setLayout(new GridLayout(1, false));
    // secondPageComposite = new Composite(contentPanel, SWT.NONE);
    // GridLayout secondPageCompositeGl = new GridLayout(1, false);
    // secondPageCompositeGl.marginBottom = -1;
    // secondPageCompositeGl.marginLeft = -1;
    // secondPageCompositeGl.marginRight = -1;
    // secondPageCompositeGl.marginTop = -1;
    // secondPageCompositeGl.marginWidth = 0;
    // secondPageCompositeGl.marginHeight = 0;
    // secondPageComposite.setLayout(secondPageCompositeGl);
    // secondPageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable = new Grid(contentPanel, SWT.BORDER | SWT.V_SCROLL);
    gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable.setHeaderVisible(true);
    gridTable.setAutoHeight(true);
    gridTable.setRowsResizeable(true);
    gridTable.setData("selectedBgColor", selectedBgColor);
    final GridColumn idItem = new GridColumn(gridTable, SWT.NONE);
    idItem.setText(Messages.getString("view.TerminologyViewPart.idItem"));
    idColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    idColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
    idItem.setCellRenderer(idColumnCellRenderer);
    idItem.setWordWrap(true);
    srcTableColumn = new GridColumn(gridTable, SWT.NONE);
    srcTableColumn.setText(Messages.getString("view.TerminologyViewPart.srcTableColumn"));
    srcColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    srcTableColumn.setCellRenderer(srcColumnCellRenderer);
    srcTableColumn.setWordWrap(true);
    tgtTableColumn = new GridColumn(gridTable, SWT.NONE);
    tgtTableColumn.setText(Messages.getString("view.TerminologyViewPart.tgtTableColumn"));
    tgtColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    tgtTableColumn.setCellRenderer(tgtColumnCellRenderer);
    tgtTableColumn.setWordWrap(true);
    final GridColumn propertyColumn = new GridColumn(gridTable, SWT.NONE);
    propertyColumn.setText(Messages.getString("view.TerminologyViewPart.propertyColumn"));
    propColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    propertyColumn.setCellRenderer(propColumnCellRenderer);
    propertyColumn.setWordWrap(true);
    copyEnable = new GridCopyEnable(gridTable);
    srcColumnCellRenderer.setCopyEnable(copyEnable);
    tgtColumnCellRenderer.setCopyEnable(copyEnable);
    // 设置列宽按比例
    contentPanel.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle area = contentPanel.getClientArea();
            Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // - 2 * gridTable.getBorderWidth();
            int width = area.width;
            if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
                Point vBarSize = gridTable.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            gridTable.setSize(area.width, area.height);
            width -= 45;
            idItem.setWidth(45);
            srcTableColumn.setWidth((int) (width * 0.4));
            tgtTableColumn.setWidth((int) (width * 0.4));
            propertyColumn.setWidth((int) (width * 0.2));
        }
    });
    Composite statusComposite = new Composite(contentPanel, SWT.NONE);
    GridLayout statusComptGridLayout = new GridLayout(2, false);
    statusComptGridLayout.marginBottom = -1;
    statusComptGridLayout.marginLeft = -1;
    statusComptGridLayout.marginRight = -1;
    statusComptGridLayout.marginTop = -1;
    statusComptGridLayout.marginWidth = 0;
    statusComptGridLayout.marginHeight = 0;
    statusComposite.setLayout(statusComptGridLayout);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tipLabel = new CLabel(statusComposite, SWT.NONE);
    tipLabel.setAlignment(SWT.LEFT);
    CLabel label = new CLabel(statusComposite, SWT.None);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd.heightHint = 20;
    label.setLayoutData(gd);
    gridTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectItem();
        }
    });
    gridTable.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            firstAction.run();
        }
    });
    initHookMenu();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ISelectionListener(org.eclipse.ui.ISelectionListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Grid(org.eclipse.nebula.widgets.grid.Grid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GridCopyEnable(net.heartsome.cat.ts.ui.grid.GridCopyEnable) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 33 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project archi by archimatetool.

the class RelationshipsMatrixDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    setTitle(Messages.RelationshipsMatrixDialog_0);
    setMessage(Messages.RelationshipsMatrixDialog_1);
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite client = new Composite(composite, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    client.setLayout(layout);
    client.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridData gd;
    GridTableViewer viewer = new GridTableViewer(client);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 800;
    gd.heightHint = 500;
    viewer.getControl().setLayoutData(gd);
    viewer.getGrid().setHeaderVisible(true);
    viewer.getGrid().setRowHeaderVisible(true);
    viewer.getGrid().setRowsResizeable(true);
    viewer.getGrid().setCellSelectionEnabled(true);
    // viewer.setColumnProperties(new String[] {"1", "2", "3"});
    viewer.setRowHeaderLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(ArchiLabelProvider.INSTANCE.getDefaultName((EClass) cell.getElement()));
            cell.setImage(ArchiLabelProvider.INSTANCE.getImage(cell.getElement()));
        }
    });
    for (EClass eClass : getData()) {
        GridColumn column = new GridColumn(viewer.getGrid(), SWT.NONE);
        column.setWidth(70);
        column.setImage(ArchiLabelProvider.INSTANCE.getImage(eClass));
        column.setHeaderTooltip(ArchiLabelProvider.INSTANCE.getDefaultName(eClass));
    }
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getData().toArray();
        }
    });
    viewer.setLabelProvider(new MyLabelProvider());
    // hookContextMenu(viewer);
    viewer.setInput(getData());
    // $NON-NLS-1$
    String text = "";
    for (Entry<EClass, Character> entry : RelationshipsMatrix.INSTANCE.getRelationshipsValueMap().entrySet()) {
        // $NON-NLS-1$ //$NON-NLS-2$
        text += entry.getValue() + ": " + ArchiLabelProvider.INSTANCE.getDefaultName(entry.getKey()) + "\n";
    }
    Label label = new Label(client, SWT.NULL);
    label.setText(text);
    label.setLayoutData(new GridData(SWT.TOP, SWT.TOP, false, true));
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) GridTableViewer(org.eclipse.nebula.jface.gridviewer.GridTableViewer) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) GridTableViewer(org.eclipse.nebula.jface.gridviewer.GridTableViewer) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) EClass(org.eclipse.emf.ecore.EClass) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 34 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.

the class AbstractIndicatorSelectGrid method handleCellHighlight.

// private boolean handleMouseScroll(MouseEvent e) {
// if (e.x > getRowHeaderWidth() && e.x < getRowHeaderWidth() + 150) {
// ScrollBar hScrollBar = getHorizontalBar();
// if (hScrollBar.getSelection() == hScrollBar.getMinimum()) {
// return false;
// }
// if (!isScrolling && e.x < getRowHeaderWidth() + 100) {
// isScrolling = true;
// thread = new HoverScrollThread(-1, hScrollBar);
// Display.getDefault().timerExec(200, thread);
// handleCellHighlight(e, getVisibleRange());
// }
// if (isScrolling) {
// thread.setAccelaration(getRowHeaderWidth() + 150 - e.x);
// startColumnIndex = -1;
// endColumnIndex = -1;
// return true;
// }
// } else if (e.x > getBounds().width - 150 && e.x < getBounds().width) {
// ScrollBar hScrollBar = getHorizontalBar();
// if (!isScrolling && e.x > getBounds().width - 100) {
// isScrolling = true;
// thread = new HoverScrollThread(1, hScrollBar);
// Display.getDefault().timerExec(200, thread);
// handleCellHighlight(e, getVisibleRange());
// }
// if (isScrolling) {
// thread.setAccelaration(e.x + 150 - getBounds().width);
// startColumnIndex = -1;
// endColumnIndex = -1;
// return true;
// }
// } else {
// if (isScrolling) {
// isScrolling = false;
// Display.getDefault().timerExec(-1, thread); // interrupt the thread
// }
// }
// return false;
// }
private boolean handleCellHighlight(MouseEvent e, GridVisibleRange range) {
    Point cell = getCell(new Point(e.x, e.y));
    if (cell != null) {
        // any cell except the row select cells
        List<GridColumn> columnList = Arrays.asList(range.getColumns());
        // replace cell.x with the current position in case the column has been moved.
        cell.x = columnList.indexOf(getColumn(cell.x)) + 2;
        for (GridItem item : range.getItems()) {
            int i = indexOf(item);
            // set background for row headers
            if (i == cell.y) {
                item.setBackground(0, highlightBlue);
                item.setBackground(1, highlightBlue);
            } else {
                item.setBackground(0, gray);
                item.setBackground(1, getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                if (item.getCheckable(1)) {
                    item.setBackground(highlightBlue);
                }
            }
            // set background for cells
            for (GridColumn column : range.getColumns()) {
                // real index in current visible range.
                int realIdx = columnList.indexOf(column) + 2;
                // the original index to be colored.
                int j = indexOf(column);
                if (i == cell.y && realIdx == cell.x) {
                    item.setBackground(j, highlightBlue);
                } else if (i == cell.y && realIdx < cell.x || realIdx == cell.x && i < cell.y) {
                    item.setBackground(j, highlightBlue);
                } else {
                    item.setBackground(j, null);
                }
            }
        }
        // set background for column headers
        for (GridColumn column : range.getColumns()) {
            // real index in current visible range.
            int realIdx = columnList.indexOf(column) + 2;
            column.getHeaderRenderer().setSelected(realIdx == cell.x);
        }
        return true;
    }
    return false;
}
Also used : TalendGridItem(org.eclipse.nebula.widgets.grid.TalendGridItem) GridItem(org.eclipse.nebula.widgets.grid.GridItem) TalendGridColumn(org.eclipse.nebula.widgets.grid.TalendGridColumn) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 35 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.

the class AbstractIndicatorSelectGrid method createRowSelectColumn.

/**
 * This column just used to take in space so that visible is false
 */
protected void createRowSelectColumn() {
    GridColumn rowSelectCol = new TalendGridColumn(this, SWT.CHECK);
    rowSelectCol.setHeaderRenderer(getColumnHeaderRenderer());
    rowSelectCol.setCellRenderer(getCellRenderer());
    // $NON-NLS-1$
    rowSelectCol.setText("Select All");
    rowSelectCol.setWidth(COLUMN_WIDTH);
    rowSelectCol.setWordWrap(true);
    rowSelectCol.setCellSelectionEnabled(true);
    // hide the row select column, it is also visible in the fixed column.
    rowSelectCol.setVisible(false);
}
Also used : TalendGridColumn(org.eclipse.nebula.widgets.grid.TalendGridColumn) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) TalendGridColumn(org.eclipse.nebula.widgets.grid.TalendGridColumn)

Aggregations

GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)45 Point (org.eclipse.swt.graphics.Point)38 GridItem (org.eclipse.nebula.widgets.grid.GridItem)16 Rectangle (org.eclipse.swt.graphics.Rectangle)14 TalendGridColumn (org.eclipse.nebula.widgets.grid.TalendGridColumn)7 GC (org.eclipse.swt.graphics.GC)7 TalendGridItem (org.eclipse.nebula.widgets.grid.TalendGridItem)6 GridData (org.eclipse.swt.layout.GridData)6 Color (org.eclipse.swt.graphics.Color)5 Image (org.eclipse.swt.graphics.Image)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Grid (org.eclipse.nebula.widgets.grid.Grid)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 TextLayout (org.eclipse.swt.graphics.TextLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4 GridCellRenderer (org.eclipse.nebula.widgets.grid.GridCellRenderer)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3