use of org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog in project webtools.sourceediting by eclipse.
the class AddNewCategoryDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
getShell().setText(dialogTitle);
Composite mainComposite = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout(2, false);
layout.marginTop = 10;
mainComposite.setLayout(layout);
mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridData data = new GridData();
data.widthHint = 400;
mainComposite.setLayoutData(data);
// Line 1, name
name = new Label(mainComposite, SWT.NONE);
name.setText(NAME_LABEL);
nameText = new Text(mainComposite, SWT.BORDER | SWT.SINGLE);
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (categoryName != null)
nameText.setText(categoryName);
PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, XSDEditorCSHelpIds.ADD_CATEGORY__NAME);
// Line 2, schema
schema = new Label(mainComposite, SWT.NONE);
schema.setText(SCHEMA_LABEL);
schemaDisplayer = new CLabel(mainComposite, SWT.BORDER | SWT.SINGLE);
schemaDisplayer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (source != null) {
if (fromCatalog)
schemaDisplayer.setImage(// $NON-NLS-1$
XSDEditorPlugin.getXSDImage("icons/xmlcatalog_obj.gif"));
else
schemaDisplayer.setImage(// $NON-NLS-1$
XSDEditorPlugin.getXSDImage("icons/XSDFile.gif"));
schemaDisplayer.setText(source);
}
PlatformUI.getWorkbench().getHelpSystem().setHelp(schemaDisplayer, XSDEditorCSHelpIds.ADD_CATEGORY__SCHEMA);
if (categoryName != null && source != null)
canOK = true;
// Line 3, schema selection buttons
Button hidden = new Button(mainComposite, SWT.NONE);
hidden.setVisible(false);
sourcesComposite = new Composite(mainComposite, SWT.NONE);
RowLayout sourcesLayout = new RowLayout();
sourcesComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
sourcesComposite.setLayout(sourcesLayout);
searchWorkspace = new Button(sourcesComposite, SWT.NONE);
searchWorkspace.setText(SELECT_FROM_WORKSPACE);
searchCatalog = new Button(sourcesComposite, SWT.NONE);
searchCatalog.setText(SELECT_FROM_CATALOG);
searchWorkspace.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// $NON-NLS-1$
final String XSD_FILE_EXTENSION = ".xsd";
SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true);
dialog.addFilterExtensions(new String[] { XSD_FILE_EXTENSION });
dialog.create();
dialog.setTitle(Messages._UI_LABEL_SELECT_XSD_FILE);
dialog.setMessage(Messages._UI_DESCRIPTION_CHOOSE_XSD_FILE);
if (dialog.open() == Window.OK) {
IFile appInfoSchemaFile = dialog.getFile();
if (appInfoSchemaFile != null) {
// remove leading slash from the value to avoid the
// whole leading slash ambiguity problem
String uri = appInfoSchemaFile.getFullPath().toString();
while (uri.startsWith("/") || uri.startsWith("\\")) {
// $NON-NLS-1$ //$NON-NLS-2$
uri = uri.substring(1);
}
appInfoSchemaLocation = uri.toString();
source = uri;
fromCatalog = false;
// $NON-NLS-1$ //$NON-NLS-2$
appInfoSchemaLocation = "file://" + Platform.getLocation().toString() + "/" + appInfoSchemaLocation;
// TODO... be careful how we construct the location
// UNIX related issues here
// $NON-NLS-1$
schemaDisplayer.setImage(XSDEditorPlugin.getXSDImage("icons/XSDFile.gif"));
schemaDisplayer.setText(uri);
// Enable the OK button if we should..
if (isCategoryNameValid) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
// $NON-NLS-1$
errDisplayer.setText("");
errDisplayer.setImage(null);
}
}
}
}
});
searchCatalog.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
SelectFromCatalogDialog dialog = new SelectFromCatalogDialog(getShell());
// dialog.open();
if (dialog.open() == Window.OK) {
appInfoSchemaLocation = dialog.getCurrentSelectionLocation();
source = dialog.getCurrentSelectionNamespace();
fromCatalog = true;
// $NON-NLS-1$
schemaDisplayer.setImage(XSDEditorPlugin.getXSDImage("icons/xmlcatalog_obj.gif"));
schemaDisplayer.setText(dialog.getCurrentSelectionNamespace());
// Enable the OK button if we should..
if (// $NON-NLS-1$
isCategoryNameValid && !appInfoSchemaLocation.equals("")) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
// $NON-NLS-1$
errDisplayer.setText("");
errDisplayer.setImage(null);
}
}
}
});
// TODO: Should be able to get the image from the XML plugin. Don't need
// to copy to XSDEditor icons folder like this.
// Composite errComp = new Composite(mainComposite, SWT.NONE);
// errComp.setBackground(org.eclipse.draw2d.ColorConstants.white);
// errComp.setLayout(new GridLayout());
errDisplayer = new CLabel(mainComposite, SWT.FLAT);
// errDisplayer.setText("abd");
GridData gd = new GridData(GridData.FILL_BOTH);
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 3;
errDisplayer.setLayoutData(gd);
// errComp.setLayoutData(gd);
// errDisplayer.setLayoutData(gd);
// errMsgContainer.setContent(errDisplayer);
nameText.addModifyListener(new ModifyListener() {
// track the nameText and enable/disable the OK button accordingly
public void modifyText(ModifyEvent e) {
categoryName = nameText.getText();
// name is in the invalid List
if (invalidNames != null) {
if (invalidNames.contains(categoryName.trim())) {
isCategoryNameValid = false;
getButton(IDialogConstants.OK_ID).setEnabled(false);
errDisplayer.setText(Messages._UI_ERROR_NAME_ALREADY_USED);
// $NON-NLS-1$
errDisplayer.setImage(XSDEditorPlugin.getXSDImage("icons/error_st_obj.gif"));
return;
}
}
// name is empty string
if (// $NON-NLS-1$
categoryName.equals("")) {
isCategoryNameValid = false;
getButton(IDialogConstants.OK_ID).setEnabled(false);
// $NON-NLS-1$
errDisplayer.setText("");
errDisplayer.setImage(null);
return;
}
/*
* Enable the Ok button if the location field AND the name field are not
* empty
*/
if (// $NON-NLS-1$
!categoryName.equals("")) {
isCategoryNameValid = true;
// $NON-NLS-1$
errDisplayer.setText("");
errDisplayer.setImage(null);
}
if (// $NON-NLS-1$
appInfoSchemaLocation != null && !appInfoSchemaLocation.equals("")) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
}
}
});
return parent;
}
use of org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog in project webtools.sourceediting by eclipse.
the class AdvancedOptionsDialog method invokeImportDialog.
protected void invokeImportDialog() {
SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true);
// $NON-NLS-1$ //$NON-NLS-2$
String[] extensions = { ".xmlcatalog", ".xml" };
dialog.addFilterExtensions(extensions);
dialog.create();
dialog.getShell().setText(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_TITLE);
dialog.setTitle(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_HEADING);
dialog.setMessage(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_MESSAGE);
dialog.setBlockOnOpen(true);
int rc = dialog.open();
if (rc == Window.OK) {
IFile file = dialog.getFile();
if (file != null) {
String fileName = file.getLocation().toFile().toURI().toString();
try {
CatalogSet tempResourceSet = new CatalogSet();
// $NON-NLS-1$
ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName);
workingUserCatalog.addEntriesFromCatalog(newCatalog);
} catch (Exception e) {
// TODO... give error message
}
}
close();
}
}
Aggregations