Search in sources :

Example 1 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdi-studio-se by Talend.

the class MultiSchemasUI method createHeaderSashForm.

private void createHeaderSashForm(Composite headerComposite) {
    GridLayout layout;
    headerSashForm = new SashForm(headerComposite, SWT.NONE);
    headerSashForm.setLayout(new FillLayout());
    headerSashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
    headerSashForm.setSashWidth(ExternalMultiSchemasUIProperties.SASHFORM_WIDTH);
    //
    multiSchemasFilePreview = new MultiSchemasShadowProcessPreview(this, headerSashForm);
    multiSchemasFilePreview.newTablePreview();
    Composite struComp = new Composite(headerSashForm, SWT.NONE);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    struComp.setLayout(layout);
    headerSashForm.setWeights(ExternalMultiSchemasUIProperties.getHeaderSashformWeights());
    //
    fetchBtn = new Button(struComp, SWT.PUSH);
    fetchBtn.setText(ExternalMultiSchemasUIProperties.FETCH_LABEL);
    fetchBtn.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    //
    schemaTreeViewer = new TreeViewer(struComp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Tree tree = schemaTreeViewer.getTree();
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    schemaTreeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    // SchemasTreeDnD dnd = new SchemasTreeDnD(schemaTreeViewer);
    // dnd.addDragAndDrop();
    schemaTreeViewer.setContentProvider(new SchemasTreeContentProvider());
    schemaTreeViewer.setLabelProvider(new SchemasTreeLabelProvider());
    // schemaTreeViewer.setSorter(new ViewerSorter() {
    //
    // @SuppressWarnings("unchecked")
    // @Override
    // public int compare(Viewer viewer, Object e1, Object e2) {
    // if (e1 instanceof SchemasKeyData && e2 instanceof SchemasKeyData) {
    // return getComparator().compare(((SchemasKeyData) e1).getKeyName(), ((SchemasKeyData) e2).getKeyName());
    // }
    // return super.compare(viewer, e1, e2);
    // }
    //
    // });
    TreeColumn column = new TreeColumn(tree, SWT.LEFT);
    column.setWidth(55);
    //$NON-NLS-1$
    column.setText("Schema");
    column.setResizable(true);
    column = new TreeColumn(tree, SWT.LEFT);
    column.setWidth(100);
    //$NON-NLS-1$
    column.setText("Record");
    column.setResizable(true);
    column = new TreeColumn(tree, SWT.LEFT);
    column.setWidth(20);
    //$NON-NLS-1$
    column.setText("Separator");
    column.setResizable(true);
    schemaTreeViewer.setColumnProperties(new String[] { ExternalMultiSchemasUIProperties.COLUMN_KEY, ExternalMultiSchemasUIProperties.COLUMN_RECORD, ExternalMultiSchemasUIProperties.COLUMN_SEPARATOR });
    // hywang for 10263
    int columnCount = schemaTreeViewer.getTree().getColumnCount();
    CellEditor[] editors = new CellEditor[columnCount];
    for (int i = 0; i < columnCount; i++) {
        editors[i] = new TextCellEditor(schemaTreeViewer.getTree());
    }
    schemaTreeViewer.setCellEditors(editors);
    schemaTreeViewer.setCellModifier(new ICellModifier() {

        public void modify(Object element, String property, Object value) {
            if (element != null) {
                if (element instanceof TreeItem) {
                    TreeItem item = (TreeItem) element;
                    if (item.getData() != null) {
                        if (item.getData() instanceof SchemasKeyData) {
                            SchemasKeyData key = (SchemasKeyData) item.getData();
                            if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_KEY)) {
                                final boolean flag = checkKeyValue(key.getUniqueRecord(), value.toString());
                                if (flag) {
                                    key.setUniqueRecord(value.toString());
                                }
                            }
                            if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_RECORD)) {
                                key.setRecordType(value.toString());
                            }
                            if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_SEPARATOR)) {
                                key.setSeparator(value.toString());
                            }
                        // Object input = schemaTreeViewer.getInput();
                        // SchemasKeyData in = (SchemasKeyData) input;
                        // if (in.getChildren().contains(key)) {
                        // in.getChildren().remove(in.getChildren().indexOf(key));
                        // List<MultiMetadataColumn> colums = multiSchemaManager.createPropertiesColumns(key);
                        // key.setMetadataColumns(colums);
                        // in.getChildren().add(key);
                        // }
                        }
                        schemaTreeViewer.refresh();
                    }
                }
            }
        }

        public Object getValue(Object element, String property) {
            String record = "";
            if (element != null) {
                if (element instanceof SchemasKeyData) {
                    SchemasKeyData key = (SchemasKeyData) element;
                    if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_KEY)) {
                        record = key.getUniqueRecord();
                    }
                    if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_RECORD)) {
                        record = key.getRecordType();
                    }
                    if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_SEPARATOR)) {
                        record = key.getSeparator();
                    }
                }
            }
            return record;
        }

        public boolean canModify(Object element, String property) {
            return true;
        }
    });
    Composite operateTreeComposite = new Composite(struComp, SWT.NONE);
    operateTreeComposite.setLayout(new GridLayout(3, false));
    operateTreeComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    addRow = new Button(operateTreeComposite, SWT.NONE);
    addRow.setText("Add");
    removeRow = new Button(operateTreeComposite, SWT.NONE);
    removeRow.setText("Remove");
    removeRow.setEnabled(false);
    editSchema = new Button(operateTreeComposite, SWT.NONE);
    editSchema.setText("Edit Columns");
    editSchema.setEnabled(false);
    Composite operation = new Composite(struComp, SWT.NONE);
    operation.setLayout(new GridLayout(2, false));
    operation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    leftBtn = new Button(operation, SWT.PUSH);
    leftBtn.setToolTipText("Left");
    leftBtn.setImage(ImageProvider.getImage(EImage.LEFT_ICON));
    leftBtn.setEnabled(false);
    rightBtn = new Button(operation, SWT.PUSH);
    rightBtn.setToolTipText("Right");
    rightBtn.setImage(ImageProvider.getImage(EImage.RIGHT_ICON));
    rightBtn.setEnabled(false);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) TreeItem(org.eclipse.swt.widgets.TreeItem) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) FillLayout(org.eclipse.swt.layout.FillLayout) SchemasTreeLabelProvider(org.talend.designer.filemultischemas.ui.provider.SchemasTreeLabelProvider) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SchemasTreeContentProvider(org.talend.designer.filemultischemas.ui.provider.SchemasTreeContentProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Tree(org.eclipse.swt.widgets.Tree) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) MultiSchemasShadowProcessPreview(org.talend.designer.filemultischemas.ui.preview.MultiSchemasShadowProcessPreview) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 2 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdi-studio-se by Talend.

the class AddArrayIndexForParentsDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite createDialogArea = (Composite) super.createDialogArea(parent);
    FillLayout layout = new FillLayout();
    // layout.horizontalSpacing = 1;
    // layout.numColumns = 1;
    GridData data = new GridData(GridData.FILL_BOTH);
    createDialogArea.setLayout(layout);
    createDialogArea.setLayoutData(data);
    table = new TableViewer(createDialogArea, SWT.FULL_SELECTION | SWT.BORDER);
    new TableColumn(table.getTable(), SWT.LEFT).setText(COLUMN_NAME[0]);
    table.getTable().getColumn(0).pack();
    new TableColumn(table.getTable(), SWT.LEFT).setText(COLUMN_NAME[1]);
    table.getTable().getColumn(1).pack();
    table.getTable().setHeaderVisible(true);
    table.getTable().setLinesVisible(true);
    table.setContentProvider(new IndexContentProvider());
    table.setLabelProvider(new IndexLabelProvider());
    table.setInput(arrayIndexList);
    table.setColumnProperties(COLUMN_NAME);
    CellEditor[] editors = new CellEditor[2];
    editors[0] = null;
    editors[1] = new TextCellEditor(table.getTable());
    table.setCellEditors(editors);
    table.setCellModifier(new ICellModifier() {

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

        public Object getValue(Object element, String property) {
            ArrayIndexList index = (ArrayIndexList) element;
            if (property.equals(COLUMN_NAME[1])) {
                if (index.getIndexNum() != null) {
                    return index.getIndexNum();
                } else {
                    return "";
                }
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            if (element instanceof Item)
                element = ((Item) element).getData();
            ArrayIndexList index = (ArrayIndexList) element;
            if (property.equals(COLUMN_NAME[1]))
                index.setIndexNum((String) value);
            table.refresh();
        }
    });
    return createDialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) Item(org.eclipse.swt.widgets.Item) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ArrayIndexList(org.talend.designer.webservice.data.ArrayIndexList) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdi-studio-se by Talend.

the class JSONFileOutputStep2Form method addJSONFileViewer.

private void addJSONFileViewer(final Composite mainComposite, final int width, final int height) {
    final Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
    GridData data = new GridData(GridData.FILL_BOTH);
    Composite composite = new Composite(group, SWT.BORDER);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(data);
    JSONViewer = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    data = new GridData(GridData.FILL_BOTH);
    JSONViewer.getControl().setLayoutData(data);
    JSONViewer.setUseHashlookup(true);
    Tree tree = JSONViewer.getTree();
    if (isReadOnly()) {
        tree.setEnabled(false);
    }
    tree.setLinesVisible(true);
    tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("JSON Tree");
    column1.setWidth(120);
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Related Column");
    column2.setWidth(100);
    TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
    column3.setText("Node Status");
    column3.setWidth(100);
    TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
    column4.setText("Default Value");
    column4.setWidth(100);
    tree.setHeaderVisible(true);
    JSONFileTreeViewerProvider provider = new JSONFileTreeViewerProvider();
    JSONViewer.setLabelProvider(provider);
    JSONViewer.setCellModifier(new ICellModifier() {

        public void modify(Object element, String property, Object value) {
            TreeItem treeItem = (TreeItem) element;
            FOXTreeNode node = (FOXTreeNode) treeItem.getData();
            if (property.equals("C1")) {
                node.setLabel((String) value);
            }
            if (property.equals("C4")) {
                node.setDefaultValue((String) value);
            }
            JSONViewer.refresh(node);
        }

        public Object getValue(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                //$NON-NLS-1$
                return node.getLabel();
            }
            if (property.equals("C4")) {
                //$NON-NLS-1$
                return node.getDefaultValue();
            }
            return null;
        }

        public boolean canModify(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                if (node.getLabel() != null && node.getLabel().length() > 0) {
                    return true;
                }
            }
            if (property.equals("C4")) {
                if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
                    return true;
                }
            }
            return false;
        }
    });
    JSONViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
    CellEditor editor = new TextCellEditor(JSONViewer.getTree());
    editor.addListener(new DialogErrorJSONLabelCellEditor(editor, "C1"));
    CellEditor editorDefault = new TextCellEditor(JSONViewer.getTree());
    editorDefault.addListener(new DialogErrorJSONLabelCellEditor(editorDefault, "C4"));
    JSONViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
    JSONViewer.setContentProvider(provider);
    // JSONViewer.setInput(treeData);
    JSONViewer.expandAll();
    createAction();
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(JSONViewer.getControl());
    JSONViewer.getControl().setMenu(menu);
    JSONViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });
    initToolBar(composite);
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) GridLayout(org.eclipse.swt.layout.GridLayout) JSONFileTreeViewerProvider(org.talend.repository.json.ui.wizards.view.JSONFileTreeViewerProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Tree(org.eclipse.swt.widgets.Tree) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 4 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method createControls.

public void createControls(Composite parent) {
    composite = widgetFactory.createFlatFormComposite(parent);
    adapterFactory = new BusinessItemProviderAdapterFactory();
    tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
    tableViewer.setLabelProvider(new RepositoryFactoryProxyLabelProvider(adapterFactory));
    Table table = tableViewer.getTable();
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final String[] columnProperties = new String[] { Messages.getString("AssignmentPropertySection.Type"), Messages.getString("AssignmentPropertySection.Name"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Messages.getString("AssignmentPropertySection.Comment") };
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column1.setText(columnProperties[0]);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column2.setText(columnProperties[1]);
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnWeightData(1, 150, true));
    column3.setText(columnProperties[2]);
    tableViewer.setColumnProperties(columnProperties);
    final IItemPropertyDescriptor itemPropertyDescriptor = getItemPropertyDescriptor();
    tableViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            return property.equals(columnProperties[2]);
        }

        @Override
        public Object getValue(Object element, String property) {
            return EmfPropertyHelper.getValue(itemPropertyDescriptor, element);
        }

        @Override
        public void modify(Object element, String property, Object value) {
            if (element instanceof TableItem) {
                TableItem tableItem = (TableItem) element;
                itemPropertyDescriptor.setPropertyValue(tableItem.getData(), value);
            }
        }
    });
    CellEditor[] cellEditors = new CellEditor[3];
    cellEditors[2] = new TextCellEditor(table);
    tableViewer.setCellEditors(cellEditors);
    // createKeyListener(table);
    createSelectionListener();
    createPopupMenu();
    createDoubleClickListener();
    handleLayout(parent, table, column1, column2, column3);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Table(org.eclipse.swt.widgets.Table) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) RepositoryFactoryProxyLabelProvider(org.talend.designer.business.diagram.custom.properties.RepositoryFactoryProxyLabelProvider) TableItem(org.eclipse.swt.widgets.TableItem) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) BusinessItemProviderAdapterFactory(org.talend.designer.business.model.business.provider.BusinessItemProviderAdapterFactory) ICellModifier(org.eclipse.jface.viewers.ICellModifier) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IItemPropertyDescriptor(org.eclipse.emf.edit.provider.IItemPropertyDescriptor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 5 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project cubrid-manager by CUBRID.

the class EditUserDialog method createAuthComposite.

/**
	 * Create auth composite
	 * 
	 * @return the composite
	 */
private Composite createAuthComposite() {
    final Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    Label classTableDescLabel = new Label(composite, SWT.NONE);
    classTableDescLabel.setText(Messages.lblUnAuthorizedTable);
    final String[] columnNameArr = new String[] { Messages.tblColClassName, Messages.tblColClassSchematype, Messages.tblColClassOwner, Messages.tblColClassType };
    classTableViewer = CommonUITool.createCommonTableViewer(composite, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    classTableViewer.setInput(classListData);
    classTable = classTableViewer.getTable();
    classTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            setAuthBtnEnableDisable();
        }
    });
    final Composite cmpControl = new Composite(composite, SWT.NONE);
    final GridData gdCmpControl = new GridData(SWT.CENTER, SWT.FILL, false, false);
    cmpControl.setLayoutData(gdCmpControl);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    cmpControl.setLayout(gridLayout);
    grantButton = new Button(cmpControl, SWT.LEFT);
    grantButton.setEnabled(false);
    grantButton.setText(Messages.addClassButtonName);
    grantButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            int[] idx = classTable.getSelectionIndices();
            if (idx.length < 0) {
                return;
            }
            for (int i : idx) {
                String className = classTable.getItem(i).getText(0);
                for (Map<String, String> map : classListData) {
                    if (map.get("0").equals(className)) {
                        classListData.remove(map);
                        break;
                    }
                }
                ClassAuthorizations classAuthorizations = classGrantMap.get(className);
                if (classAuthorizations == null) {
                    classAuthorizations = new ClassAuthorizations();
                    classAuthorizations.setClassName(className);
                    classAuthorizations.setSelectPriv(true);
                }
                authListData.add(getItemAuthMap(classAuthorizations));
            }
            classTableViewer.refresh();
            authTableViewer.refresh();
            if (authTableViewer.getTable().getColumn(0) != null) {
                authTableViewer.getTable().getColumn(0).pack();
            }
            setAuthBtnEnableDisable();
        }
    });
    revokeButton = new Button(cmpControl, SWT.NONE);
    revokeButton.setEnabled(false);
    revokeButton.setText(Messages.deleteClassButtonName);
    revokeButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            int[] idx = authTable.getSelectionIndices();
            if (idx.length < 0) {
                return;
            }
            for (int id : idx) {
                String tableName = authTable.getItem(id).getText(0);
                for (ClassInfo bean : allClassInfoList) {
                    if (tableName.equals(bean.getClassName())) {
                        if (bean.isSystemClass()) {
                            CommonUITool.openErrorBox(parentComp.getShell(), Messages.errRemoveSysClass);
                            return;
                        } else {
                            Map<String, String> map = new HashMap<String, String>();
                            map.put("0", bean.getClassName());
                            map.put("1", bean.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
                            map.put("2", bean.getOwnerName());
                            map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
                            classListData.add(map);
                        }
                    }
                }
                for (Map<String, Object> map : authListData) {
                    String className = (String) map.get("0");
                    if (tableName.equals(className)) {
                        authListData.remove(map);
                        break;
                    }
                }
            }
            authTableViewer.refresh();
            classTableViewer.refresh();
            setAuthBtnEnableDisable();
        }
    });
    Label authTableDescLabel = new Label(composite, SWT.NONE);
    authTableDescLabel.setText(Messages.lblAuthorizedTable);
    final String[] authColumnNameArr = new String[] { Messages.tblColAuthTable, Messages.tblColAuthSelect, Messages.tblColAuthInsert, Messages.tblColAuthUpdate, Messages.tblColAuthDelete, Messages.tblColAuthAlter, Messages.tblColAuthIndex, Messages.tblColAuthExecute, Messages.tblColAuthGrantselect, Messages.tblColAuthGrantinsert, Messages.tblColAuthGrantupdate, Messages.tblColAuthGrantdelete, Messages.tblColAuthGrantalter, Messages.tblColAuthGrantindex, Messages.tblColAuthGrantexecute };
    authTableViewer = createCommonTableViewer(composite, authColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    authTableViewer.setLabelProvider(new AuthTableLabelProvider());
    authTableViewer.setInput(authListData);
    authTable = authTableViewer.getTable();
    CellEditor[] editors = new CellEditor[15];
    editors[0] = null;
    for (int i = 1; i < 15; i++) {
        editors[i] = new CheckboxCellEditor(authTable, SWT.READ_ONLY);
    }
    authTableViewer.setColumnProperties(authColumnNameArr);
    authTableViewer.setCellEditors(editors);
    authTableViewer.setCellModifier(new ICellModifier() {

        @SuppressWarnings("unchecked")
        public boolean canModify(Object element, String property) {
            Map<String, Object> map = (Map<String, Object>) element;
            boolean isDbaAuthority = database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
            if (isDbaAuthority) {
                return true;
            }
            /*Can't grant/revoke for  current login user*/
            if (StringUtil.isEqual(userName, currentUserInfo.getName())) {
                return false;
            }
            String name = (String) map.get("0");
            for (ClassInfo bean : allClassInfoList) {
                if (name.equals(bean.getClassName())) {
                    if (bean.isSystemClass()) {
                        return false;
                    } else if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
                        return true;
                    }
                }
            }
            ClassAuthorizations authorizations = currentUserAuthorizations.get(name);
            if (authorizations == null || authorizations.isAllPriv() || authorizations.isPriv(property)) {
                return true;
            } else {
                return false;
            }
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, Object> map = (Map<String, Object>) element;
            for (int i = 1; i < 15; i++) {
                if (property.equals(authColumnNameArr[i])) {
                    return Boolean.valueOf((Boolean) map.get("" + i));
                }
            }
            return null;
        }

        @SuppressWarnings("unchecked")
        public void modify(Object element, String property, Object value) {
            Object elementData;
            elementData = element;
            if (element instanceof Item) {
                elementData = ((Item) element).getData();
            }
            String key = "";
            Map<String, Object> map = (Map<String, Object>) elementData;
            for (int i = 1; i < 15; i++) {
                if (property.equals(authColumnNameArr[i])) {
                    key = "" + i;
                    break;
                }
            }
            if (value instanceof Boolean) {
                map.put(key, ((Boolean) value).booleanValue());
            }
            authTableViewer.refresh();
        }
    });
    authTable.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
        }

        public void widgetSelected(SelectionEvent event) {
            setAuthBtnEnableDisable();
        }
    });
    authTable.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            setAuthBtnEnableDisable();
        }
    });
    return composite;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) Label(org.eclipse.swt.widgets.Label) FocusEvent(org.eclipse.swt.events.FocusEvent) Item(org.eclipse.swt.widgets.Item) TableItem(org.eclipse.swt.widgets.TableItem) CTabItem(org.eclipse.swt.custom.CTabItem) GridLayout(org.eclipse.swt.layout.GridLayout) TableViewerSorter(com.cubrid.common.ui.spi.TableViewerSorter) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Map(java.util.Map) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ICellModifier (org.eclipse.jface.viewers.ICellModifier)45 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)42 CellEditor (org.eclipse.jface.viewers.CellEditor)30 GridData (org.eclipse.swt.layout.GridData)29 Composite (org.eclipse.swt.widgets.Composite)27 TableItem (org.eclipse.swt.widgets.TableItem)26 GridLayout (org.eclipse.swt.layout.GridLayout)24 TableViewer (org.eclipse.jface.viewers.TableViewer)22 TableColumn (org.eclipse.swt.widgets.TableColumn)21 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 Item (org.eclipse.swt.widgets.Item)16 SelectionListener (org.eclipse.swt.events.SelectionListener)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)10 Button (org.eclipse.swt.widgets.Button)9 Table (org.eclipse.swt.widgets.Table)9 Text (org.eclipse.swt.widgets.Text)9