Search in sources :

Example 1 with SelectIncrementContentProvider

use of com.devonfw.cobigen.eclipse.wizard.common.model.SelectIncrementContentProvider in project cobigen by devonfw.

the class SelectFilesPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.FILL);
    container.setLayout(new GridLayout());
    SashForm sash = new SashForm(container, SWT.HORIZONTAL);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    sash.setLayoutData(gd);
    Composite containerLeft = new Composite(sash, SWT.FILL);
    containerLeft.setLayout(new GridLayout(1, false));
    Label label = new Label(containerLeft, SWT.NONE);
    label.setText("Filter (increments):");
    this.incrementSelector = new CustomizedCheckboxTreeViewer(containerLeft);
    this.incrementSelector.setContentProvider(new SelectIncrementContentProvider());
    this.incrementSelector.setInput(this.cobigenWrapper.getAllIncrements());
    gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessVerticalSpace = true;
    this.incrementSelector.getTree().setLayoutData(gd);
    this.incrementSelector.expandAll();
    this.containerRight = new Composite(sash, SWT.FILL);
    this.containerRight.setLayout(new GridLayout(1, false));
    boolean initiallyCustomizable = false;
    buildResourceTreeViewer(initiallyCustomizable);
    CheckStateListener checkListener = new CheckStateListener(this.cobigenWrapper, this, this.batch);
    this.incrementSelector.addCheckStateListener(checkListener);
    sash.setWeights(new int[] { 1, 3 });
    this.rememberSelection = new Button(container, SWT.CHECK);
    this.rememberSelection.setText("Remember my selection");
    gd = new GridData();
    gd.horizontalAlignment = SWT.BEGINNING;
    this.rememberSelection.setLayoutData(gd);
    this.rememberSelection.addSelectionListener(checkListener);
    Button but = new Button(container, SWT.PUSH);
    but.setText("Customize");
    gd = new GridData();
    gd.horizontalAlignment = SWT.END;
    but.setLayoutData(gd);
    but.addListener(SWT.Selection, new ButtonListener(initiallyCustomizable, this));
    setControl(container);
    loadSelection();
}
Also used : ButtonListener(com.devonfw.cobigen.eclipse.wizard.common.control.ButtonListener) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) SelectIncrementContentProvider(com.devonfw.cobigen.eclipse.wizard.common.model.SelectIncrementContentProvider) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) CheckStateListener(com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) CustomizedCheckboxTreeViewer(com.devonfw.cobigen.eclipse.wizard.common.widget.CustomizedCheckboxTreeViewer)

Example 2 with SelectIncrementContentProvider

use of com.devonfw.cobigen.eclipse.wizard.common.model.SelectIncrementContentProvider in project cobigen by devonfw.

the class CheckStateListener method performCheckLogic.

/**
 * Performs an intelligent check logic such that the same element in different paths will be checked simultaneously,
 * parents will be unselected if at least one child is not selected, and parents will be automatically selected if all
 * children of the parent are selected
 *
 * @param event triggering {@link CheckStateChangedEvent}
 * @param packageSelector current {@link CheckboxTreeViewer} for the package selection
 */
public void performCheckLogic(CheckStateChangedEvent event, CheckboxTreeViewer packageSelector) {
    if (event.getSource().equals(packageSelector)) {
        SelectIncrementContentProvider cp = (SelectIncrementContentProvider) packageSelector.getContentProvider();
        TreePath[] paths = cp.getAllPaths(event.getElement());
        for (TreePath path : paths) {
            packageSelector.setSubtreeChecked(path, event.getChecked());
        }
        TreePath[] parents = cp.getParents(event.getElement());
        if (event.getChecked()) {
            for (TreePath parent : parents) {
                boolean allChecked = true;
                for (Object child : cp.getChildren(parent)) {
                    if (!packageSelector.getChecked(parent.createChildPath(child))) {
                        allChecked = false;
                        break;
                    }
                }
                if (allChecked) {
                    packageSelector.setChecked(parent, true);
                }
            }
            if (event.getElement().toString().contains("All")) {
                packageSelector.setAllChecked(true);
            }
            // checks if all child increments are checked and checks All-Checkbox
            boolean allChecked = true;
            for (TreeItem item : packageSelector.getTree().getItems()) {
                if (!item.getChecked() && !item.getText().contains("All")) {
                    allChecked = false;
                    break;
                }
            }
            if (allChecked) {
                packageSelector.getTree().getItem(0).setChecked(true);
            }
        } else {
            for (TreePath parent : parents) {
                if (parent.getSegmentCount() > 0) {
                    packageSelector.setChecked(parent, false);
                }
            }
        }
    }
}
Also used : SelectIncrementContentProvider(com.devonfw.cobigen.eclipse.wizard.common.model.SelectIncrementContentProvider) TreePath(org.eclipse.jface.viewers.TreePath) TreeItem(org.eclipse.swt.widgets.TreeItem)

Aggregations

SelectIncrementContentProvider (com.devonfw.cobigen.eclipse.wizard.common.model.SelectIncrementContentProvider)2 ButtonListener (com.devonfw.cobigen.eclipse.wizard.common.control.ButtonListener)1 CheckStateListener (com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener)1 CustomizedCheckboxTreeViewer (com.devonfw.cobigen.eclipse.wizard.common.widget.CustomizedCheckboxTreeViewer)1 TreePath (org.eclipse.jface.viewers.TreePath)1 SashForm (org.eclipse.swt.custom.SashForm)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1