Search in sources :

Example 1 with CheckStateListener

use of com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener 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 CheckStateListener

use of com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener in project cobigen by devonfw.

the class SelectFilesPage method buildResourceTreeViewer.

/**
 * Builds the {@link TreeViewer} providing the tree of resources to be generated
 *
 * @param customizable states whether the checkboxes of the tree should be displayed or not
 */
public void buildResourceTreeViewer(boolean customizable) {
    IContentProvider cp;
    IBaseLabelProvider lp;
    Object[] checkedElements;
    if (this.resourcesTree != null) {
        cp = this.resourcesTree.getContentProvider();
        lp = this.resourcesTree.getLabelProvider();
        checkedElements = this.resourcesTree.getCheckedElements();
    } else {
        cp = new SelectFileContentProvider();
        lp = new SelectFileLabelProvider(this.cobigenWrapper, this.batch);
        this.incrementSelector.addCheckStateListener((SelectFileLabelProvider) lp);
        checkedElements = new Object[0];
    }
    disposeContainerRightChildren();
    Label label = new Label(this.containerRight, SWT.NONE);
    label.setText("Resources to be generated (selected):");
    if (customizable) {
        this.resourcesTree = new CustomizedCheckboxTreeViewer(this.containerRight);
    } else {
        this.resourcesTree = new SimulatedCheckboxTreeViewer(this.containerRight);
    }
    this.resourcesTree.setContentProvider(cp);
    this.resourcesTree.setLabelProvider(lp);
    this.resourcesTree.setInput(ResourcesPlugin.getWorkspace().getRoot().getProjects());
    this.resourcesTree.expandToLevel(AbstractTreeViewer.ALL_LEVELS);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    this.resourcesTree.getTree().setLayoutData(gd);
    CheckStateListener listener = new CheckStateListener(this.cobigenWrapper, this, this.batch);
    this.resourcesTree.addCheckStateListener(listener);
    this.resourcesTree.setCheckedElements(checkedElements);
    this.containerRight.layout();
}
Also used : SelectFileContentProvider(com.devonfw.cobigen.eclipse.wizard.common.model.SelectFileContentProvider) IContentProvider(org.eclipse.jface.viewers.IContentProvider) SimulatedCheckboxTreeViewer(com.devonfw.cobigen.eclipse.wizard.common.widget.SimulatedCheckboxTreeViewer) CheckStateListener(com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectFileLabelProvider(com.devonfw.cobigen.eclipse.wizard.common.model.SelectFileLabelProvider) CustomizedCheckboxTreeViewer(com.devonfw.cobigen.eclipse.wizard.common.widget.CustomizedCheckboxTreeViewer)

Example 3 with CheckStateListener

use of com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener in project cobigen by devonfw.

the class SelectFileLabelProvider method checkStateChanged.

@Override
public void checkStateChanged(CheckStateChangedEvent event) {
    synchronized (this.selectedIncrements) {
        // Increments selection has been changed
        if (event.getSource() instanceof CheckboxTreeViewer) {
            CheckboxTreeViewer incrementSelector = (CheckboxTreeViewer) event.getSource();
            CheckStateListener listener = new CheckStateListener(this.cobigenWrapper, null, this.batch);
            listener.performCheckLogic(event, incrementSelector);
            Set<Object> selectedElements = new HashSet<>(Arrays.asList(((CheckboxTreeViewer) event.getSource()).getCheckedElements()));
            this.selectedIncrements.clear();
            for (Object o : selectedElements) {
                if (o instanceof IncrementTo) {
                    this.selectedIncrements.add((IncrementTo) o);
                } else {
                    throw new CobiGenEclipseRuntimeException("Unexpected increment type '" + o.getClass().getCanonicalName() + "' !");
                }
            }
        }
    }
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) CobiGenEclipseRuntimeException(com.devonfw.cobigen.eclipse.common.exceptions.CobiGenEclipseRuntimeException) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CheckStateListener(com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener) HashSet(java.util.HashSet)

Aggregations

CheckStateListener (com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener)3 CustomizedCheckboxTreeViewer (com.devonfw.cobigen.eclipse.wizard.common.widget.CustomizedCheckboxTreeViewer)2 GridData (org.eclipse.swt.layout.GridData)2 Label (org.eclipse.swt.widgets.Label)2 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)1 CobiGenEclipseRuntimeException (com.devonfw.cobigen.eclipse.common.exceptions.CobiGenEclipseRuntimeException)1 ButtonListener (com.devonfw.cobigen.eclipse.wizard.common.control.ButtonListener)1 SelectFileContentProvider (com.devonfw.cobigen.eclipse.wizard.common.model.SelectFileContentProvider)1 SelectFileLabelProvider (com.devonfw.cobigen.eclipse.wizard.common.model.SelectFileLabelProvider)1 SelectIncrementContentProvider (com.devonfw.cobigen.eclipse.wizard.common.model.SelectIncrementContentProvider)1 SimulatedCheckboxTreeViewer (com.devonfw.cobigen.eclipse.wizard.common.widget.SimulatedCheckboxTreeViewer)1 HashSet (java.util.HashSet)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 IBaseLabelProvider (org.eclipse.jface.viewers.IBaseLabelProvider)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 IContentProvider (org.eclipse.jface.viewers.IContentProvider)1 SashForm (org.eclipse.swt.custom.SashForm)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1