Search in sources :

Example 1 with SelectSingleFileDialog

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;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) SelectSingleFileDialog(org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with SelectSingleFileDialog

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();
    }
}
Also used : SelectSingleFileDialog(org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog) IFile(org.eclipse.core.resources.IFile) CatalogSet(org.eclipse.wst.xml.core.internal.catalog.CatalogSet) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Aggregations

IFile (org.eclipse.core.resources.IFile)2 SelectSingleFileDialog (org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog)2 CLabel (org.eclipse.swt.custom.CLabel)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 CatalogSet (org.eclipse.wst.xml.core.internal.catalog.CatalogSet)1 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)1