Search in sources :

Example 16 with Item

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

the class ShardKeysPanel method linkEditorForKeyInfoTable.

/**
	 * Links the editable column of table
	 */
private void linkEditorForKeyInfoTable() {
    keyInfoTableViewer.setColumnProperties(keyInfoColumnNameArrs);
    CellEditor[] editors = new CellEditor[3];
    editors[0] = new TextCellEditor(keyInfoTable);
    editors[1] = new TextCellEditor(keyInfoTable);
    String[] shardIds = new String[shardIdList.size()];
    shardIds = shardIdList.toArray(shardIds);
    shardIdCellEditor = new ComboBoxCellEditor(keyInfoTable, shardIds, SWT.READ_ONLY) {

        {
            if (!shardIdList.isEmpty()) {
                this.doSetValue(shardIdList.get(0));
            }
        }

        protected void doSetValue(Object value) {
            for (int i = 0; i < shardIdList.size(); i++) {
                if (shardIdList.get(i).equals((String) value)) {
                    super.doSetValue(i);
                }
            }
        }

        protected Object doGetValue() {
            int selection = ((Integer) super.doGetValue()).intValue();
            if (selection == -1) {
                return "";
            }
            return shardIdList.get(selection);
        }
    };
    editors[2] = shardIdCellEditor;
    keyInfoTableViewer.setCellEditors(editors);
    keyInfoTableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(keyInfoColumnNameArrs[0])) {
                return map.get("0");
            } else if (property.equals(keyInfoColumnNameArrs[1])) {
                return map.get("1");
            } else if (property.equals(keyInfoColumnNameArrs[2])) {
                return map.get("2");
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) obj;
            boolean isValid = true;
            if (!StringUtil.isEmpty(value.toString())) {
                if (isValid && !ValidateUtil.isInteger(value.toString())) {
                    isValid = false;
                    CommonUITool.openErrorBox(Messages.errShardKeyParameterNotNumeric);
                }
                if (isValid) {
                    if (property.equals(keyInfoColumnNameArrs[0])) {
                        map.put("0", value.toString());
                    } else if (property.equals(keyInfoColumnNameArrs[1])) {
                        map.put("1", value.toString());
                    } else if (property.equals(keyInfoColumnNameArrs[2])) {
                        map.put("2", value.toString());
                    }
                }
            }
            keyInfoTableViewer.refresh();
            saveShardKey();
            // Notice the upper layer
            modifyListener.modifyText(null);
        }
    });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ToolItem(org.eclipse.swt.widgets.ToolItem) Item(org.eclipse.swt.widgets.Item) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with Item

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

the class RenameDatabaseDialog method createNewDatabaseInfoComp.

/**
	 * 
	 * Create database name group
	 * 
	 * @param parent the parent composite
	 */
private void createNewDatabaseInfoComp(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    comp.setLayoutData(gridData);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    comp.setLayout(layout);
    Label databaseNameLabel = new Label(comp, SWT.LEFT | SWT.WRAP);
    databaseNameLabel.setText(Messages.lblNewDbName);
    gridData = new GridData();
    gridData.widthHint = 150;
    databaseNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    databaseNameText = new Text(comp, SWT.BORDER);
    databaseNameText.setTextLimit(ValidateUtil.MAX_DB_NAME_LENGTH);
    databaseNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    exVolumePathButton = new Button(comp, SWT.LEFT | SWT.RADIO);
    exVolumePathButton.setText(Messages.btnExtendedVolumePath);
    exVolumePathButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    exVolumePathButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (exVolumePathButton.getSelection()) {
                exVolumePathText.setEditable(true);
                renameVolumeButton.setSelection(false);
                volumeTable.setEnabled(false);
                if (selectVolumeDirectoryButton != null) {
                    ServerInfo serverInfo = database.getServer().getServerInfo();
                    selectVolumeDirectoryButton.setEnabled(serverInfo != null && serverInfo.isLocalServer());
                }
            } else {
                exVolumePathText.setEditable(false);
                volumeTable.setEnabled(true);
                if (selectVolumeDirectoryButton != null) {
                    selectVolumeDirectoryButton.setEnabled(false);
                }
            }
        }
    });
    exVolumePathButton.setSelection(true);
    boolean isLocalServer = database.getServer().getServerInfo().isLocalServer();
    exVolumePathText = new Text(comp, SWT.BORDER);
    exVolumePathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, isLocalServer ? 1 : 2, 1, -1, -1));
    if (isLocalServer) {
        selectVolumeDirectoryButton = new Button(comp, SWT.NONE);
        selectVolumeDirectoryButton.setText(Messages.btnBrowse);
        selectVolumeDirectoryButton.setLayoutData(CommonUITool.createGridData(1, 1, 80, -1));
        selectVolumeDirectoryButton.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                String text = exVolumePathText.getText();
                if (text == null || text.trim().length() == 0) {
                    text = CubridManagerUIPlugin.getPluginDialogSettings().get(KEY_EXTENDED_VOLUME_PATH + database.getId());
                }
                if (text == null || text.trim().length() == 0) {
                    text = extVolumePath;
                }
                DirectoryDialog dlg = new DirectoryDialog(getShell());
                if (text != null) {
                    dlg.setFilterPath(text);
                }
                dlg.setText(Messages.msgSelectDir);
                dlg.setMessage(Messages.msgSelectDir);
                String dir = dlg.open();
                if (dir != null) {
                    exVolumePathText.setText(dir);
                    CubridManagerUIPlugin.getPluginDialogSettings().put(KEY_EXTENDED_VOLUME_PATH + database.getId(), dir);
                }
            }
        });
        selectVolumeDirectoryButton.setEnabled(true);
    }
    renameVolumeButton = new Button(comp, SWT.LEFT | SWT.RADIO);
    renameVolumeButton.setText(Messages.btnRenameIndiVolume);
    renameVolumeButton.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    renameVolumeButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (renameVolumeButton.getSelection()) {
                volumeTable.setEnabled(true);
            } else {
                volumeTable.setEnabled(false);
            }
        }
    });
    final String[] columnNameArr = new String[] { Messages.tblColumnCurrVolName, Messages.tblColumnNewVolName, Messages.tblColumnCurrDirPath, Messages.tblColumnNewDirPath };
    volumeTableViewer = CommonUITool.createCommonTableViewer(comp, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    volumeTable = volumeTableViewer.getTable();
    volumeTable.setEnabled(false);
    volumeTableViewer.setColumnProperties(columnNameArr);
    CellEditor[] editors = new CellEditor[4];
    editors[0] = null;
    editors[1] = new TextCellEditor(volumeTable);
    editors[2] = null;
    editors[3] = new TextCellEditor(volumeTable);
    volumeTableViewer.setCellEditors(editors);
    volumeTableViewer.setCellModifier(new ICellModifier() {

        @SuppressWarnings("unchecked")
        public boolean canModify(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            String name = map.get("0");
            if (property.equals(columnNameArr[0]) || property.equals(columnNameArr[2])) {
                return false;
            } else if (property.equals(columnNameArr[1]) && name.equals(database.getName())) {
                return false;
            }
            return true;
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(columnNameArr[1])) {
                return map.get("1");
            } else if (property.equals(columnNameArr[3])) {
                return map.get("3");
            }
            return null;
        }

        @SuppressWarnings("unchecked")
        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            Map<String, String> map = (Map<String, String>) obj;
            if (property.equals(columnNameArr[1])) {
                map.put("1", value.toString());
            } else if (property.equals(columnNameArr[3])) {
                map.put("3", value.toString());
            }
            volumeTableViewer.refresh();
        }
    });
    forceDelBackupVolumeButton = new Button(comp, SWT.LEFT | SWT.CHECK);
    forceDelBackupVolumeButton.setText(Messages.btnForceDelBackupVolume);
    forceDelBackupVolumeButton.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Item(org.eclipse.swt.widgets.Item) GridLayout(org.eclipse.swt.layout.GridLayout) TableViewerSorter(com.cubrid.common.ui.spi.TableViewerSorter) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Map(java.util.Map) HashMap(java.util.HashMap) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 18 with Item

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

the class SetReplicationParamComp method linkEditorForTable.

/**
	 * check & update table content of being edited
	 * 
	 */
private void linkEditorForTable() {
    replicationParamTableViewer.setColumnProperties(columnNameArrs);
    CellEditor[] editors = new CellEditor[3];
    editors[0] = null;
    editors[1] = null;
    editors[2] = new TextCellEditor(replicationParamTable);
    replicationParamTableViewer.setCellEditors(editors);
    replicationParamTableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            if (property.equals(columnNameArrs[2])) {
                return true;
            }
            return false;
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(columnNameArrs[2])) {
                return map.get("2");
            }
            return null;
        }

        @SuppressWarnings("unchecked")
        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            Map<String, String> map = (Map<String, String>) obj;
            String parameter = map.get("0");
            String type = map.get("1");
            String paraValue = map.get("2");
            boolean isValid = true;
            String errorMsg = null;
            if (type.startsWith("bool")) {
                if (!value.toString().equalsIgnoreCase("Y") && !value.toString().equalsIgnoreCase("N")) {
                    isValid = false;
                    errorMsg = Messages.bind(Messages.repparm0errYesNoParameter, new String[] { parameter });
                }
            } else if (type.startsWith("int")) {
                String paraVal = value.toString();
                if (paraVal.length() > 8 || !paraVal.matches("\\d+")) {
                    isValid = false;
                }
                if (isValid) {
                    int intValue = Integer.parseInt(paraVal);
                    if (parameter.equals(ReplicationParamConstants.PERF_POLL_INTERVAL)) {
                        if (intValue < 10 || intValue > 60) {
                            isValid = false;
                            errorMsg = Messages.bind(Messages.repparm0errPerfPollInterval, new String[] { parameter });
                        }
                    } else if (parameter.equals(ReplicationParamConstants.SIZE_OF_LOG_BUFFER)) {
                        if (intValue < 100 || intValue > 1000) {
                            isValid = false;
                            errorMsg = Messages.bind(Messages.repparm0errSizeOfLogBuffer, new String[] { parameter });
                        }
                    } else if (parameter.equals(ReplicationParamConstants.SIZE_OF_CACHE_BUFFER)) {
                        if (intValue < 100 || intValue > 500) {
                            isValid = false;
                            errorMsg = Messages.bind(Messages.repparm0errSizeOfCacheBuffer, new String[] { parameter });
                        }
                    } else if (parameter.equals(ReplicationParamConstants.SIZE_OF_COPYLOG)) {
                        if (intValue < 1000 || intValue > 10000) {
                            isValid = false;
                            errorMsg = Messages.bind(Messages.repparm0errSizeOfCopylog, new String[] { parameter });
                        }
                    } else if (parameter.equals(ReplicationParamConstants.LOG_APPLY_INTERVAL)) {
                        if (intValue < 0 || intValue > 600) {
                            isValid = false;
                            errorMsg = Messages.bind(Messages.repparm0errLogApplyInterval, new String[] { parameter });
                        }
                    } else if (parameter.equals(ReplicationParamConstants.RESTART_INTERVAL) && (intValue < 1 || intValue > 60)) {
                        isValid = false;
                        errorMsg = Messages.bind(Messages.repparm0errRestartInterval, new String[] { parameter });
                    }
                } else {
                    errorMsg = Messages.bind(Messages.repparm0errOnlyInteger, new String[] { parameter });
                    isValid = false;
                }
            }
            if (!isValid && errorMsg != null) {
                setErrorMsg(errorMsg);
                updatableComp.updateUI();
            }
            setErrorMsg(null);
            if (isValid && property.equals(columnNameArrs[2]) && !paraValue.equals(value)) {
                map.put("2", value.toString());
                updatableComp.updateUI();
            }
            replicationParamTableViewer.refresh();
            for (int i = 0; i < replicationParamTable.getColumnCount(); i++) {
                replicationParamTable.getColumn(i).pack();
            }
        }
    });
}
Also used : Item(org.eclipse.swt.widgets.Item) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with Item

use of org.eclipse.swt.widgets.Item in project tdi-studio-se by Talend.

the class Schema2XMLLinker method addLink.

/**
     * amaumont Comment method "addLink".
     * 
     * @param tableItem
     * @param dataItem1
     * @param tree
     * @param dataItem2
     */
private LinkDescriptor<Item, Object, Tree, Object> addLink(Item tableItem, Object dataItem1, Tree tree, Object dataItem2) {
    LinkDescriptor<Item, Object, Tree, Object> link = new LinkDescriptor<Item, Object, Tree, Object>(new ItemExtremityDescriptor(tableItem, dataItem1), new ExtremityLink<Tree, Object>(tree, dataItem2));
    link.setStyleLink(getUnselectedStyleLink());
    getLinksManager().addLink(link);
    updateLinksStyleAndControlsSelection(tree);
    return link;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) Item(org.eclipse.swt.widgets.Item) ItemExtremityDescriptor(org.talend.commons.ui.swt.drawing.link.ItemExtremityDescriptor) Tree(org.eclipse.swt.widgets.Tree) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Example 20 with Item

use of org.eclipse.swt.widgets.Item in project tdi-studio-se by Talend.

the class SchemaXMLLinker method updateLinksStyleAndControlsSelection.

@SuppressWarnings("unchecked")
public void updateLinksStyleAndControlsSelection(Control currentControl, boolean lastOne) {
    // super.updateLinksStyleAndControlsSelection(currentControl);
    boolean isTarget = false;
    if (getSource() != currentControl) {
        isTarget = true;
    } else {
        isTarget = false;
    }
    HashSet selectedItems = new HashSet();
    Map itemsToSelect = new HashMap();
    if (isTarget) {
        getTarget().deselectAll();
        TreeItem[] selection = getTarget().getSelection();
        for (TreeItem tableItem : selection) {
            selectedItems.add(tableItem.getData());
        }
    } else {
        TableItem[] selection = getSource().getSelection();
        for (TableItem treeItem : selection) {
            selectedItems.add(treeItem.getData());
        }
    }
    List<LinkDescriptor<Item, Object, Tree, Object>> links = linksManager.getLinks();
    for (LinkDescriptor<Item, Object, Tree, Object> link : links) {
        IStyleLink styleLink = null;
        IExtremityLink extremity = null;
        IExtremityLink otherExtremity = null;
        if (isTarget) {
            extremity = link.getExtremity2();
            otherExtremity = link.getExtremity1();
        } else {
            extremity = link.getExtremity1();
            otherExtremity = link.getExtremity2();
        }
        boolean currentItemIsSelected = selectedItems.contains(extremity.getDataItem());
        if (extremity.getGraphicalObject() == xmlViewer.getTree() || otherExtremity.getGraphicalObject() == xmlViewer.getTree()) {
            styleLink = getSelectedLoopStyleLink();
        } else {
            if (currentItemIsSelected) {
                styleLink = getSelectedStyleLink();
                if (isTarget) {
                    itemsToSelect.put(otherExtremity.getGraphicalObject(), null);
                } else {
                    Table currentTable = (Table) otherExtremity.getGraphicalObject();
                    List<TableItem> tableItemsToSelect = (List<TableItem>) itemsToSelect.get(currentTable);
                    if (tableItemsToSelect == null) {
                        tableItemsToSelect = new ArrayList<TableItem>();
                        itemsToSelect.put(currentTable, tableItemsToSelect);
                    }
                    TableItem tableItem = TableUtils.getTableItem(currentTable, otherExtremity.getDataItem());
                    tableItemsToSelect.add(tableItem);
                }
            } else {
                styleLink = getUnselectedStyleLink();
            }
        }
        if (styleLink == null) {
            styleLink = getDefaultStyleLink();
        }
        link.setStyleLink(styleLink);
    }
    if (isTarget) {
        (getSource()).setSelection((TableItem[]) itemsToSelect.keySet().toArray(new TableItem[0]));
    } else {
        Set<Table> set = itemsToSelect.keySet();
        if (set.size() > 0) {
            for (Table table : set) {
                ArrayList<TableItem> tableItemsToSelect = (ArrayList<TableItem>) itemsToSelect.get(table);
                table.deselectAll();
                TableItem[] tableItems = tableItemsToSelect.toArray(new TableItem[0]);
                table.setSelection(tableItems);
            }
        } else {
            xmlViewer.getTree().deselectAll();
        }
    }
    getLinksManager().sortLinks(getDrawingLinksComparator());
    // for bug 9279
    if (lastOne) {
        getBackgroundRefresher().refreshBackground();
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) HashMap(java.util.HashMap) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) Item(org.eclipse.swt.widgets.Item) IExtremityLink(org.talend.commons.ui.swt.drawing.link.IExtremityLink) IStyleLink(org.talend.commons.ui.swt.drawing.link.IStyleLink) Tree(org.eclipse.swt.widgets.Tree) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor) HashSet(java.util.HashSet)

Aggregations

Item (org.eclipse.swt.widgets.Item)23 HashMap (java.util.HashMap)15 Map (java.util.Map)14 TableItem (org.eclipse.swt.widgets.TableItem)14 ICellModifier (org.eclipse.jface.viewers.ICellModifier)13 CellEditor (org.eclipse.jface.viewers.CellEditor)12 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)11 Tree (org.eclipse.swt.widgets.Tree)7 TreeItem (org.eclipse.swt.widgets.TreeItem)7 LinkDescriptor (org.talend.commons.ui.swt.drawing.link.LinkDescriptor)7 GridData (org.eclipse.swt.layout.GridData)6 ArrayList (java.util.ArrayList)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 ToolItem (org.eclipse.swt.widgets.ToolItem)5 List (java.util.List)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 Composite (org.eclipse.swt.widgets.Composite)4 HashSet (java.util.HashSet)3 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)3 GridLayout (org.eclipse.swt.layout.GridLayout)3