Search in sources :

Example 1 with MdwChoiceDialog

use of com.centurylink.mdw.plugin.designer.dialogs.MdwChoiceDialog in project mdw-designer by CenturyLinkCloud.

the class PackageConfigurationSection method createButtons.

private void createButtons(Composite parent) {
    buttonComposite = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    buttonComposite.setLayout(gl);
    GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
    buttonComposite.setLayoutData(gd);
    Group propBtnGroup = new Group(buttonComposite, SWT.NONE);
    propBtnGroup.setText("Properties");
    gl = new GridLayout();
    propBtnGroup.setLayout(gl);
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
    gd.verticalIndent = 15;
    propBtnGroup.setLayoutData(gd);
    // add prop
    Button addButton = new Button(propBtnGroup, SWT.PUSH | SWT.CENTER);
    addButton.setText("Add");
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    gridData.widthHint = 60;
    gridData.horizontalIndent = 3;
    addButton.setLayoutData(gridData);
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            propertyRows.add(new PropertyRow("new.property"));
            if (// first property added
            propertyRows.size() == 1)
                propertyRows.get(0).envValues.put("", "");
            tableViewer.setInput(propertyRows);
            updateModel();
            if (// first property added
            propertyRows.size() == 1)
                setSelection(workflowPackage);
        }
    });
    // delete prop
    Button deleteButton = new Button(propBtnGroup, SWT.PUSH | SWT.CENTER);
    deleteButton.setText("Delete");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    gridData.widthHint = 60;
    gridData.horizontalIndent = 3;
    deleteButton.setLayoutData(gridData);
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            PropertyRow row = (PropertyRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
            if (row != null)
                propertyRows.remove(row);
            tableViewer.setInput(propertyRows);
            updateModel();
        }
    });
    if (!workflowPackage.getProject().checkRequiredVersion(6)) {
        Group envBtnGroup = new Group(buttonComposite, SWT.NONE);
        envBtnGroup.setText("Environments");
        gl = new GridLayout();
        envBtnGroup.setLayout(gl);
        gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
        gd.verticalIndent = 10;
        envBtnGroup.setLayoutData(gd);
        // add env
        Button newEnvButton = new Button(envBtnGroup, SWT.PUSH | SWT.CENTER);
        newEnvButton.setText("Add...");
        gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
        gridData.widthHint = 60;
        gridData.horizontalIndent = 3;
        newEnvButton.setLayoutData(gridData);
        newEnvButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                MdwInputDialog inputDlg = new MdwInputDialog(getShell(), "Environment Name", false);
                inputDlg.setTitle("New Environment");
                if (inputDlg.open() == Dialog.OK) {
                    if (propertyRows.isEmpty())
                        propertyRows.add(new PropertyRow("new.property"));
                    propertyRows.get(0).envValues.put(inputDlg.getInput(), "");
                    tableViewer.setInput(propertyRows);
                    updateModel();
                    setSelection(workflowPackage);
                }
            }
        });
        // delete env
        Button deleteEnvButton = new Button(envBtnGroup, SWT.PUSH | SWT.CENTER);
        deleteEnvButton.setText("Delete...");
        gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
        gridData.widthHint = 60;
        gridData.horizontalIndent = 3;
        deleteEnvButton.setLayoutData(gridData);
        deleteEnvButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                List<String> envs = new ArrayList<>();
                for (PropertyRow propRow : propertyRows) {
                    for (String env : propRow.envValues.keySet()) {
                        if (!envs.contains(env))
                            envs.add(env);
                    }
                }
                MdwChoiceDialog choiceDlg = new MdwChoiceDialog(getShell(), "Environment to Remove", envs.toArray(new String[0]));
                choiceDlg.setTitle("Remove Environment");
                int res = choiceDlg.open();
                if (res != MdwChoiceDialog.CANCEL && !envs.isEmpty()) {
                    String choice = envs.get(res);
                    for (PropertyRow propRow : propertyRows) {
                        propRow.envValues.remove(choice);
                    }
                    updateModel();
                    setSelection(workflowPackage);
                }
            }
        });
    }
    // save
    saveButton = new Button(buttonComposite, SWT.PUSH | SWT.CENTER);
    saveButton.setText("Save");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    gridData.widthHint = 60;
    gridData.verticalIndent = 15;
    saveButton.setLayoutData(gridData);
    saveButton.setEnabled(dirty);
    saveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            saveMetaContent();
        }
    });
}
Also used : PropertyGroup(com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MdwChoiceDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwChoiceDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) MdwInputDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwInputDialog)

Aggregations

PropertyGroup (com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup)1 MdwChoiceDialog (com.centurylink.mdw.plugin.designer.dialogs.MdwChoiceDialog)1 MdwInputDialog (com.centurylink.mdw.plugin.designer.dialogs.MdwInputDialog)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)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 Group (org.eclipse.swt.widgets.Group)1