Search in sources :

Example 41 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project GT by Tencent.

the class DevicesView method createTargetPkgTableView.

/**
 * 创建被测进程列表
 * @Title: createTargetPkgTableView
 * @Description:
 * @param parent
 * void
 * @throws
 */
private void createTargetPkgTableView(Composite parent) {
    targetPkgTableViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK);
    ctv = new CheckboxTableViewer(targetPkgTableViewer.getTable());
    ctv.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (isSupportCheckChangePer) {
                GetCurCheckedStateUtil.update();
            } else {
                APTConsoleFactory.getInstance().APTPrint("Operation forbid");
            }
        }
    });
    // 设置表头内容
    for (int i = 0; i < TARGET_COLUMN_NAME.length; i++) {
        new TableColumn(targetPkgTableViewer.getTable(), SWT.LEFT).setText(TARGET_COLUMN_NAME[i]);
    }
    targetPkgTableViewer.getTable().getColumn(0).setWidth(200);
    targetPkgTableViewer.getTable().getColumn(1).setWidth(50);
    // 设置表头和表格线可见
    targetPkgTableViewer.getTable().setHeaderVisible(true);
    targetPkgTableViewer.getTable().setLinesVisible(true);
    targetPkgTableViewer.setContentProvider(new ViewContentProvider());
    targetPkgTableViewer.setLabelProvider(new ViewLabelProvider());
    targetPkgTableViewer.getTable().addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            if (isSupportAddOrDeleteOper) {
                APTState.getInstance().DealWithEventBefore(APTEventEnum.CONFIGRURE_OPER);
                TableItem[] selectData = targetPkgTableViewer.getTable().getSelection();
                if (selectData == null || selectData.length == 0) {
                    return;
                }
                PkgInfo itemData = (PkgInfo) selectData[0].getData();
                targetPkgTableViewer.remove(itemData);
                APTState.getInstance().DealWithEventAfter(APTEventEnum.CONFIGRURE_OPER);
            } else {
                APTConsoleFactory.getInstance().APTPrint("Operation forbid");
            }
        }
    });
    targetPkgTableViewer.getTable().setToolTipText("双击或者右键菜单可删除被测进程");
    FormData tableViewFormData = new FormData();
    tableViewFormData.left = new FormAttachment(0, 5);
    tableViewFormData.right = new FormAttachment(100, -5);
    tableViewFormData.top = new FormAttachment(pkgNameText, 10);
    tableViewFormData.height = 125;
    Table table = targetPkgTableViewer.getTable();
    table.setLayoutData(tableViewFormData);
}
Also used : FormData(org.eclipse.swt.layout.FormData) MouseEvent(org.eclipse.swt.events.MouseEvent) Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TableColumn(org.eclipse.swt.widgets.TableColumn) PkgInfo(com.tencent.wstt.apt.data.PkgInfo) MouseListener(org.eclipse.swt.events.MouseListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 42 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project hale by halestudio.

the class SchemasRetrievalPage method createComponent.

private void createComponent() {
    if (multipleSelection) {
        selectAll = new Button(page, SWT.CHECK);
        selectAll.setText("Select all");
        selectAll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        selectAll.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                schemaTable.setAllChecked(((Button) e.getSource()).getSelection());
            }
        });
        schemaTable = CheckboxTableViewer.newCheckList(page, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    } else
        schemaTable = CheckboxTableViewer.newCheckList(page, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    schemaTable.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return element.toString();
        }
    });
    schemaTable.setContentProvider(ArrayContentProvider.getInstance());
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    layoutData.widthHint = SWT.DEFAULT;
    layoutData.heightHint = 8 * schemaTable.getTable().getItemHeight();
    schemaTable.getControl().setLayoutData(layoutData);
    schemaTable.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked() && (!multipleSelection)) {
                schemaTable.setAllChecked(false);
                schemaTable.setCheckedElements(new Object[] { event.getElement() });
            }
            setPageComplete(validate());
        }
    });
    setPageComplete(false);
    page.layout(true, true);
}
Also used : Button(org.eclipse.swt.widgets.Button) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 43 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project hale by halestudio.

the class EditMappableTypesPage method createControl.

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControl(Composite parent) {
    parent.setLayout(new GridLayout());
    // create filtered tree
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
            return new CheckboxTreeViewer(parent, style);
        }
    };
    // configure viewer
    viewer = (CheckboxTreeViewer) tree.getViewer();
    contentProvider = new NSTypeTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setComparator(new DefinitionComparator());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object doubleClicked = selection.getFirstElement();
            if (doubleClicked instanceof String)
                viewer.setExpandedState(doubleClicked, !viewer.getExpandedState(doubleClicked));
            else {
                boolean newState = !checkStateProvider.isChecked(doubleClicked);
                viewer.setChecked(doubleClicked, newState);
                checkStateOfTypeChanged((TypeDefinition) doubleClicked, newState);
            }
        }
    });
    viewer.setLabelProvider(definitionLabels);
    // because elements filtered by FilteredTree lose their checked state:
    checkStateProvider = new ICheckStateProvider() {

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof String) {
                Object[] children = contentProvider.getChildren(element);
                boolean containsChecked = false;
                boolean containsUnchecked = false;
                for (Object child : children) {
                    if (isChecked(child))
                        containsChecked = true;
                    else
                        containsUnchecked = true;
                    if (containsChecked && containsUnchecked)
                        return true;
                }
            }
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            if (element instanceof String) {
                for (Object child : contentProvider.getChildren(element)) if (isChecked(child))
                    return true;
                return false;
            }
            return ((TypeDefinition) element).getConstraint(MappingRelevantFlag.class).isEnabled() != changedTypes.contains(element);
        }
    };
    viewer.setCheckStateProvider(checkStateProvider);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof String) {
                // update children
                viewer.setGrayed(event.getElement(), false);
                for (Object child : contentProvider.getChildren(event.getElement())) {
                    // if (mappedTypeFilter.select(viewer, event.getElement(), child)) {
                    if (checkStateProvider.isChecked(child) != event.getChecked()) {
                        viewer.setChecked(child, event.getChecked());
                        checkStateOfTypeChanged((TypeDefinition) child, event.getChecked());
                    }
                // }
                }
                viewer.setGrayed(event.getElement(), checkStateProvider.isGrayed(event.getElement()));
            // only two levels, no need to update any parents or
            // children's children
            } else {
                // if (mappedTypeFilter.select(viewer, null, event.getElement()))
                checkStateOfTypeChanged((TypeDefinition) event.getElement(), event.getChecked());
            // else if (!event.getChecked())
            // viewer.setChecked(event.getElement(), true);
            }
        }
    });
    // // filter types which are used in the current alignment
    // viewer.addFilter(mappedTypeFilter);
    // set input to all types in the given index
    viewer.setInput(typeIndex.getTypes());
    // expand all except XMLSchema
    viewer.expandAll();
    viewer.setExpandedState("http://www.w3.org/2001/XMLSchema", false);
    // set control
    setControl(viewer.getControl());
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) NSTypeTreeContentProvider(eu.esdihumboldt.hale.ui.service.schema.util.NSTypeTreeContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Example 44 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project hale by halestudio.

the class AbstractFeatureTypesPage method createContent.

@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(1, false));
    // create filtered tree
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(page, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
            return new CheckboxTreeViewer(parent, style);
        }
    };
    // configure viewer
    viewer = (CheckboxTreeViewer) tree.getViewer();
    contentProvider = new FeatureTypeTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    // viewer.setComparator(new DefinitionComparator());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object doubleClicked = selection.getFirstElement();
            if (doubleClicked instanceof String)
                viewer.setExpandedState(doubleClicked, !viewer.getExpandedState(doubleClicked));
            else {
                boolean newState = !checkStateProvider.isChecked(doubleClicked);
                viewer.setChecked(doubleClicked, newState);
                checkStateOfTypeChanged((QName) doubleClicked, newState);
            }
        }
    });
    viewer.setLabelProvider(new FeatureTypeTreeLabelProvider());
    // because elements filtered by FilteredTree lose their checked state:
    checkStateProvider = new ICheckStateProvider() {

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof String) {
                Object[] children = contentProvider.getChildren(element);
                boolean containsChecked = false;
                boolean containsUnchecked = false;
                for (Object child : children) {
                    if (isChecked(child))
                        containsChecked = true;
                    else
                        containsUnchecked = true;
                    if (containsChecked && containsUnchecked)
                        return true;
                }
            }
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            if (element instanceof String) {
                for (Object child : contentProvider.getChildren(element)) if (isChecked(child))
                    return true;
                return false;
            }
            return selected.contains(element);
        }
    };
    viewer.setCheckStateProvider(checkStateProvider);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof String) {
                // update children
                viewer.setGrayed(event.getElement(), false);
                for (Object child : contentProvider.getChildren(event.getElement())) {
                    if (checkStateProvider.isChecked(child) != event.getChecked()) {
                        viewer.setChecked(child, event.getChecked());
                        checkStateOfTypeChanged((QName) child, event.getChecked());
                    }
                }
                viewer.setGrayed(event.getElement(), checkStateProvider.isGrayed(event.getElement()));
            // only two levels, no need to update any parents or
            // children's children
            } else {
                checkStateOfTypeChanged((QName) event.getElement(), event.getChecked());
            }
        }
    });
    setControl(page);
    // initial update
    updateState(selected);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) QName(javax.xml.namespace.QName) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 45 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project tbd-studio-se by Talend.

the class HadoopServicesTableComposite method addListener.

private void addListener() {
    servicesTableViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            checkServices();
        }
    });
    selectAllBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doSelectAll();
        }
    });
    deselectAllBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doDeselectAll();
        }
    });
}
Also used : ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)101 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)97 GridData (org.eclipse.swt.layout.GridData)62 Composite (org.eclipse.swt.widgets.Composite)48 GridLayout (org.eclipse.swt.layout.GridLayout)44 SelectionEvent (org.eclipse.swt.events.SelectionEvent)40 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)34 Label (org.eclipse.swt.widgets.Label)32 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)31 Button (org.eclipse.swt.widgets.Button)30 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)22 Viewer (org.eclipse.jface.viewers.Viewer)21 Table (org.eclipse.swt.widgets.Table)21 ArrayList (java.util.ArrayList)19 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