Search in sources :

Example 1 with TreeWithAddRemove

use of org.python.pydev.ui.editors.TreeWithAddRemove in project Pydev by fabioz.

the class PythonExistingSourceListGroup method createContents.

protected void createContents(Composite parent, final SelectionListener sourceChangeListener) {
    GridData gd;
    GridData data;
    Label l2 = new Label(parent, SWT.NONE);
    l2.setText("Project External Source Folders\n\nChoose external folders containing source that should be used for this project." + "\nThese folders will be automatically added to the PYTHONPATH\n(unless the 'Don't configure PYTHONPATH' option was selected).");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;
    l2.setLayoutData(gd);
    treeLinkTargets = new TreeWithAddRemove(parent, 0, null) {

        private String sourceFolders = "";

        @Override
        protected String getButtonLabel(int i) {
            switch(i) {
                case 0:
                    return "Add external source folder";
                default:
                    throw new AssertionError("Unexpected: " + i);
            }
        }

        @Override
        protected void customizeAddSomethingButton(Button addButton, final int nButton) {
            super.customizeAddSomethingButton(addButton, nButton);
            if (sourceChangeListener != null) {
                addButton.addSelectionListener(sourceChangeListener);
            }
        }

        @Override
        protected void customizeRemSourceFolderButton(Button buttonRem) {
            super.customizeRemSourceFolderButton(buttonRem);
            if (sourceChangeListener != null) {
                buttonRem.addSelectionListener(sourceChangeListener);
            }
        }

        @Override
        protected void handleAddButtonSelected(int nButton) {
            if (nButton == 0) {
                addItemWithDialog(new DirectoryDialog(getShell()));
                IPath selected = getSelectedFolder();
                if (selected != null) {
                    selectLinkTarget(selected);
                }
            } else {
                throw new AssertionError("Unexpected");
            }
        }

        @Override
        protected void handleRemove() {
            super.handleRemove();
            if (folderWasSelected()) {
                conflictCheck();
            }
        }

        private IPath getSelectedFolder() {
            if (!folderWasSelected()) {
                return null;
            }
            String linkTarget = sourceFolders.substring(sourceFolders.lastIndexOf('|') + 1);
            return Path.fromOSString(linkTarget);
        }

        private boolean folderWasSelected() {
            String newSourceFolders = StringUtils.leftAndRightTrim(treeLinkTargets.getTreeItemsAsStr(), '|');
            if (sourceFolders.equals(newSourceFolders)) {
                // cancelled
                return false;
            }
            sourceFolders = newSourceFolders;
            return true;
        }

        @Override
        protected String getImageConstant() {
            return UIConstants.SOURCE_FOLDER_ICON;
        }

        @Override
        protected int getNumberOfAddButtons() {
            return 1;
        }
    };
    data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    treeLinkTargets.setLayoutData(data);
}
Also used : TreeWithAddRemove(org.python.pydev.ui.editors.TreeWithAddRemove) IPath(org.eclipse.core.runtime.IPath) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 2 with TreeWithAddRemove

use of org.python.pydev.ui.editors.TreeWithAddRemove in project Pydev by fabioz.

the class TabVariables method createTabVariables.

private void createTabVariables(Map<String, String> initialVariables) {
    if (initialVariables == null) {
        initialVariables = new HashMap<String, String>();
    }
    TabItem tabItem = new TabItem(tabFolder, SWT.None);
    tabItem.setText("String Substitution Variables");
    tabItem.setImage(ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.VARIABLE_ICON)));
    Composite topComp = new Composite(tabFolder, SWT.None);
    topComp.setLayout(new GridLayout(1, false));
    GridData gd;
    GridData data;
    Label l2;
    l2 = new Label(topComp, SWT.None);
    l2.setText("String substitution variables are used to resolve:\n" + "  - source folders\n" + "  - external libraries\n" + "  - main module in launch configuration");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;
    l2.setLayoutData(gd);
    final Map<String, String> vars = initialVariables;
    treeVariables = new TreeWithAddRemove(topComp, 0, vars, true) {

        @Override
        protected String getImageConstant() {
            return UIConstants.VARIABLE_ICON;
        }

        @Override
        protected void handleAddButtonSelected(int nButton) {
            if (nButton == 0) {
                addItemWithDialog(new MapOfStringsInputDialog(getShell(), "Variable", "Enter the variable name/value.", vars) {

                    @Override
                    protected boolean isExistingKeyEdit() {
                        return false;
                    }
                });
            } else {
                throw new AssertionError("Unexpected (only 0 should be available)");
            }
        }

        @Override
        protected void handleEdit() {
            TreeItem[] selection = this.tree.getSelection();
            if (selection.length != 1) {
                return;
            }
            TreeItem treeItem = selection[0];
            if (treeItem == null) {
                return;
            }
            final String fixedKeyText = treeItem.getText(0);
            // Overridden because we want the key to be fixed.
            MapOfStringsInputDialog dialog = new MapOfStringsInputDialog(getShell(), "Variable", "Enter the variable name/value.", vars) {

                @Override
                protected org.eclipse.swt.widgets.Control createDialogArea(Composite parent) {
                    Control control = super.createDialogArea(parent);
                    this.keyField.setText(fixedKeyText);
                    this.keyField.setEditable(false);
                    this.valueField.setFocus();
                    String value = vars.get(fixedKeyText);
                    if (value == null) {
                        value = "";
                    }
                    this.valueField.setText(value);
                    return control;
                }

                @Override
                protected boolean isExistingKeyEdit() {
                    return true;
                }

                @Override
                protected String getInitialMessage() {
                    // it starts in a valid state
                    return null;
                }
            };
            if (dialog.open() == Window.OK) {
                Tuple<String, String> keyAndValueEntered = dialog.getKeyAndValueEntered();
                if (keyAndValueEntered != null) {
                    vars.put(keyAndValueEntered.o1, keyAndValueEntered.o2);
                    treeItem.setText(1, keyAndValueEntered.o2);
                }
            }
        }

        @Override
        protected String getButtonLabel(int i) {
            if (i != 0) {
                throw new RuntimeException("Expected only i==0. Received: " + i);
            }
            return "Add variable";
        }

        @Override
        protected int getNumberOfAddButtons() {
            return 1;
        }
    };
    data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    treeVariables.setLayoutData(data);
    tabItem.setControl(topComp);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) MapOfStringsInputDialog(org.python.pydev.ui.dialogs.MapOfStringsInputDialog) Control(org.eclipse.swt.widgets.Control) TreeWithAddRemove(org.python.pydev.ui.editors.TreeWithAddRemove) GridData(org.eclipse.swt.layout.GridData) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 3 with TreeWithAddRemove

use of org.python.pydev.ui.editors.TreeWithAddRemove in project Pydev by fabioz.

the class EditIgnoredCaughtExceptionsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    memento.readSettings();
    Composite area = (Composite) super.createDialogArea(parent);
    treeWithAddRemove = new TreeWithAddRemove(area, 0, map) {

        @Override
        protected void handleAddButtonSelected(int nButton) {
            throw new RuntimeException("not implemented: no add buttons");
        }

        @Override
        protected String getImageConstant() {
            return UIConstants.PUBLIC_ATTR_ICON;
        }

        @Override
        protected String getButtonLabel(int i) {
            throw new RuntimeException("not implemented: no add buttons");
        }

        @Override
        protected int getNumberOfAddButtons() {
            return 0;
        }
    };
    GridData data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    treeWithAddRemove.setLayoutData(data);
    treeWithAddRemove.fitToContents();
    return area;
}
Also used : TreeWithAddRemove(org.python.pydev.ui.editors.TreeWithAddRemove) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Point(org.eclipse.swt.graphics.Point)

Example 4 with TreeWithAddRemove

use of org.python.pydev.ui.editors.TreeWithAddRemove in project Pydev by fabioz.

the class PyProjectProperties method createTabExternalSourceFolders.

private void createTabExternalSourceFolders(String externalSourcePath) {
    TabItem tabItem = new TabItem(tabFolder, SWT.None);
    tabItem.setText("External Libraries");
    Composite topComp = new Composite(tabFolder, SWT.None);
    tabItem.setImage(ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.LIB_SYSTEM)));
    topComp.setLayout(new GridLayout(1, false));
    GridData gd;
    GridData data;
    Label l2;
    l2 = new Label(topComp, SWT.None);
    l2.setText("External libraries (source folders/zips/jars/eggs) outside of the workspace.\n\n" + "When using variables, the final paths resolved must be filesystem absolute.\n\n" + "Changes in external libraries are not monitored, so, the 'Force restore internal info'\ns" + "hould be used if an external library changes. ");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;
    l2.setLayoutData(gd);
    treeExternalLibs = new TreeWithAddRemove(topComp, 0, PythonNature.getStrAsStrItems(externalSourcePath)) {

        @Override
        protected String getImageConstant() {
            return UIConstants.LIB_SYSTEM;
        }

        @Override
        protected String getButtonLabel(int i) {
            switch(i) {
                case 0:
                    return "Add source folder";
                case 1:
                    return "Add zip/jar/egg";
                case 2:
                    return "Add based on variable";
                default:
                    throw new AssertionError("Unexpected: " + i);
            }
        }

        @Override
        protected void handleAddButtonSelected(int nButton) {
            if (nButton == 0) {
                addItemWithDialog(new DirectoryDialog(getShell()));
            } else if (nButton == 1) {
                addItemWithDialog(new FileDialog(getShell(), SWT.MULTI));
            } else if (nButton == 2) {
                addItemWithDialog(new InputDialog(getShell(), "Add path to resolve with variable", "Add path to resolve with variable in the format: ${VARIABLE}", "", null));
            } else {
                throw new AssertionError("Unexpected");
            }
        }
    };
    data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    treeExternalLibs.setLayoutData(data);
    tabItem.setControl(topComp);
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) TreeWithAddRemove(org.python.pydev.ui.editors.TreeWithAddRemove) GridData(org.eclipse.swt.layout.GridData) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 5 with TreeWithAddRemove

use of org.python.pydev.ui.editors.TreeWithAddRemove in project Pydev by fabioz.

the class PyProjectProperties method createTabProjectSourceFolders.

private void createTabProjectSourceFolders(String sourcePath) {
    TabItem tabItem = new TabItem(tabFolder, SWT.None);
    tabItem.setText("Source Folders");
    tabItem.setImage(ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.SOURCE_FOLDER_ICON)));
    Composite topComp = new Composite(tabFolder, SWT.None);
    topComp.setLayout(new GridLayout(1, false));
    GridData gd;
    GridData data;
    Label l2 = new Label(topComp, SWT.None);
    l2.setText("Project Source Folders (and zips/jars/eggs).\n\n" + "When using variables, the final paths resolved must be workspace-relative.");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;
    l2.setLayoutData(gd);
    treeSourceFolders = new TreeWithAddRemove(topComp, 0, PythonNature.getStrAsStrItems(sourcePath)) {

        @Override
        protected String getButtonLabel(int i) {
            switch(i) {
                case 0:
                    return "Add source folder";
                case 1:
                    return "Add zip/jar/egg";
                case 2:
                    return "Add based on variable";
                default:
                    throw new AssertionError("Unexpected: " + i);
            }
        }

        @Override
        protected void handleAddButtonSelected(int nButton) {
            if (nButton == 0) {
                addItemWithDialog(new ProjectFolderSelectionDialog(getShell(), project, true, "Choose source folders to add to PYTHONPATH"), project);
            } else if (nButton == 1) {
                addItemWithDialog(new ResourceSelectionDialog(getShell(), project, "Choose zip/jar/egg to add to PYTHONPATH"), project);
            } else if (nButton == 2) {
                addItemWithDialog(new InputDialog(getShell(), "Add path to resolve with variable", "Add path to resolve with variable in the format: ${VARIABLE}", "", null));
            } else {
                throw new AssertionError("Unexpected");
            }
        }

        @Override
        protected String getImageConstant() {
            return UIConstants.SOURCE_FOLDER_ICON;
        }
    };
    data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    treeSourceFolders.setLayoutData(data);
    tabItem.setControl(topComp);
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) ResourceSelectionDialog(org.eclipse.ui.dialogs.ResourceSelectionDialog) TreeWithAddRemove(org.python.pydev.ui.editors.TreeWithAddRemove) ProjectFolderSelectionDialog(org.python.pydev.ui.dialogs.ProjectFolderSelectionDialog) GridData(org.eclipse.swt.layout.GridData)

Aggregations

GridData (org.eclipse.swt.layout.GridData)5 TreeWithAddRemove (org.python.pydev.ui.editors.TreeWithAddRemove)5 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 GridLayout (org.eclipse.swt.layout.GridLayout)3 TabItem (org.eclipse.swt.widgets.TabItem)3 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)2 IPath (org.eclipse.core.runtime.IPath)1 Point (org.eclipse.swt.graphics.Point)1 Button (org.eclipse.swt.widgets.Button)1 Control (org.eclipse.swt.widgets.Control)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 ResourceSelectionDialog (org.eclipse.ui.dialogs.ResourceSelectionDialog)1 Tuple (org.python.pydev.shared_core.structure.Tuple)1 MapOfStringsInputDialog (org.python.pydev.ui.dialogs.MapOfStringsInputDialog)1 ProjectFolderSelectionDialog (org.python.pydev.ui.dialogs.ProjectFolderSelectionDialog)1