Search in sources :

Example 91 with TableItem

use of org.eclipse.swt.widgets.TableItem in project cubrid-manager by CUBRID.

the class ViewDashboardEditorPart method dropView.

public void dropView() {
    TableItem[] items = viewsDetailInfoTable.getTable().getSelection();
    if (items.length > 0) {
        List<ISchemaNode> selectNodeList = new ArrayList<ISchemaNode>();
        for (TableItem item : items) {
            ViewDetailInfo viewInfo = (ViewDetailInfo) item.getData();
            Set<String> typeSet = new HashSet<String>();
            typeSet.add(NodeType.USER_VIEW);
            ICubridNode viewNode = CommonUITool.findNode(database, typeSet, viewInfo.getViewName());
            selectNodeList.add((ISchemaNode) viewNode);
        }
        if (selectNodeList.size() > 0) {
            DropViewAction action = (DropViewAction) ActionManager.getInstance().getAction(DropViewAction.ID);
            ISchemaNode[] nodeArr = new ISchemaNode[selectNodeList.size()];
            action.run(selectNodeList.toArray(nodeArr));
            if (!action.isCanceledTask()) {
                refresh();
            }
        }
    } else {
        CommonUITool.openWarningBox(Messages.viewDetailInfoPartTableNoSelectionMsg);
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ViewDetailInfo(com.cubrid.common.core.common.model.ViewDetailInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) HashSet(java.util.HashSet) DropViewAction(com.cubrid.common.ui.cubrid.table.action.DropViewAction)

Example 92 with TableItem

use of org.eclipse.swt.widgets.TableItem in project cubrid-manager by CUBRID.

the class QueryExecuter method handleButtonEvent.

/**
	 * Open detail dialog
	 *
	 * @param event MouseEvent
	 */
@SuppressWarnings("unchecked")
public void handleButtonEvent(int rowIndex, int columnIndex) {
    // Get columnInfo
    ColumnInfo columnInfo = (ColumnInfo) tblResult.getColumn(columnIndex).getData();
    // Get data
    final TableItem item = selectableSupport.getTableCursor().getRow();
    Map<String, CellValue> dataMap = (Map<String, CellValue>) item.getData();
    Map<String, CellValue> newValueMap = (Map<String, CellValue>) item.getData(LASTEST_DATA_FLAG);
    if (newValueMap == null) {
        newValueMap = new HashMap<String, CellValue>();
        newValueMap.putAll(dataMap);
        item.setData(LASTEST_DATA_FLAG, newValueMap);
    }
    String dataIndex = String.valueOf(columnIndex);
    CellValue cellValue = newValueMap.get(dataIndex);
    if (cellValue == null) {
        cellValue = new CellValue();
        newValueMap.put(dataIndex, cellValue);
    }
    String charset = getDatabaseInfo() != null ? getDatabaseInfo().getCharSet() : null;
    String dataType = DataType.makeType(columnInfo.getType(), columnInfo.getChildElementType(), columnInfo.getPrecision(), columnInfo.getScale());
    cellValue.setFileCharset(charset);
    CellViewer cellViewer = new CellViewer(columnInfo, editMode, charset);
    if (IDialogConstants.OK_ID == cellViewer.openCellViewer(tblResult.getShell(), cellValue)) {
        CellValue newValue = cellViewer.getValue();
        if (!CellViewer.isCellValueEqual(cellValue, newValue)) {
            String showValue = null;
            if (newValue.getValue() == null) {
                showValue = DataType.NULL_EXPORT_FORMAT;
                item.setText(columnIndex, showValue);
                newValueMap.put(dataIndex, newValue);
                updateValue(item, dataMap, newValueMap);
            } else if (newValue.getValue() instanceof String) {
                String strValue = newValue.getValue().toString();
                FormatDataResult result = DBAttrTypeFormatter.format(dataType, strValue, null, false, charset, false);
                if (result.isSuccess()) {
                    // Update the data
                    showValue = newValue.getShowValue();
                    item.setText(columnIndex, showValue);
                    newValueMap.put(dataIndex, newValue);
                    updateValue(item, dataMap, newValueMap);
                } else {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errTextTypeNotMatch, dataType));
                    return;
                }
            } else if (newValue.getValue() instanceof byte[]) {
                if (DataType.DATATYPE_BIT.equalsIgnoreCase(columnInfo.getType()) || DataType.DATATYPE_BIT_VARYING.equalsIgnoreCase(columnInfo.getType())) {
                    byte[] bValues = (byte[]) newValue.getValue();
                    if (bValues.length * 8 > columnInfo.getPrecision() + 7) {
                        String msg = Messages.bind(Messages.errTextTypeNotMatch, dataType);
                        CommonUITool.openErrorBox(msg);
                        return;
                    }
                }
                showValue = newValue.getShowValue();
                item.setText(columnIndex, showValue);
                newValueMap.put(dataIndex, newValue);
                updateValue(item, dataMap, newValueMap);
            } else {
                showValue = newValue.getShowValue();
                item.setText(columnIndex, showValue);
                newValueMap.put(dataIndex, newValue);
                updateValue(item, dataMap, newValueMap);
            }
            selectableSupport.getTableCursor().redraw();
        }
    }
}
Also used : CellViewer(com.cubrid.common.ui.spi.table.celleditor.CellViewer) FormatDataResult(com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult) TableItem(org.eclipse.swt.widgets.TableItem) CellValue(com.cubrid.common.ui.spi.table.CellValue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 93 with TableItem

use of org.eclipse.swt.widgets.TableItem in project cubrid-manager by CUBRID.

the class GetInfoDataTask method displayDemoDataTableItem.

/**
	 * Display table item by the data in allDataList
	 */
private void displayDemoDataTableItem() {
    for (int i = 0; i < allDataList.size(); i++) {
        TableItem item = new TableItem(demoDataTable, SWT.MULTI);
        Map<String, Object> map = allDataList.get(i);
        makeItemValue(item, map);
        if (i % 2 == 0) {
            item.setBackground(ResourceManager.getColor(230, 230, 230));
        }
        if (doesGetOidInfo) {
            item.setBackground(1, Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
        }
    }
    // Auto set column size, maximum is 300px,minimum is 50px
    CommonUITool.packTable(demoDataTable, 50, 300);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem)

Example 94 with TableItem

use of org.eclipse.swt.widgets.TableItem in project cubrid-manager by CUBRID.

the class BatchRunComposite method createTableGroup.

private void createTableGroup(Composite composite) {
    final String[] columnNames = new String[] { "", com.cubrid.common.ui.query.Messages.msgBatchRunSqlFile, com.cubrid.common.ui.query.Messages.msgBatchRunMemo, com.cubrid.common.ui.query.Messages.msgBatchRunRegdate };
    tv = (CheckboxTableViewer) CommonUITool.createCheckBoxTableViewer(composite, null, columnNames, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    tv.setInput(listData);
    TableLayout tableLayout = new TableLayout();
    tv.getTable().setLayout(tableLayout);
    tableLayout.addColumnData(new ColumnPixelData(30));
    tableLayout.addColumnData(new ColumnPixelData(209));
    tableLayout.addColumnData(new ColumnPixelData(272));
    tableLayout.addColumnData(new ColumnPixelData(118));
    editor = new TableEditor(tv.getTable());
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    tv.getTable().addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            if (event.button != 1) {
                return;
            }
            validateCheck();
            Point pt = new Point(event.x, event.y);
            int newIndex = tv.getTable().getSelectionIndex();
            if (tv.getTable().getItemCount() <= newIndex || newIndex < 0) {
                return;
            }
            final TableItem item = tv.getTable().getItem(newIndex);
            if (item == null) {
                return;
            }
            Rectangle rect = item.getBounds(2);
            if (rect.contains(pt)) {
                focusCell(item, newIndex, 2);
            }
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) TraverseListener(org.eclipse.swt.events.TraverseListener) TableItem(org.eclipse.swt.widgets.TableItem) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Rectangle(org.eclipse.swt.graphics.Rectangle) Event(org.eclipse.swt.widgets.Event) TraverseEvent(org.eclipse.swt.events.TraverseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point) TableLayout(org.eclipse.jface.viewers.TableLayout) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 95 with TableItem

use of org.eclipse.swt.widgets.TableItem in project cubrid-manager by CUBRID.

the class FilterChooserDialog method createComposite.

/**
	 * 
	 * Create the composite
	 * 
	 * @param parent Composite
	 */
private void createComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    composite.setLayout(layout);
    Label infoLabel = new Label(composite, SWT.NONE);
    infoLabel.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    infoLabel.setText(Messages.lblFilterChooser);
    String[] columnNames = new String[] { Messages.colColumn };
    tv = (CheckboxTableViewer) CommonUITool.createCheckBoxTableViewer(composite, null, columnNames, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, 300, 200));
    tv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (!event.getChecked() && selectAllBtn.getSelection()) {
                selectAllBtn.setSelection(false);
            }
            if (colInfoList != null && colInfoList.size() == tv.getCheckedElements().length) {
                selectAllBtn.setSelection(true);
            }
        }
    });
    final List<Map<String, Object>> colNameList = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < colInfoList.size(); i++) {
        ColumnInfo colInfo = colInfoList.get(i);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("0", colInfo.getName());
        map.put("1", colInfo);
        colNameList.add(map);
    }
    tv.setInput(colNameList);
    tv.getTable().setFocus();
    selectAllBtn = new Button(composite, SWT.CHECK);
    {
        selectAllBtn.setText(Messages.btnSelectAll);
        GridData gridData = new GridData();
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalIndent = 0;
        gridData.horizontalSpan = 3;
        selectAllBtn.setLayoutData(gridData);
    }
    selectAllBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            boolean selection = selectAllBtn.getSelection();
            tv.setAllChecked(selection);
        }
    });
    for (TableItem item : tv.getTable().getItems()) {
        @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) item.getData();
        if (map != null && selectedColInfoList.contains(map.get("1"))) {
            item.setChecked(true);
        }
    }
    TableColumn[] tblCols = tv.getTable().getColumns();
    for (TableColumn tblCol : tblCols) {
        tblCol.setWidth(280);
    }
    if (colInfoList != null && selectedColInfoList != null && colInfoList.size() == selectedColInfoList.size()) {
        selectAllBtn.setSelection(true);
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TableItem (org.eclipse.swt.widgets.TableItem)475 Point (org.eclipse.swt.graphics.Point)136 Table (org.eclipse.swt.widgets.Table)125 TableColumn (org.eclipse.swt.widgets.TableColumn)79 SelectionEvent (org.eclipse.swt.events.SelectionEvent)73 GridData (org.eclipse.swt.layout.GridData)70 GridLayout (org.eclipse.swt.layout.GridLayout)61 Composite (org.eclipse.swt.widgets.Composite)56 ArrayList (java.util.ArrayList)55 Image (org.eclipse.swt.graphics.Image)55 Button (org.eclipse.swt.widgets.Button)53 Rectangle (org.eclipse.swt.graphics.Rectangle)52 Label (org.eclipse.swt.widgets.Label)51 Shell (org.eclipse.swt.widgets.Shell)49 Color (org.eclipse.swt.graphics.Color)48 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)43 Text (org.eclipse.swt.widgets.Text)42 FillLayout (org.eclipse.swt.layout.FillLayout)40 Test (org.junit.Test)39 SelectionListener (org.eclipse.swt.events.SelectionListener)36