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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations