Search in sources :

Example 1 with CheckStateChangedEvent

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

the class StatLogsAndImplicitcontextTreeViewPage method createStatTree.

private void createStatTree(Composite composite) {
    //$NON-NLS-1$
    Group g = widgetFactory.createGroup(composite, Messages.getString("StatsAndLogsComposite.StatsLogsSettings"));
    GridData gd = new GridData(GridData.FILL_BOTH);
    g.setLayoutData(gd);
    g.setLayout(new FillLayout());
    statViewer = new CheckboxRepositoryTreeViewer(g, SWT.MULTI | SWT.V_SCROLL);
    statContentProvider = new AllJobContentProvider(repositoryView);
    statViewer.setContentProvider(statContentProvider);
    statViewer.setLabelProvider(new RepositoryLabelProvider(repositoryView));
    statViewer.setSorter(repositoryView.getViewer().getSorter());
    IViewSite viewSite = repositoryView.getViewSite();
    statViewer.setInput(viewSite);
    // This only tree listener aim is to change open/close icons on folders :
    statViewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                TreeItem item = getObject(statViewer.getTree(), event.getElement());
                if (item != null) {
                    item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_CLOSE_ICON));
                }
            }
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                TreeItem item = getObject(statViewer.getTree(), event.getElement());
                if (item != null) {
                    item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_OPEN_ICON));
                }
            }
        }
    });
    statViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
            processItems(objects, node);
            if (event.getChecked()) {
                statAddedObjects.addAll(objects);
                statRemovedObjects.removeAll(objects);
                statCheckedObjects.addAll(objects);
            } else {
                statAddedObjects.removeAll(objects);
                statRemovedObjects.addAll(objects);
                statCheckedObjects.removeAll(objects);
            }
            // set checked
            statViewer.setCheckedElements(statCheckedObjects.toArray());
        // viewer.refresh();
        }
    });
    RepositoryNode[] nodes = statContentProvider.getContents();
    List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
    if (nodes != null) {
        for (RepositoryNode n : nodes) {
            processItems(objects, n);
            for (RepositoryNode node : objects) {
                if (isStatUseProjectSetting(node)) {
                    if (!statCheckedObjects.contains(node)) {
                        statCheckedObjects.add(node);
                    }
                }
            }
        }
    }
    statViewer.setCheckedElements(statCheckedObjects.toArray());
    if (nodes != null) {
        statViewer.setExpandedElements(nodes);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) TreeItem(org.eclipse.swt.widgets.TreeItem) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) ArrayList(java.util.ArrayList) FillLayout(org.eclipse.swt.layout.FillLayout) RepositoryLabelProvider(org.talend.core.repository.ui.view.RepositoryLabelProvider) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IViewSite(org.eclipse.ui.IViewSite) CheckboxRepositoryTreeViewer(org.talend.repository.viewer.ui.viewer.CheckboxRepositoryTreeViewer) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ArrayList(java.util.ArrayList) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 2 with CheckStateChangedEvent

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

the class ExportSettingForLoadDBPage method createControl.

/**
	 * Create the page content
	 *
	 * @param parent Composite
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FormLayout());
    Composite leftComposite = new Composite(container, SWT.NONE);
    leftComposite.setLayout(new GridLayout());
    FormData leftData = new FormData();
    leftData.top = new FormAttachment(0, 5);
    leftData.bottom = new FormAttachment(100, 0);
    leftData.left = new FormAttachment(0, 5);
    leftData.right = new FormAttachment(45, 0);
    leftComposite.setLayoutData(leftData);
    Composite rightComposite = new Composite(container, SWT.NONE);
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 5);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(45, 0);
    rightData.right = new FormAttachment(100, -5);
    rightComposite.setLayoutData(rightData);
    GridLayout rightCompositeLayout = new GridLayout();
    rightCompositeLayout.verticalSpacing = 10;
    rightComposite.setLayout(rightCompositeLayout);
    Label tableInfoLabel = new Label(leftComposite, SWT.None);
    tableInfoLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    tableInfoLabel.setText(Messages.exportWizardSourceTableLable);
    ctv = new CheckboxTreeViewer(leftComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    ctv.getTree().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    ctv.setContentProvider(new FilterTreeContentProvider());
    ctv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            updateDialogStatus();
        }
    });
    final TreeViewerColumn dbObjectCol = new TreeViewerColumn(ctv, SWT.NONE);
    dbObjectCol.setLabelProvider(new ExportObjectLabelProvider());
    final TreeViewerColumn whereCnd = new TreeViewerColumn(ctv, SWT.NONE);
    whereCnd.setLabelProvider(new ExportObjectLabelProvider());
    whereCnd.setEditingSupport(new EditingSupport(ctv) {

        TextCellEditor textCellEditor;

        protected boolean canEdit(Object element) {
            if (element instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) element;
                if (node.getType() == NodeType.TABLE_COLUMN_FOLDER) {
                    return true;
                }
            }
            return false;
        }

        protected CellEditor getCellEditor(Object element) {
            if (textCellEditor == null) {
                textCellEditor = new TextCellEditor(ctv.getTree());
            }
            return textCellEditor;
        }

        protected Object getValue(Object element) {
            final ICubridNode node = (ICubridNode) element;
            String condition = (String) node.getData(ExportObjectLabelProvider.CONDITION);
            if (condition == null) {
                return "";
            } else {
                return condition;
            }
        }

        protected void setValue(Object element, Object value) {
            final ICubridNode node = (ICubridNode) element;
            node.setData(ExportObjectLabelProvider.CONDITION, value);
            ctv.refresh();
        }
    });
    dbObjectCol.getColumn().setWidth(160);
    dbObjectCol.getColumn().setText(Messages.tableLabel);
    whereCnd.getColumn().setWidth(120);
    whereCnd.getColumn().setText(Messages.conditionLabel);
    final Button selectAllBtn = new Button(leftComposite, 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();
            for (ICubridNode node : tablesOrViewLst) {
                ctv.setGrayed(node, false);
                ctv.setChecked(node, selection);
            }
            updateDialogStatus();
        }
    });
    Group fileOptionGroup = new Group(rightComposite, SWT.None);
    fileOptionGroup.setText(Messages.exportWizardWhereExport);
    fileOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    fileOptionGroup.setLayout(new GridLayout(3, false));
    schemaButton = new Button(fileOptionGroup, SWT.CHECK);
    schemaButton.setText("Schema");
    schemaButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    schemaButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (schemaButton.getSelection()) {
                schemaPathText.setEnabled(true);
                schemaBrowseButton.setEnabled(true);
                startValueButton.setEnabled(true);
            } else {
                schemaPathText.setEnabled(false);
                schemaBrowseButton.setEnabled(false);
                startValueButton.setEnabled(false);
            }
            updateDialogStatus();
        }
    });
    schemaPathText = new Text(fileOptionGroup, SWT.BORDER);
    schemaPathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    schemaPathText.setEnabled(true);
    schemaPathText.setEditable(false);
    schemaPathText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus();
        }
    });
    schemaBrowseButton = new Button(fileOptionGroup, SWT.None);
    schemaBrowseButton.setText(Messages.btnBrowse);
    schemaBrowseButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    schemaBrowseButton.setEnabled(true);
    schemaBrowseButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DatabaseInfo databaseInfo = getDatabase().getDatabaseInfo();
            String databaseName = databaseInfo.getDbName();
            String fileNameForLoaddbSchema = databaseName + "_schema";
            File savedFile = TableUtil.getSavedFile(getShell(), new String[] { "*.*" }, new String[] { "All Files" }, fileNameForLoaddbSchema, null, null);
            if (savedFile != null) {
                schemaPathText.setText(savedFile.getAbsolutePath());
            }
            updateDialogStatus();
        }
    });
    indexButton = new Button(fileOptionGroup, SWT.CHECK);
    indexButton.setText("Index");
    indexButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    indexButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (indexButton.getSelection()) {
                indexPathText.setEnabled(true);
                indexBrowseButton.setEnabled(true);
            } else {
                indexPathText.setEnabled(false);
                indexBrowseButton.setEnabled(false);
            }
            updateDialogStatus();
        }
    });
    indexPathText = new Text(fileOptionGroup, SWT.BORDER);
    indexPathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    indexPathText.setEnabled(true);
    indexPathText.setEditable(false);
    indexPathText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus();
        }
    });
    indexBrowseButton = new Button(fileOptionGroup, SWT.None);
    indexBrowseButton.setText(Messages.btnBrowse);
    indexBrowseButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    indexBrowseButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DatabaseInfo databaseInfo = getDatabase().getDatabaseInfo();
            String databaseName = databaseInfo.getDbName();
            String fileNameForLoaddbIndex = databaseName + "_indexes";
            File savedFile = TableUtil.getSavedFile(getShell(), new String[] { "*.*" }, new String[] { "All Files" }, fileNameForLoaddbIndex, null, null);
            if (savedFile != null) {
                indexPathText.setText(savedFile.getAbsolutePath());
            }
            updateDialogStatus();
        }
    });
    dataButton = new Button(fileOptionGroup, SWT.CHECK);
    dataButton.setText("Data");
    dataButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    dataButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (dataButton.getSelection()) {
                dataPathText.setEnabled(true);
                dataBrowseButton.setEnabled(true);
            } else {
                dataPathText.setEnabled(false);
                dataBrowseButton.setEnabled(false);
            }
            updateDialogStatus();
        }
    });
    dataPathText = new Text(fileOptionGroup, SWT.BORDER);
    dataPathText.setEditable(false);
    dataPathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    dataPathText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus();
        }
    });
    dataBrowseButton = new Button(fileOptionGroup, SWT.None);
    dataBrowseButton.setText(Messages.btnBrowse);
    dataBrowseButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    dataBrowseButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DatabaseInfo databaseInfo = getDatabase().getDatabaseInfo();
            String databaseName = databaseInfo.getDbName();
            String fileNameForLoaddbData = databaseName + "_objects";
            File savedFile = TableUtil.getSavedFile(getShell(), new String[] { "*.*" }, new String[] { "All Files" }, fileNameForLoaddbData, null, null);
            if (savedFile != null) {
                dataPathText.setText(savedFile.getAbsolutePath());
            }
            updateDialogStatus();
        }
    });
    Group enCodingOptionGroup = new Group(rightComposite, SWT.None);
    enCodingOptionGroup.setText(Messages.exportWizardDataOption);
    enCodingOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    enCodingOptionGroup.setLayout(new GridLayout(4, false));
    Label dbCharsetLabel = new Label(enCodingOptionGroup, SWT.None);
    dbCharsetLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    dbCharsetLabel.setText(Messages.lblJDBCCharset);
    dbCharsetCombo = new Combo(enCodingOptionGroup, SWT.BORDER);
    dbCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, 50, 21));
    dbCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    dbCharsetCombo.setEnabled(false);
    Label fileCharsetLabel = new Label(enCodingOptionGroup, SWT.None);
    fileCharsetLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    fileCharsetLabel.setText(Messages.lblFileCharset);
    fileCharsetCombo = new Combo(enCodingOptionGroup, SWT.BORDER);
    fileCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, 50, 21));
    fileCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    fileCharsetCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus();
        }
    });
    startValueButton = new Button(enCodingOptionGroup, SWT.CHECK);
    startValueButton.setText(Messages.lblExportTargetStartValue);
    startValueButton.setLayoutData(CommonUITool.createGridData(4, 1, -1, -1));
    startValueButton.setToolTipText(Messages.tipExportTargetStartValue);
    setControl(container);
}
Also used : Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) FilterTreeContentProvider(com.cubrid.common.ui.common.dialog.FilterTreeContentProvider) ExportObjectLabelProvider(com.cubrid.common.ui.common.navigator.ExportObjectLabelProvider) GridData(org.eclipse.swt.layout.GridData) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) File(java.io.File)

Example 3 with CheckStateChangedEvent

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

the class MultiDBQueryComposite method initialize.

/**
	 * Create the SQL history composite
	 */
public void initialize() {
    Composite toolBarComposite = new Composite(this, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 10;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    toolBarComposite.setLayout(gridLayout);
    toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
    refreshToolItem.setText(Messages.lblItemRefreshMulti);
    refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setToolTipText(Messages.refresh);
    refreshToolItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            //refresh may set tree to group type or not
            //so mark the select db then set it to checked after set input
            //				Object[] checkedObject = ctv.getCheckedElements();
            setInput();
        //				for (Object o : checkedObject) {
        //					if (o instanceof CubridDatabase) {
        //						ctv.setChecked(o, true);
        //					}
        //				}
        //				refresh(editor.getSelectedDatabase());
        }
    });
    runItem = new ToolItem(toolBar, SWT.PUSH);
    runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
    runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
    runItem.setText(Messages.lblItemRunMulti);
    runItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            editor.runMultiQuery();
        }
    });
    Label lblNotice = new Label(toolBarComposite, SWT.None);
    lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
    lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
    // create the query result tab folder
    multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
    multiDBQueryCompTabFolder.setSimple(false);
    multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
    multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
    multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
    multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
    multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
    multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
    //TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
    //tabContextMenuManager.createContextMenu();
    multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
    multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
    multiDBQueryCompTabItem.setControl(this);
    multiDBQueryCompTabItem.setShowClose(false);
    SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
    bottomSash.SASH_WIDTH = SASH_WIDTH;
    bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
    tailSash.SASH_WIDTH = SASH_WIDTH;
    tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    Composite treeComp = new Composite(tailSash, SWT.NONE);
    {
        treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
        treeComp.setLayout(new GridLayout());
    }
    ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
    ctv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
                ctv.setChecked(event.getElement(), true);
                return;
            }
            ctv.setChecked(event.getElement(), false);
            lastSelectedTime = System.currentTimeMillis() + 100;
            if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
                editor.setMultiQueryRunItemStatus(true);
            } else if (getQueryDatabaseList().size() == 0) {
                editor.setMultiQueryRunItemStatus(false);
            }
            //if (!event.getChecked()) {
            selectedNodes.remove(event.getElement());
            if (event.getElement() instanceof CubridDatabase) {
                CubridDatabase database = (CubridDatabase) event.getElement();
                if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                    //ctv.setChecked(event.getElement(), false);
                    selectedNodes.remove(database);
                } else {
                    if (database.getData(INDEXKEY) == null) {
                        database.setData(INDEXKEY, String.valueOf(databaseIndex++));
                    }
                }
            } else if (event.getElement() instanceof CubridServer) {
                CubridServer serverNode = (CubridServer) event.getElement();
                for (ICubridNode dbFolderNode : serverNode.getChildren()) {
                    for (ICubridNode dbNode : dbFolderNode.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                //ctv.setChecked(dbNode, false);
                                selectedNodes.remove(database);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, true);
                            }
                        }
                    }
                    //only has one db folder  so first time break it
                    break;
                }
            } else if (event.getElement() instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) event.getElement();
                if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
                    for (ICubridNode dbNode : node.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                ctv.setChecked(dbNode, false);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, false);
                            }
                        }
                    }
                }
            //					else if (node.getType().equals(NodeType.GROUP)) {
            //						for (ICubridNode childNode : node.getChildren()) {
            //							//CQB tree
            //							if(childNode instanceof CubridDatabase) {
            //								CubridDatabase database = (CubridDatabase) childNode;
            //								if (database.getRunningType() == DbRunningType.STANDALONE
            //										|| !database.isLogined()) {
            //									if (childNode.getData(INDEXKEY) == null) {
            //										childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //									}
            //								}
            //								continue;
            //							}
            //							//CM tree
            //							for (ICubridNode dbFolderNode : childNode.getChildren()) {
            //								for (ICubridNode dbNode : dbFolderNode.getChildren()) {
            //									if(dbNode instanceof CubridDatabase) {
            //										CubridDatabase database = (CubridDatabase) dbNode;
            //										if (database.getRunningType() == DbRunningType.STANDALONE
            //												|| !database.isLogined()) {
            //											ctv.setChecked(dbNode, false);
            //										} else if (ctv.getChecked(dbNode)) {
            //											ctv.setChecked(dbNode, true);
            //											if (dbNode.getData(INDEXKEY) == null) {
            //												dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //											}
            //										} else {
            //											ctv.setChecked(dbNode, false);
            //										}
            //									}
            //								}
            //							}
            //							//only has one db folder  so first time break it
            //							break;
            //						}
            //					}
            }
            ctv.refresh();
        }
    });
    ctv.getTree().addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent event) {
            //mac can't drag and drop,so support copy and paste db node
            if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                String[] databaseNameArray = plainText.split(",");
                selectedNodes.addAll(getDatabaseNode(databaseNameArray));
                setInput();
            }
        }
    });
    //		ctv.addDoubleClickListener(LayoutManager.getInstance());
    //		ctv.addTreeListener(new ITreeViewerListener() {
    //			public void treeCollapsed(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //
    //			public void treeExpanded(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //		});
    final Tree tableTree = ctv.getTree();
    tableTree.setHeaderVisible(true);
    tableTree.setLinesVisible(true);
    final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
    dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    dbCol.getColumn().setWidth(250);
    dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
    final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
    indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    indexCol.getColumn().setWidth(50);
    indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
    indexCol.setEditingSupport(new EditingSupport(ctv) {

        TextCellEditor textCellEditor;

        protected boolean canEdit(Object element) {
            if (element instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) element;
                if (node.getType() == NodeType.DATABASE) {
                    CubridDatabase database = (CubridDatabase) element;
                    if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
                        return true;
                    }
                }
            }
            return false;
        }

        protected CellEditor getCellEditor(Object element) {
            if (textCellEditor == null) {
                textCellEditor = new TextCellEditor(ctv.getTree());
                textCellEditor.setValidator(new IndexCellEditorValidator());
                textCellEditor.addListener(new ICellEditorListener() {

                    public void applyEditorValue() {
                    }

                    public void cancelEditor() {
                    }

                    public void editorValueChanged(boolean oldValidState, boolean newValidState) {
                    }
                });
            }
            return textCellEditor;
        }

        protected Object getValue(Object element) {
            final ICubridNode node = (ICubridNode) element;
            String index = (String) node.getData(INDEXKEY);
            if (index == null) {
                return "";
            } else {
                return index;
            }
        }

        protected void setValue(Object element, Object value) {
            if (value == null) {
                return;
            }
            try {
                Integer.valueOf((String) value);
            } catch (Exception e) {
                return;
            }
            final ICubridNode node = (ICubridNode) element;
            node.setData(INDEXKEY, value);
            //				setAllParentExpandOrCollapse(node.getParent(), true);
            ctv.refresh();
        }

        /**
			 * MyCellEditorValidator
			 *
			 * @author fulei
			 *
			 */
        class IndexCellEditorValidator implements ICellEditorValidator {

            /**
				 * isValid
				 *
				 * @param value Object
				 * @return String
				 */
            public String isValid(Object value) {
                try {
                    Integer.valueOf((String) value);
                } catch (Exception e) {
                    CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
                    return Messages.qedit_multiDBQueryComp_tree_indexErr;
                }
                return null;
            }
        }
    });
    final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
    commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    commentCol.getColumn().setWidth(200);
    commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
    CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
    tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
    tabItem.setControl(bottomSash);
    tabItem.setShowClose(false);
    setInput();
    //		HostNodePersistManager.getInstance().getAllServer();
    multiDBQueryCompTabFolder.setSelection(tabItem);
    dragController = new MultiDBQueryDNDController(this, ctv);
    dragController.registerDropTarget();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) CTabItem(org.eclipse.swt.custom.CTabItem) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) SashForm(org.eclipse.swt.custom.SashForm) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with CheckStateChangedEvent

use of org.eclipse.jface.viewers.CheckStateChangedEvent 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)

Example 5 with CheckStateChangedEvent

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

the class FilterSettingDialog method createTreeComposite.

/**
	 * 
	 * Create the tree composite
	 * 
	 * @param parent Composite
	 */
private void createTreeComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.LEFT);
    label.setText(Messages.lblTreeFilter);
    label.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    ctv = new CheckboxTreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 300));
    ctv.setContentProvider(new FilterTreeContentProvider());
    ctv.setLabelProvider(tv.getLabelProvider(0));
    ctv.setInput(tv.getInput());
    ctv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            ctv.setSubtreeChecked(event.getElement(), event.getChecked());
            ctv.setGrayChecked(event.getElement(), false);
            ctv.setChecked(event.getElement(), event.getChecked());
            if (event.getElement() instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) event.getElement();
                ICubridNode parent = node.getParent();
                setParentStatus(parent);
            }
        }

        /**
			 * 
			 * Set parent element status
			 * 
			 * @param parent ICubridNode
			 */
        private void setParentStatus(ICubridNode parent) {
            if (parent == null) {
                return;
            }
            int state = getAllChildrenCheckedState(parent);
            if (state == -1) {
                ctv.setGrayChecked(parent, false);
                ctv.setChecked(parent, false);
            } else if (state == 1 || state == 0) {
                ctv.setChecked(parent, false);
                ctv.setGrayChecked(parent, true);
            }
            setParentStatus(parent.getParent());
        }

        /**
			 * 
			 * Return checked children element status
			 * 
			 * @param parent ICubridNode
			 * @return int <code>-1</code>all is not checked;<code>1</code>all
			 *         is checked;<code>0</code> some is checked,others is not
			 *         checked
			 */
        private int getAllChildrenCheckedState(ICubridNode parent) {
            List<ICubridNode> childrenList = parent.getChildren();
            boolean isAllChecked = true;
            boolean isHasChecked = false;
            for (ICubridNode node : childrenList) {
                if (ctv.getGrayed(node)) {
                    isAllChecked = false;
                    isHasChecked = true;
                } else if (ctv.getChecked(node)) {
                    isHasChecked = true;
                } else {
                    isAllChecked = false;
                }
            }
            if (!isHasChecked) {
                return -1;
            }
            if (isAllChecked) {
                return 1;
            }
            return 0;
        }
    });
    Composite btnComposite = new Composite(composite, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginRight = 10;
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    gridData.verticalAlignment = GridData.CENTER;
    gridData.grabExcessHorizontalSpace = true;
    btnComposite.setLayoutData(gridData);
    btnComposite.setLayout(gridLayout);
    Button restoreBtn = new Button(btnComposite, SWT.PUSH);
    restoreBtn.setText(Messages.btnRest);
    restoreBtn.setLayoutData(CommonUITool.createGridData(GridData.END, 1, 1, -1, -1));
    restoreBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            ctv.setCheckedElements(defaultCheckedList.toArray());
            for (ICubridNode node : defaultGrayCheckedList) {
                ctv.setGrayChecked(node, true);
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)99 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)96 GridData (org.eclipse.swt.layout.GridData)62 Composite (org.eclipse.swt.widgets.Composite)47 GridLayout (org.eclipse.swt.layout.GridLayout)43 SelectionEvent (org.eclipse.swt.events.SelectionEvent)39 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 Label (org.eclipse.swt.widgets.Label)33 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)32 Button (org.eclipse.swt.widgets.Button)29 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)22 Viewer (org.eclipse.jface.viewers.Viewer)22 Table (org.eclipse.swt.widgets.Table)21 ArrayList (java.util.ArrayList)18 TableColumn (org.eclipse.swt.widgets.TableColumn)17 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)16 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)16 Event (org.eclipse.swt.widgets.Event)16 Listener (org.eclipse.swt.widgets.Listener)15 List (java.util.List)13