use of org.eclipse.swt.widgets.DirectoryDialog in project bndtools by bndtools.
the class WorkspaceLocationPart method createControl.
public Control createControl(final Composite parent) {
// Create Controls
group = new Group(parent, SWT.NONE);
group.setText("Location");
GridLayout layout = new GridLayout(3, false);
group.setLayout(layout);
File workspace = getUpdate();
if (workspace == null) {
final Button btnCreateInEclipseWorkspace = new Button(group, SWT.RADIO);
btnCreateInEclipseWorkspace.setText("Create in current Eclipse Workspace");
btnCreateInEclipseWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
Label lblEclipseWorkspace = new Label(group, SWT.NONE);
lblEclipseWorkspace.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
lblEclipseWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
final Button btnCreateExternal = new Button(group, SWT.RADIO);
btnCreateExternal.setText("Create in:");
final Text txtExternalLocation = new Text(group, SWT.BORDER);
txtExternalLocation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
final Button btnBrowseExternal = new Button(group, SWT.PUSH);
btnBrowseExternal.setText("Browse");
updateFields = new Runnable() {
@Override
public void run() {
btnCreateInEclipseWorkspace.setSelection(location.eclipseWorkspace);
btnCreateExternal.setSelection(!location.eclipseWorkspace);
txtExternalLocation.setText(location.externalPath != null ? location.externalPath : "");
}
};
updateEnablement = new Runnable() {
@Override
public void run() {
txtExternalLocation.setEnabled(!location.eclipseWorkspace);
btnBrowseExternal.setEnabled(!location.eclipseWorkspace);
}
};
// Load initial state
updateFields.run();
updateEnablement.run();
// Event listeners
final Listener locationListener = new Listener() {
@Override
public void handleEvent(Event ev) {
modifyLock.modifyOperation(new Runnable() {
@Override
public void run() {
setLocation(new LocationSelection(btnCreateInEclipseWorkspace.getSelection(), txtExternalLocation.getText()));
}
});
}
};
btnCreateExternal.addListener(SWT.Selection, locationListener);
btnCreateInEclipseWorkspace.addListener(SWT.Selection, locationListener);
txtExternalLocation.addListener(SWT.Modify, locationListener);
btnBrowseExternal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(parent.getShell());
String path = dialog.open();
if (path != null)
txtExternalLocation.setText(path);
}
});
} else {
final Label txtUpdateLocation = new Label(group, SWT.BORDER);
txtUpdateLocation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtUpdateLocation.setText("Update in current Bnd Workspace");
Label lblEclipseWorkspace = new Label(group, SWT.NONE);
lblEclipseWorkspace.setText(workspace.getAbsolutePath());
lblEclipseWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
setLocation(new LocationSelection(false, workspace.getAbsolutePath()));
}
return group;
}
use of org.eclipse.swt.widgets.DirectoryDialog in project bndtools by bndtools.
the class ProjectLocationGroup method createControl.
/**
* @wbp.parser.entryPoint
*/
public Control createControl(Composite parent) {
container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout(3, false));
btnUseBndWorkspace = new Button(container, SWT.CHECK);
btnUseBndWorkspace.setText("Use bnd workspace location");
btnUseBndWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
lblOtherLocation = new Label(container, SWT.NONE);
lblOtherLocation.setText("Location:");
txtLocation = new Text(container, SWT.BORDER);
txtLocation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtLocation.setText("[WorkspaceLocation]");
btnBrowse = new Button(container, SWT.NONE);
btnBrowse.setText("Browse...");
btnBrowse.setLayoutData(getButtonLayoutData(btnBrowse));
updateUI();
txtLocation.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
IPath oldValue = getLocation();
if (!useBndWorkspace) {
externalPath = txtLocation.getText();
}
IPath newValue = getLocation();
if (!programmaticChange) {
propSupport.firePropertyChange(PROP_LOCATION, oldValue, newValue);
validate();
}
}
});
btnUseBndWorkspace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IPath oldValue = getLocation();
useBndWorkspace = btnUseBndWorkspace.getSelection();
IPath newValue = getLocation();
if (!programmaticChange) {
propSupport.firePropertyChange(PROP_LOCATION, oldValue, newValue);
updateUI();
validate();
}
}
});
btnBrowse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(container.getShell());
dialog.setMessage("Choose a directory for the project contents:");
String directoryName = txtLocation.getText().trim();
if (directoryName == null || directoryName.length() == 0) {
String previous = JavaPlugin.getDefault().getDialogSettings().get(DIALOGSTORE_LAST_EXTERNAL_LOC);
if (previous != null)
directoryName = previous;
}
assert (directoryName != null);
if (directoryName.length() > 0) {
File path = new File(directoryName);
if (path.exists())
dialog.setFilterPath(directoryName);
}
String selected = dialog.open();
if (selected != null) {
IPath path = new Path(selected);
if (projectName != null && !projectName.equals(path.lastSegment()))
selected = path.append(projectName).toString();
txtLocation.setText(selected);
}
}
});
return container;
}
use of org.eclipse.swt.widgets.DirectoryDialog in project bndtools by bndtools.
the class IndexerWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
setControl(composite);
// Create controls
new Label(composite, SWT.NONE).setText(Messages.IndexerWizardPage_baseDir);
txtBaseDir = new Text(composite, SWT.BORDER);
newSpacer(composite);
Composite cmpButtonBar = new Composite(composite, SWT.NONE);
Button btnBrowseWorkspace = new Button(cmpButtonBar, SWT.PUSH);
btnBrowseWorkspace.setText(Messages.IndexerWizardPage_browse);
Button btnBrowseExternal = new Button(cmpButtonBar, SWT.PUSH);
btnBrowseExternal.setText(Messages.IndexerWizardPage_browseExternal);
new Label(composite, SWT.NONE).setText(Messages.IndexerWizardPage_resourcePattern);
txtResourcePattern = new Text(composite, SWT.BORDER);
ControlDecoration decorResourcePattern = new ControlDecoration(txtResourcePattern, SWT.LEFT | SWT.TOP, composite);
decorResourcePattern.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
decorResourcePattern.setMarginWidth(3);
decorResourcePattern.setDescriptionText(Messages.IndexerWizardPage_resourcePatternHelp);
decorResourcePattern.setShowHover(true);
decorResourcePattern.setShowOnlyOnFocus(false);
Label lblInputs = new Label(composite, SWT.NONE);
lblInputs.setText(Messages.IndexerWizardPage_inputs);
Table tblInputs = new Table(composite, SWT.MULTI | SWT.BORDER);
vwrInputs = new TableViewer(tblInputs);
vwrInputs.setContentProvider(ArrayContentProvider.getInstance());
vwrInputs.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object elem = cell.getElement();
if (elem instanceof Path) {
cell.setText(elem.toString());
cell.setImage(imgFile);
} else if (elem instanceof IStatus) {
IStatus status = (IStatus) elem;
cell.setText(status.getMessage());
if (status.getSeverity() == IStatus.ERROR)
cell.setImage(imgError);
else if (status.getSeverity() == IStatus.WARNING)
cell.setImage(imgWarning);
}
}
});
newSpacer(composite);
lblInputCount = new Label(composite, SWT.NONE);
Label lblOutputs = new Label(composite, SWT.NONE);
lblOutputs.setText(Messages.IndexerWizardPage_output);
Group grpOutput = new Group(composite, SWT.NONE);
new Label(grpOutput, SWT.NONE).setText(Messages.IndexerWizardPage_prefix);
txtOutputPrefix = new Text(grpOutput, SWT.BORDER);
newSpacer(grpOutput);
btnOutputPretty = new Button(grpOutput, SWT.RADIO);
btnOutputPretty.setText(Messages.IndexerWizardPage_prettyPrint);
newSpacer(grpOutput);
btnOutputCompressed = new Button(grpOutput, SWT.RADIO);
btnOutputCompressed.setText(Messages.IndexerWizardPage_compressed);
newSpacer(grpOutput);
lblOutputName = new Label(grpOutput, SWT.NONE);
// LAYOUT
GridLayout gl;
GridData gd;
gl = new GridLayout(2, false);
gl.horizontalSpacing = 10;
composite.setLayout(gl);
txtBaseDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
cmpButtonBar.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
gl = new GridLayout(2, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
cmpButtonBar.setLayout(gl);
btnBrowseWorkspace.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
btnBrowseExternal.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
txtResourcePattern.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
lblInputs.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
gd.heightHint = 120;
gd.widthHint = 100;
tblInputs.setLayoutData(gd);
lblInputCount.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
lblOutputs.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
grpOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
grpOutput.setLayout(new GridLayout(2, false));
txtOutputPrefix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
btnOutputCompressed.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
btnOutputPretty.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
lblOutputName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
// LOAD DATA
if (baseDir != null)
txtBaseDir.setText(baseDir.getAbsolutePath());
if (resourcePattern != null)
txtResourcePattern.setText(resourcePattern);
//$NON-NLS-1$
txtOutputPrefix.setText("index");
btnOutputCompressed.setSelection(outputStyle == IndexFormatStyle.COMPRESSED);
btnOutputPretty.setSelection(outputStyle == IndexFormatStyle.PRETTY_UNCOMPRESSED);
updateOutputFileName();
updateInputs();
// LISTENERS
txtBaseDir.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent me) {
String baseDirStr = txtBaseDir.getText();
baseDir = baseDirStr.isEmpty() ? null : new File(baseDirStr);
validate();
updateInputs();
}
});
txtResourcePattern.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent me) {
resourcePattern = txtResourcePattern.getText();
updateInputs();
}
});
btnBrowseWorkspace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
ContainerSelectionDialog containerDlg = new ContainerSelectionDialog(getShell(), root, false, Messages.IndexerWizardPage_selectBaseDir);
containerDlg.showClosedProjects(false);
if (containerDlg.open() == Window.OK) {
Object[] selection = containerDlg.getResult();
if (selection != null && selection.length > 0) {
IPath workspacePath = (IPath) selection[0];
IResource resource = root.findMember(workspacePath);
if (resource == null)
MessageDialog.openError(getShell(), "Error", "Could not find resource for path " + workspacePath);
else
txtBaseDir.setText(resource.getLocation().toString());
}
}
}
});
btnBrowseExternal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dirDialog = new DirectoryDialog(getShell());
dirDialog.setMessage(Messages.IndexerWizardPage_selectBaseDir);
String selectedPath = dirDialog.open();
if (selectedPath != null)
txtBaseDir.setText(selectedPath);
}
});
txtOutputPrefix.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent me) {
updateOutputFileName();
validate();
}
});
Listener outputRadioListener = new Listener() {
@Override
public void handleEvent(Event ev) {
outputStyle = btnOutputCompressed.getSelection() ? IndexFormatStyle.COMPRESSED : IndexFormatStyle.PRETTY_UNCOMPRESSED;
updateOutputFileName();
validate();
}
};
btnOutputCompressed.addListener(SWT.Selection, outputRadioListener);
btnOutputPretty.addListener(SWT.Selection, outputRadioListener);
validate();
}
Aggregations