Composite mainComp = new Composite(parent, SWT.None);
mainComp.setLayout(new GridLayout());
mainComp.setLayoutData(new GridData(GridData.FILL_BOTH));
PixelConverter pixelConverter = new PixelConverter(mainComp);
// Remote path text field:
Label label = new Label(mainComp, SWT.NONE);
label.setText(Messages.PathMapperEntryDialog_2);
fRemotePathText = new Text(mainComp, SWT.BORDER);
fRemotePathText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
// System.out.println(fRemotePathText.getText());
ignorePathText.setText(fRemotePathText.getText());
validate();
}
});
GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
// layoutData.widthHint =
// pixelConverter.convertWidthInCharsToPixels(90);
fRemotePathText.setLayoutData(layoutData);
// Radio buttons group:
Composite typeSelectionGroup = new Composite(mainComp, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
typeSelectionGroup.setLayout(layout);
typeSelectionGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
// Workspace file:
fWorkspacePathBtn = new Button(typeSelectionGroup, SWT.RADIO);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 2;
fWorkspacePathBtn.setLayoutData(layoutData);
fWorkspacePathBtn.setText(Messages.PathMapperEntryDialog_3);
fWorkspacePathBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean enabled = fWorkspacePathBtn.getSelection();
fWorkspacePathText.setEnabled(enabled);
fWorkspacePathBrowseBtn.setEnabled(enabled);
fExternalPathText.setEnabled(!enabled);
fExternalPathBrowseBtn.setEnabled(!enabled);
ignorePathText.setEnabled(!enabled);
validate();
}
});
fWorkspacePathText = new Text(typeSelectionGroup, SWT.BORDER);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalIndent = pixelConverter
.convertWidthInCharsToPixels(1);
fWorkspacePathText.setLayoutData(layoutData);
fWorkspacePathText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validate();
}
});
fWorkspacePathBrowseBtn = new Button(typeSelectionGroup, SWT.NONE);
fWorkspacePathBrowseBtn.setText(Messages.PathMapperEntryDialog_4);
fWorkspacePathBrowseBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
WorkspaceBrowseDialog dialog = new WorkspaceBrowseDialog(
getShell());
if (dialog.open() == Window.OK) {
Object selectedElement = dialog.getSelectedElement();
fWorkspacePathText.setData(null);
if (selectedElement instanceof IResource) {
IResource resource = (IResource) selectedElement;
fWorkspacePathText.setData(Type.WORKSPACE);
fWorkspacePathText.setText(resource.getFullPath()
.toString());
} else if (selectedElement instanceof IBuildpathEntry) {
IBuildpathEntry includePathEntry = (IBuildpathEntry) selectedElement;
fWorkspacePathText.setData(includePathEntry
.getEntryKind() == IBuildpathEntry.BPE_VARIABLE ? Type.INCLUDE_VAR
: Type.INCLUDE_FOLDER);
if (includePathEntry.getEntryKind() == IBuildpathEntry.BPE_VARIABLE) {
IPath incPath = DLTKCore
.getResolvedVariablePath(includePathEntry
.getPath());
if (incPath != null) {
fWorkspacePathText.setText(incPath.toOSString());
}
} else {
fWorkspacePathText.setText(EnvironmentPathUtils
.getLocalPath(includePathEntry.getPath())
.toOSString());
}
} else if (selectedElement instanceof IPFile) {
IPFile ipFile = (IPFile) selectedElement;
IBuildpathEntry includePathEntry = ipFile.includePathEntry;
fWorkspacePathText.setData(includePathEntry
.getEntryKind() == IBuildpathEntry.BPE_VARIABLE ? Type.INCLUDE_VAR
: Type.INCLUDE_FOLDER);
fWorkspacePathText.setText(ipFile.file
.getAbsolutePath());
}
}
}
});
// External file:
fExternalPathBtn = new Button(typeSelectionGroup, SWT.RADIO);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 2;
fExternalPathBtn.setLayoutData(layoutData);
fExternalPathBtn.setText(Messages.PathMapperEntryDialog_5);
fExternalPathBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean enabled = fExternalPathBtn.getSelection();
fExternalPathText.setEnabled(enabled);
fExternalPathBrowseBtn.setEnabled(enabled);
fWorkspacePathText.setEnabled(!enabled);
fWorkspacePathBrowseBtn.setEnabled(!enabled);
ignorePathText.setEnabled(!enabled);
validate();
}
});
fExternalPathText = new Text(typeSelectionGroup, SWT.BORDER);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalIndent = pixelConverter
.convertWidthInCharsToPixels(1);
fExternalPathText.setLayoutData(layoutData);
fExternalPathText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validate();
}
});
fExternalPathBrowseBtn = new Button(typeSelectionGroup, SWT.NONE);
fExternalPathBrowseBtn.setText(Messages.PathMapperEntryDialog_6);
fExternalPathBrowseBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
String path = dialog.open();
if (path != null) {
fExternalPathText.setText(path);
}
}
});
ignoreMappingBtn = new Button(typeSelectionGroup, SWT.RADIO);
ignoreMappingBtn
.setText(Messages.PathMapperEntryDialog_18);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 2;
ignoreMappingBtn.setLayoutData(layoutData);
ignoreMappingBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean enabled = ignoreMappingBtn.getSelection();
fWorkspacePathText.setEnabled(!enabled);
fWorkspacePathBrowseBtn.setEnabled(!enabled);
fExternalPathText.setEnabled(!enabled);
fExternalPathBrowseBtn.setEnabled(!enabled);
ignorePathText.setEnabled(enabled);
// configurePathBtn.setEnabled(enabled);
validate();
}
});
ignorePathText = new Text(typeSelectionGroup, SWT.BORDER
| SWT.READ_ONLY);
ignorePathText.setEnabled(false);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
// layoutData.horizontalIndent = convertWidthInCharsToPixels(2);
layoutData.horizontalIndent = pixelConverter
.convertWidthInCharsToPixels(1);
layoutData.widthHint = convertWidthInCharsToPixels(70);
ignorePathText.setLayoutData(layoutData);
ignorePathText.setText(""); //$NON-NLS-1$