diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards')
8 files changed, 0 insertions, 2324 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/NewXSDWizard.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/NewXSDWizard.java deleted file mode 100644 index 41cd29db42..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/NewXSDWizard.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.wizards; - -import java.io.ByteArrayInputStream; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.part.ISetSelectionTarget; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; - - -public class NewXSDWizard extends Wizard implements INewWizard { - private XSDNewFilePage newFilePage; - private IStructuredSelection selection; - private IWorkbench workbench; - - public NewXSDWizard() { - } - - public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) { - this.selection = aSelection; - this.workbench = aWorkbench; - - this.setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(XSDEditorPlugin.class, "icons/NewXSD.png")); - this.setWindowTitle(XSDEditorPlugin.getXSDString("_UI_WIZARD_CREATE_XSD_MODEL_TITLE")); - } - - public void addPages() { - newFilePage = new XSDNewFilePage(selection); - addPage(newFilePage); - } - - public boolean performFinish() { - IFile file = newFilePage.createNewFile(); - - // - // Get the xsd schema name from the full path name - // e.g. f:/b2b/po.xsd => schema name = po - // - IPath iPath = file.getFullPath().removeFileExtension(); - // String schemaName = iPath.lastSegment(); - String schemaName = iPath.lastSegment(); - String schemaPrefix = "tns"; - String prefixForSchemaNamespace = ""; - String schemaNamespaceAttribute = "xmlns"; - if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) { - // Added this if check before disallowing blank prefixes in the - // preferences... - // Can take this out. See also XSDEditor - if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) { - prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":"; - schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix(); - } - } - - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - if (charSet == null || charSet.trim().equals("")) { - charSet = "UTF-8"; - } - - String newContents = "<?xml version=\"1.0\" encoding=\"" + charSet + "\"?>\n"; - - String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace(); - newContents += "<" + prefixForSchemaNamespace + "schema " + schemaNamespaceAttribute + "=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"" + defaultTargetURI + schemaName + "\" xmlns:" + schemaPrefix + "=\"" + defaultTargetURI + schemaName + "\" elementFormDefault=\"qualified\">\n</" + prefixForSchemaNamespace + "schema>"; - - try { - byte[] bytes = newContents.getBytes(charSet); - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - - file.setContents(inputStream, true, false, null); - inputStream.close(); - } - catch (Exception e) { - // XSDEditorPlugin.getPlugin().getMsgLogger().write("Error writing - // default content:\n" + newContents); - // XSDEditorPlugin.getPlugin().getMsgLogger().write(e); - } - - if (file != null) { - revealSelection(new StructuredSelection(file)); - } - - openEditor(file); - - return true; - } - - private void revealSelection(final ISelection selection) { - if (selection != null) { - IWorkbench workbench2; - if (workbench == null) - { - workbench2 = XSDEditorPlugin.getPlugin().getWorkbench(); - } - else - { - workbench2 = workbench; - } - final IWorkbenchWindow workbenchWindow = workbench2.getActiveWorkbenchWindow(); - final IWorkbenchPart focusPart = workbenchWindow.getActivePage().getActivePart(); - if (focusPart instanceof ISetSelectionTarget) { - Display.getCurrent().asyncExec(new Runnable() { - public void run() { - ((ISetSelectionTarget) focusPart).selectReveal(selection); - } - }); - } - } - } - - public void openEditor(final IFile iFile) { - if (iFile != null) { - IWorkbench workbench2; - if (workbench == null) - { - workbench2 = XSDEditorPlugin.getPlugin().getWorkbench(); - } - else - { - workbench2 = workbench; - } - final IWorkbenchWindow workbenchWindow = workbench2.getActiveWorkbenchWindow(); - - Display.getDefault().asyncExec(new Runnable() { - public void run() { - try { - String editorId = null; - IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(iFile.getLocation().toOSString(), iFile.getContentDescription().getContentType()); - if (editor != null) { - editorId = editor.getId(); - } - workbenchWindow.getActivePage().openEditor(new FileEditorInput(iFile), editorId); - - } - catch (PartInitException ex) { - } - catch (CoreException ex) { - } - } - }); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexCompositionPage.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexCompositionPage.java deleted file mode 100644 index 1a1712d35b..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexCompositionPage.java +++ /dev/null @@ -1,947 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -// Based on version 1.12 of original xsdeditor -package org.eclipse.wst.xsd.ui.internal.wizards; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.util.ViewUtility; -import org.eclipse.xsd.XSDPatternFacet; - - - -/* --other regex features (eg case sensitivity, ^ or $, |, etc etc) --smarter model --better keyboard navigation --update list of tokens -*/ - -public class RegexCompositionPage extends WizardPage -{ - private static final boolean debug = false; - - /* The text representation of our pattern. */ - private StyledText value; - - /* The StyleRange used to color code the current parse error. */ - private StyleRange currentError; - - /* The regex terms we can form tokens from. */ - private Combo terms; - - /* The checkbox for activating auto-escape mode. */ - private Button escapeCheckbox; - - /* On/off status of auto-escape mode. */ - private boolean autoEscapeStatus; - - /* The Add Token button. */ - private Button add; - - - // The following controls are used in the occurrence selection group - - private Text repeatValue; - - private Text rangeMinValue; - private Text rangeMaxValue; - private Label rangeToLabel; - - private Button singleRadio; - private Button starRadio; - private Button plusRadio; - private Button optionalRadio; - private Button repeatRadio; - private Button rangeRadio; - - - // The following variables used as part of the model. - - /* Our pattern. */ - private XSDPatternFacet pattern; - - /* Model used to store the current token. */ - private RegexNode node; - - /* The flags passed to the new RegularExpression object. Default value includes: - X = XMLSchema mode */ - private String regexFlags = "X"; - - - /* Is the current regex token valid? */ - private boolean isValidToken; - - /* The label used to indicate the value's caret position when it looses focus. */ - private Label caretLabel; - - /* The pixel offsets needed to align the label icon with the caret location. - These are dependent on the icon used. */ - private static final int CARET_LABEL_X_OFFSET = -3; - private static final int CARET_LABEL_Y_OFFSET = 19; - - - /* Enumerated constants for specifying the type of an error message. */ - private static final int TOKEN = 0; - private static final int SELECTION = 1; - private static final int PARSE = 2; - - private static final int NUM_ERROR_MESSAGE_TYPES = 3; - - /* The current error message for each type of error. A value of null indicates no message. - The array is indexed according to the above constants. - */ - private String[] currentErrorMessages; - - - public RegexCompositionPage(XSDPatternFacet pattern) - { - super(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_COMPOSITION_PAGE_TITLE")); - this.pattern = pattern; - - setTitle(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_COMPOSITION_PAGE_TITLE")); - setDescription(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_COMPOSITION_PAGE_DESCRIPTION")); - } - - public void createControl(Composite parent) - { - // Set up our model and validator - node = new RegexNode(); - - isValidToken = true; - - currentErrorMessages = new String[NUM_ERROR_MESSAGE_TYPES]; - - // The main composite - Composite composite= new Composite(parent, SWT.NONE); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, XSDEditorCSHelpIds.REGEX_WIZARD_PAGE); - composite.setLayout(new GridLayout()); - - - // The composite for the token combo box, label, and auto-escape checkbox - Composite tokenComposite = new Composite (composite, SWT.NONE); - GridLayout tokenCompositeLayout = new GridLayout(); - tokenCompositeLayout.numColumns = 3; - tokenCompositeLayout.marginWidth = 0; - tokenComposite.setLayout(tokenCompositeLayout); - - - new Label(tokenComposite, SWT.LEFT).setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TOKEN_LABEL")); - - terms = new Combo(tokenComposite, SWT.DROP_DOWN); - PlatformUI.getWorkbench().getHelpSystem().setHelp(terms, XSDEditorCSHelpIds.REGEX_TOKEN_CONTENTS); - for (int i = 0; i < RegexNode.getNumRegexTerms(); i++) - { - terms.add(RegexNode.getRegexTermText(i)); - } - terms.addListener(SWT.Modify, new ComboListener()); - terms.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_TERMS")); - - escapeCheckbox = new Button(tokenComposite, SWT.CHECK); - escapeCheckbox.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_AUTO_ESCAPE_CHECKBOX_LABEL")); - escapeCheckbox.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_AUTO_ESCAPE_CHECKBOX")); - escapeCheckbox.addSelectionListener(new CheckboxListener()); - autoEscapeStatus = false; - - - // Set up the composites pertaining to the selection of occurrence quantifiers - - Group occurrenceSelectionArea = new Group(composite, SWT.NONE); - occurrenceSelectionArea.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_OCCURENCE_LABEL")); - PlatformUI.getWorkbench().getHelpSystem().setHelp(occurrenceSelectionArea, XSDEditorCSHelpIds.REGEX_WIZARD_PAGE); - GridLayout selectionAreaLayout = new GridLayout(); - selectionAreaLayout.numColumns = 2; - occurrenceSelectionArea.setLayout(selectionAreaLayout); - - occurrenceSelectionArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Listener used for all of the text fields - TextListener textListener = new TextListener(); - - - // Add the radio buttons - RadioSelectListener radioSelectListener = new RadioSelectListener(); - - singleRadio = addOccurenceRadioButton(RegexNode.SINGLE, occurrenceSelectionArea, radioSelectListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(singleRadio, XSDEditorCSHelpIds.REGEX_JUST_ONCE); - ViewUtility.createHorizontalFiller(occurrenceSelectionArea, 1); - - starRadio = addOccurenceRadioButton(RegexNode.STAR, occurrenceSelectionArea, radioSelectListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(starRadio, XSDEditorCSHelpIds.REGEX_ZERO_OR_MORE); - ViewUtility.createHorizontalFiller(occurrenceSelectionArea, 1); - - plusRadio = addOccurenceRadioButton(RegexNode.PLUS, occurrenceSelectionArea, radioSelectListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(plusRadio, XSDEditorCSHelpIds.REGEX_ONE_OR_MORE); - ViewUtility.createHorizontalFiller(occurrenceSelectionArea, 1); - - optionalRadio = addOccurenceRadioButton(RegexNode.OPTIONAL, occurrenceSelectionArea, radioSelectListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(optionalRadio, XSDEditorCSHelpIds.REGEX_OPTIONAL); - ViewUtility.createHorizontalFiller(occurrenceSelectionArea, 1); - - repeatRadio = addOccurenceRadioButton(RegexNode.REPEAT, occurrenceSelectionArea, radioSelectListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(repeatRadio, XSDEditorCSHelpIds.REGEX_REPEAT_RADIO); - - repeatValue = new Text(occurrenceSelectionArea, SWT.SINGLE | SWT.BORDER); - repeatValue.addListener(SWT.Modify, textListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(repeatValue, XSDEditorCSHelpIds.REGEX_REPEAT_FIELD); - repeatValue.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_REPEAT")); - repeatValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - setEnabledStatus(RegexNode.REPEAT, false); - - rangeRadio = addOccurenceRadioButton(RegexNode.RANGE, occurrenceSelectionArea, radioSelectListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(rangeRadio, XSDEditorCSHelpIds.REGEX_RANGE_RADIO); - - // Add text fields and labels for specifying the range - Composite rangeWidgets = new Composite(occurrenceSelectionArea, SWT.NONE); - GridLayout gridLayout = new GridLayout(3, false); - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 0; - rangeWidgets.setLayout(gridLayout); - rangeWidgets.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - rangeMinValue = new Text(rangeWidgets, SWT.SINGLE | SWT.BORDER); - rangeMinValue.addListener(SWT.Modify, textListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(rangeMinValue, XSDEditorCSHelpIds.REGEX_RANGE_MINIMUM_FIELD); - rangeMinValue.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_MIN")); - rangeMinValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - rangeToLabel = new Label(rangeWidgets, SWT.NONE); - rangeToLabel.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TO_LABEL")); - - rangeMaxValue = new Text(rangeWidgets, SWT.SINGLE | SWT.BORDER); - rangeMaxValue.addListener(SWT.Modify, textListener); - rangeMaxValue.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_MAX")); - PlatformUI.getWorkbench().getHelpSystem().setHelp(rangeMaxValue, XSDEditorCSHelpIds.REGEX_RANGE_MAXIMUM_FIELD); - rangeMaxValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - setEnabledStatus(RegexNode.RANGE, false); - - singleRadio.setSelection(true); - - // The add button - add = new Button(composite, SWT.PUSH); - add.addSelectionListener(new ButtonSelectListener()); - add.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_ADD_BUTTON_LABEL")); - PlatformUI.getWorkbench().getHelpSystem().setHelp(add, XSDEditorCSHelpIds.REGEX_ADD_BUTTON); - add.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_ADD_BUTTON")); - - - Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); - separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - - // Our main text box - - Label valueLabel= new Label(composite, SWT.LEFT); - valueLabel.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_CURRENT_REGEX_LABEL")); - - value = new StyledText(composite, SWT.SINGLE | SWT.BORDER); - value.addListener(SWT.Modify, textListener); - value.addListener(SWT.Selection, textListener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(value, XSDEditorCSHelpIds.REGEX_CURRENT_VALUE); - value.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_CURRENT_REGEX")); - value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - value.setFocus(); - - // StyleRange used for highlighting parse errors - currentError = new StyleRange(); - currentError.length = 1; - currentError.foreground = parent.getDisplay().getSystemColor(SWT.COLOR_RED); - - // The caret label - caretLabel = new Label(composite, SWT.LEFT); - caretLabel.setImage(XSDEditorPlugin.getXSDImage("icons/RegexWizardArrow.gif")); - caretLabel.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_CARET_LABEL")); - setShowCaretLabel(true); - - value.addFocusListener(new TextFocusListener()); - - terms.select(0); - - - setControl(composite); - } - - - public void setVisible(boolean visible) - { - super.setVisible(visible); - - value.setText(pattern.getLexicalValue()); - value.setCaretOffset(value.getCharCount()); - } - - public void dispose() - { - super.dispose(); - } - - - /** - * Sets the visible status of caretLabel to status. If status is true, then we also update the position - * of caretLabel in one of two ways. If there is no active selection in value, we set caretLabel's - * position to correspond with the position of the actual caret. Alternatively, if there is an active selection - * in value, we set caretLabel's position to the beginning of the selection. - * - * @param The new visibility status of caretLabel. - */ - private void setShowCaretLabel(boolean status) - { - if (status) - { - - int offset; - - if (value.getSelectionText().equals("")) - { - offset = value.getCaretOffset(); - } - else - { - offset = value.getSelection().x; - } - - Point p = value.getLocationAtOffset(offset); - - p.x += value.getLocation().x; - p.y = value.getLocation().y; - - // Place the label under value, and make sure it is aligned with the caret. - // The offsets are dependent on the icon used. - p.x += CARET_LABEL_X_OFFSET; - p.y += CARET_LABEL_Y_OFFSET; - - if (debug) - { - System.out.println("POINT: " + p); //$NON-NLS-1$ - } - - caretLabel.setLocation(p); - caretLabel.setVisible(true); - } - else - { - caretLabel.setVisible(false); - } - } - - - /** - * Adds a new radio button to Composite c with SelectionListener l. The text of the button is the String associated with - * quantifier. - * - * @param quantifier The desired quantifier, as enumerated in RegexNode. - * @param c The Composite to add the buttons to (normally occurrenceRadioButtons). - * @param l The SelectionListener (normally radioSelectionListener). - * @return The newly created button. - */ - private Button addOccurenceRadioButton(int quantifier, Composite c, SelectionListener l) - { - Button result = new Button(c, SWT.RADIO); - result.setText(RegexNode.getQuantifierText(quantifier)); - result.addSelectionListener(l); - return result; - } - - - /** - * Validates the regex in value. If the regex is valid, clears the Wizard's error message. If it's not valid, - * sets the Wizard's error message accordingly. - * - * @return Whether the regex is valid. - */ - private boolean validateRegex() - { - - boolean isValid; - try - { - // We validate the regex by checking whether we get a ParseException. - // By default, we assume that it's valid unless we determine otherwise. - isValid = true; - displayRegexErrorMessage(null); - value.setStyleRange(null); - - Pattern.compile(value.getText()); - } - catch (PatternSyntaxException pe) - { - isValid = false; - displayRegexErrorMessage(pe.getMessage()); - - // An off-by-one bug in the xerces regex parser will sometimes return a location for the parseError that - // is off the end of the string. If this is the case, then we want to highlight the last character. - if (pe.getIndex() >= value.getText().length()) - { - currentError.start = value.getText().length() - 1; - } - else - { - currentError.start = pe.getIndex(); - } - - if (debug) - { - System.out.println("Parse Error location: " + pe.getIndex()); //$NON-NLS-1$ - System.out.println("currentError.start: " + currentError.start); //$NON-NLS-1$ - } - - value.setStyleRange(currentError); - - } - - // Another bug in the xerces parser will sometimes throw a RuntimeException instead of a ParseException. - // When we get a RuntimeException, we aren't provided with the additional information we need to highlight - // the parse error. So, we merely report that there is an error. - catch (RuntimeException re) - { - displayRegexErrorMessage(""); - value.setStyleRange(null); - isValid = false; - } - - setPageComplete(isValid); - return isValid; - } - - - /** - * Manages the display of error messages. - * Sets the error message for type to errorMessage. If errorMessage != null, then we set the Wizard's error message - * to errorMessage. If errorMessage == null, then we check whether we have a pending message of another type. - * If we do, then it is displayed as the Wizard's error message. If we don't, then the Wizard's error message field - * is cleared. - * - * @param errorMessage The text of the new error message. A value of null indicates that the error message should - * be cleared. - * @param type The error type, one of PARSE, TOKEN, or SELECTION. - */ - private void displayErrorMessage(String errorMessage, int type) - { - String messageToDisplay = null; - - - currentErrorMessages[type] = errorMessage; - - messageToDisplay = errorMessage; - - for (int i = 0; i < NUM_ERROR_MESSAGE_TYPES; i++) - { - if (messageToDisplay != null) - { - break; - } - messageToDisplay = currentErrorMessages[i]; - } - - setErrorMessage(messageToDisplay); - } - - - /** - * Sets the Wizard's error message to message, preceded by a standard prefix. - * - * @param message The new error message (or null to clear it). - */ - private void displayRegexErrorMessage (String errorMessage) - { - if (errorMessage == null) - { - displayErrorMessage(null, PARSE); - } - else - { - if (errorMessage.trim().equals("")) // when there is no error message available. - { - displayErrorMessage(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_REGEX_ERROR"), - PARSE); - } - else - { - displayErrorMessage(errorMessage, PARSE); - } - } - } - - - /** - * Updates the token status. Sets isValidToken to status && the status of the other error type. - * If status is true, we clear the wizard's error message for this type; if it is false, we set it to errorMessage. - * - * @param status The new isValidToken value. - * @param errorMessage The new error message. - * @param type The type of the error (either TOKEN or SELECTION). - */ - private void setTokenStatus (boolean status, String errorMessage, int type) - { - boolean otherTypeStatus = (type == TOKEN) ? - currentErrorMessages[SELECTION] == null : - currentErrorMessages[TOKEN] == null; - - isValidToken = status && otherTypeStatus; - add.setEnabled(isValidToken); - - if (status) - { - displayErrorMessage(null, type); - } - else - { - if (errorMessage != null && errorMessage.trim().equals("")) // when there is no error message available. - { - displayErrorMessage(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_TOKEN_ERROR"), - type); - } - else - { - displayErrorMessage(errorMessage, type); - } - } - } - - - /** - * Updates the token status. Sets isValidToken to status && the status of the other error type. - * Also clears the wizard's error message for this type. - * Usually used to set isValidToken to true. - * - * @param status The new isValidToken value. - * @param type The type of the error (either TOKEN or SELECTION). - */ - private void setTokenStatus(boolean status, int type) - { - setTokenStatus(status, null, type); - } - - - - /** - * Sets the enabled status of the text fields and labels associated with the specified quantifier. - * If status is true, then fields and labels associated with other quantifiers are disabled. - * @param quantifier The quantifier whose elements' enabled status we wish to change - * (as enumerated in RegexNode). - * @param status The new status of the elements. If true, then all elements associated with other buttons - * are disabled. - */ - private void setEnabledStatus(int quantifier, boolean status) - { - switch (quantifier) - { - - case RegexNode.REPEAT: - repeatValue.setEnabled(status); - if (status) - { - rangeMinValue.setEnabled(false); - rangeMaxValue.setEnabled(false); - rangeToLabel.setEnabled(false); - } - break; - - case RegexNode.RANGE: - rangeMinValue.setEnabled(status); - rangeMaxValue.setEnabled(status); - rangeToLabel.setEnabled(status); - if (status) - { - repeatValue.setEnabled(false); - } - break; - - } - } - - /** - * Checks to see if there is a selection in value. If there is not, we set the Wizard's error message accordingly. - * If there is, we update the contents of node. If "Current Selection" is not the current token, then - * we clear the Selection error message. - */ - private void updateCurrentSelectionStatus() - { - if (terms.getSelectionIndex() == RegexNode.SELECTION) - { - String selection = value.getSelectionText(); - if (selection.equals("")) - { - setTokenStatus(false, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_SELECTION_ERROR"), SELECTION); - } - else - { - setTokenStatus(true, SELECTION); - node.setContents(selection); - node.setHasParens(true); - } - } - else - { - setTokenStatus(true, SELECTION); - } - } - - /** - * Updates the enabled status of the auto-escape checkbox. If status is true, we enable the checkbox, and - * set its selection status and node's auto-escape status to the value of autoEscapeStatus. If status is - * false, then we disable and deselect the checkbox, and set node's status to false. - * - * @param status The new enabled status. - */ - private void setEscapeCheckboxEnabledStatus(boolean status) - { - if (status) - { - escapeCheckbox.setEnabled(true); - escapeCheckbox.setSelection(autoEscapeStatus); - node.setAutoEscapeStatus(autoEscapeStatus); - } - else - { - escapeCheckbox.setEnabled(false); - escapeCheckbox.setSelection(false); - node.setAutoEscapeStatus(false); - } - } - - - /** - * Returns the current regex flags. - */ - String getFlags() - { - return regexFlags; - } - - /** - * Returns the current XSDPattern model. - */ - XSDPatternFacet getPattern() - { - return pattern; - } - - - /** - * Returns a string consisting of the values of min, max, and repeat stored in node. - * Used for debugging purposes only. - */ - private String getAllFieldValues() - { - String result = ""; - result += "Min: " + node.getMin() + "\n"; - result += "Max: " + node.getMax() + "\n"; - result += "Repeat: " + node.getRepeat() + "\n"; - result += "\n"; - return result; - } - - - /* Listener for the add button. */ - class ButtonSelectListener implements SelectionListener - { - public void widgetDefaultSelected(SelectionEvent e) - { - } - - // Precondition: isValidToken == true - public void widgetSelected(SelectionEvent e) - { - if (!isValidToken) // should never happen - { - return; - } - - // Whether there is anything selected in value. - boolean isActiveSelection = value.getSelectionCount() != 0; - - value.insert(node.toString()); - - if (terms.getSelectionIndex() == RegexNode.SELECTION) - { - updateCurrentSelectionStatus(); - } - - // If nothing is selected, then we need to advance the caret location. - if (!isActiveSelection) - { - value.setCaretOffset(value.getCaretOffset() + node.toString().length()); - } - - value.setFocus(); - - } - - } - - - /* Listener for the terms combo box. */ - class ComboListener implements Listener - { - public void handleEvent(Event e) - { - - updateCurrentSelectionStatus(); - - // If the user has typed in a token - if (terms.getSelectionIndex() == -1) - { - setEscapeCheckboxEnabledStatus(true); - node.setContents(terms.getText()); - node.setHasParens(true); - - - if (debug) - { - System.out.println(terms.getText()); - } - - } - else if (terms.getSelectionIndex() == RegexNode.SELECTION) - { - setEscapeCheckboxEnabledStatus(false); - } - else - { - node.setContents(RegexNode.getRegexTermValue(terms.getSelectionIndex())); - node.setHasParens(false); - setEscapeCheckboxEnabledStatus(false); - } - } - } - - - /* Listener for enabling/disabling caretLabel. */ - class TextFocusListener implements FocusListener - { - public void focusGained(FocusEvent e) - { - setShowCaretLabel(false); - } - public void focusLost(FocusEvent e) - { - setShowCaretLabel(true); - } - } - - - - /* Listener for the text fields. */ - class TextListener implements Listener - { - public void handleEvent (Event e) - { - - if (debug) - { - System.out.println("Inside TextListener handler"); //$NON-NLS-1$ - System.out.println(e); - System.out.println(getAllFieldValues()); - } - - - if ( (e.widget == value) && (e.type == SWT.Modify) ) - { - pattern.setLexicalValue(value.getText()); - validateRegex(); - } - - else if (e.widget == value && e.type == SWT.Selection) - { - if (terms.getSelectionIndex() == RegexNode.SELECTION) - { - updateCurrentSelectionStatus(); - } - } - - else if (e.widget == rangeMinValue) - { - boolean isValid = node.setMin(rangeMinValue.getText()); - - if (isValid) - { - setTokenStatus(true, null, TOKEN); - } - else - { - setTokenStatus(false, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_MIN_ERROR_SUFFIX"), TOKEN); - } - } - - else if (e.widget == rangeMaxValue) - { - boolean isValid = node.setMax(rangeMaxValue.getText()); - - if (node.getMin() == RegexNode.EMPTY) - { - setTokenStatus(false, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_MISSING_MIN_ERROR_SUFFIX"), TOKEN); - } - else if (isValid) - { - setTokenStatus(true, null, TOKEN); - } - else - { - setTokenStatus(false, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_MAX_ERROR_SUFFIX"), TOKEN); - } - } - - else // (e.widget == repeatValue) - { - boolean isValid = node.setRepeat(repeatValue.getText()); - if (isValid) - { - setTokenStatus(true, null, TOKEN); - } - else - { - setTokenStatus(false, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_REPEAT_ERROR_SUFFIX"), TOKEN); - } - } - } - } - - /* Listener for the auto-escape checkbox. */ - class CheckboxListener implements SelectionListener - { - public void widgetDefaultSelected(SelectionEvent e) - { - } - - public void widgetSelected(SelectionEvent e) - { - boolean newStatus = !autoEscapeStatus; - node.setAutoEscapeStatus(newStatus); - autoEscapeStatus = newStatus; - - if (debug) - { - System.out.println("AutoEscape Status: " + node.getAutoEscapeStatus()); //$NON-NLS-1$ - } - } - - } - - - /* Listener for the radio buttons. */ - class RadioSelectListener implements SelectionListener - { - public void widgetDefaultSelected(SelectionEvent e) - { - } - - public void widgetSelected(SelectionEvent e) - { - if (debug) - { - System.out.println(getAllFieldValues()); - } - - - int currentQuantifier = getQuantifier(e); - - node.setQuantifier(currentQuantifier); - - switch (currentQuantifier) - { - case RegexNode.SINGLE: - case RegexNode.STAR: - case RegexNode.PLUS: - case RegexNode.OPTIONAL: - setEnabledStatus(RegexNode.REPEAT, false); - setEnabledStatus(RegexNode.RANGE, false); - setTokenStatus(true, TOKEN); - break; - - case RegexNode.REPEAT: - setEnabledStatus(RegexNode.REPEAT, true); - setTokenStatus(node.hasValidRepeat(), XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_REPEAT_ERROR_SUFFIX"), TOKEN); - repeatValue.setFocus(); - break; - - case RegexNode.RANGE: - setEnabledStatus(RegexNode.RANGE, true); - String error = (node.hasValidMin()) ? - XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_MAX_ERROR_SUFFIX") : - XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_INVALID_MIN_ERROR_SUFFIX"); - - setTokenStatus( node.hasValidMin() && node.hasValidMax(), error, TOKEN); - rangeMinValue.setFocus(); - break; - } - } - - private int getQuantifier(SelectionEvent e) - { - - if (e.widget == singleRadio) - { - return RegexNode.SINGLE; - } - - else if (e.widget == starRadio) - { - return RegexNode.STAR; - } - - else if (e.widget == plusRadio) - { - return RegexNode.PLUS; - } - - else if (e.widget == optionalRadio) - { - return RegexNode.OPTIONAL; - } - - else if (e.widget == repeatRadio) - { - return RegexNode.REPEAT; - } - - else if (e.widget == rangeRadio) - { - return RegexNode.RANGE; - } - - else // can't get here - { - return RegexNode.EMPTY; - } - } - } - - public String getValue() - { - return value.getText(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexNode.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexNode.java deleted file mode 100644 index 64bbebcc07..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexNode.java +++ /dev/null @@ -1,421 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.wizards; - -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; - - -class RegexNode -{ - private String contents; - private int min; - private int max; - private int repeat; - private int quantifier; - private boolean hasParens; - private boolean autoEscapeStatus; - - - /* Quantifiers. */ - public static final int SINGLE = 0; - public static final int STAR = 1; - public static final int PLUS = 2; - public static final int OPTIONAL = 3; - public static final int REPEAT = 4; - public static final int RANGE = 5; - - /* Regex quantifiers. First column is the on-screen textual representation, second column is the - on-screen regex representation. The two are concatenated together to form the on-screen - representation. - Indexing of this array must correspond to the values of the quantifier constants above. - */ - private static final String[][] regexQuantifiers = - { - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_QUANTIFIER_SINGLE"), "" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_QUANTIFIER_STAR"), "*" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_QUANTIFIER_PLUS"), "+" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_QUANTIFIER_OPTIONAL"), "?" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_QUANTIFIER_REPEAT"), "" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_QUANTIFIER_RANGE"), "" }, - }; - - - /* Regex tokens. First column is the on-screen representation, second column is the regex representation. - More tokens can be added, but it is assumed that "Current Selection" is the last element in the array. - If this is not the case, then the value of the SELECTION constant below will need to be changed - accordingly. - Also note that because these are java Strings, backslashes must be escaped (this is only relevant to the - second column of the array). - */ - private static final String[][] regexTerms = - { - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_ANY_CHAR"), "." }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_ALPHANUMERIC_CHAR"), "\\w" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_WHITESPACE"), "\\s" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_DIGIT"), "\\d" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_UPPER"), "[A-Z]" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_LOWER"), "[a-z]" }, - { XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TERM_SELECTION"), "" }, - }; - - /* Token enumerated constants. */ - - // SELECTION must correspond to the index in regexTerms of "Current Selection". This is assumed to be - // the last element. - public static final int SELECTION = regexTerms.length - 1; - - public static final int EMPTY = -1; - - /* - The metacharacters recognized by XML Schema. - Note that the double backslash ("\\") actually represents an escaped single backslash character ("\"). - */ - private static final String metacharacters = ".\\?*+{}()[]"; - - - public static String getRegexTermText(int i) - { - if (i == SELECTION) - { - return regexTerms[i][0]; - } - else - { - return regexTerms[i][0] + " ( " + regexTerms[i][1] + " )"; - } - } - - public static String getRegexTermValue(int i) - { - if (i == SELECTION) // shouldn't happen - { - return ""; - } - else - { - return regexTerms[i][1]; - } - } - - public static int getNumRegexTerms() - { - return regexTerms.length; - } - - public static String getQuantifierText(int i) - { - String result = regexQuantifiers[i][0]; - - if (!regexQuantifiers[i][1].equals("")) - { - result += " ( "; - result += regexQuantifiers[i][1]; - result += " )"; - } - - return result; - } - - public RegexNode() - { - this.contents = ""; - this.quantifier = SINGLE; - this.min = EMPTY; - this.max = EMPTY; - this.repeat = EMPTY; - this.hasParens = false; - - } - - - public String getContents() - { - return contents; - } - - public void setContents(String contents) - { - this.contents = contents; - } - - - public int getQuantifier() - { - return quantifier; - } - - public void setQuantifier(int quantifier) - { - this.quantifier = quantifier; - } - - - public int getMin() - { - return min; - } - - public void setMin(int min) - { - this.min = min; - } - - /** - * Sets this.min to the integer representation of min iff min is a valid value (i.e. greater than 0). - * Sets this.min to EMPTY if it is not. - * - * @param min The new min value - * @returns Whether min was a valid value - */ - public boolean setMin(String min) - { - this.min = convertToInt(min); - - // min > max is an invalid case, unless max is EMPTY (since EMPTY == -1). - if ( (this.max != EMPTY) && (this.min > this.max) ) - { - return false; - } - - return (this.min >= 0); - } - - - public int getMax() - { - return max; - } - - public void setMax(int max) - { - this.max = max; - } - - /** - * Sets this.max to the integer representation of max iff max is a valid value (i.e. greater than 0). - * Sets this.max to EMPTY if it is not. - * - * @param max The new max value - * @returns Whether max was a valid value, or (whether max == the empty string && min has a valid value) - */ - public boolean setMax(String max) - { - this.max = convertToInt(max); - - // The empty string is a valid max value iff min has a valid value. - // This is due to the fact that {n,} means "at least n times" in regex parlance. - if (max.equals("") && this.min != EMPTY) - { - return true; - } - - else if (this.max < this.min) - { - return false; - } - - else - { - return (this.max >= 0); - } - } - - - - public int getRepeat() - { - return repeat; - } - - public void setRepeat(int repeat) - { - this.repeat = repeat; - } - - /** - * Sets this.repeat to the integer representation of repeat iff repeat is a valid value (i.e. greater than 0). - * Sets this.repeat to EMPTY if it is not. - * - * @param repeat The new repeat value - * @returns Whether repeat was a valid value - */ - public boolean setRepeat(String repeat) - { - this.repeat = convertToInt(repeat); - return (this.repeat >= 0); - } - - - - /** - * Returns the integer representation of s. If s is less than zero, or if s is not an int - * (i.e. if Integer.parseInt would throw a NumberFormatException), then returns EMPTY. - * - * @param s The String to convert. - * @returns The integer representation of s. - */ - private int convertToInt(String s) - { - int result; - try - { - result = Integer.parseInt(s); - if (result < 0) - { - result = EMPTY; - } - } - catch (NumberFormatException e) - { - result = EMPTY; - } - - return result; - } - - - public boolean getHasParens() - { - return hasParens; - } - - public void setHasParens(boolean status) - { - this.hasParens = status; - } - - public boolean getAutoEscapeStatus() - { - return autoEscapeStatus; - } - - public void setAutoEscapeStatus(boolean status) - { - this.autoEscapeStatus = status; - } - - /** - * Returns an escaped version of s. In other words, each occurrence of a metacharacter ( .\?*+{}()[] ) - * is replaced by that character preceded by a backslash. - * - * @param s The String to escape. - * @returns An escaped version of s. - */ - private String addEscapeCharacters(String s) - { - StringBuffer result = new StringBuffer(""); - - for (int i = 0; i < s.length(); i++) - { - char currentChar = s.charAt(i); - - if (isMetachar(currentChar)) - { - result.append("\\"); // Note that this is an escaped backslash, not a double backslash. - } - result.append(currentChar); - - } - - return result.toString(); - } - - /** - * Checks whether c is a metacharacter as defined in the static variable metacharacters. - * - * @param c The character to check. - * @returns Whether c is a metacharacter. - */ - private boolean isMetachar(char c) - { - return metacharacters.indexOf(c) != -1; - } - - - public boolean hasValidMin() - { - return (min != EMPTY); - } - - public boolean hasValidMax() - { - return(max != EMPTY); - } - - public boolean hasValidRepeat() - { - return(repeat != EMPTY); - } - - public String toString() - { - String result = ""; - - if (hasParens) - { - result += "("; - } - - if (autoEscapeStatus) - { - result += addEscapeCharacters(contents); - } - else - { - result += contents; - } - - - if (hasParens) - { - result += ")"; - } - - switch (quantifier) - { - case STAR: - result += "*"; - break; - - case PLUS: - result += "+"; - break; - - case OPTIONAL: - result += "?"; - break; - - case REPEAT: - result += "{" + repeat + "}"; - break; - - case RANGE: - result += "{" + min + ","; - if (max == EMPTY) - { - result += ""; - } - else - { - result += max; - } - result += "}"; - break; - - // SINGLE is a fall through - - } - return result; - - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexTestingPage.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexTestingPage.java deleted file mode 100644 index 488c6ea155..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexTestingPage.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -// Based on version 1.6 of original xsdeditor -package org.eclipse.wst.xsd.ui.internal.wizards; - -import java.util.regex.Pattern; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.osgi.util.TextProcessor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.util.ViewUtility; - - -public class RegexTestingPage extends WizardPage -{ - /* Validator from xerces package. */ -// private RegularExpression validator; - - /* Displays the status of the match. */ - private Label matchLabel; - - - /* The regex. */ - private Text value; - - /* The string the user is trying to match against the regex. */ - private StyledText testString; - - public RegexTestingPage() - { - super(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TESTING_PAGE_TITLE")); - - setTitle(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TESTING_PAGE_TITLE")); - setDescription(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TESTING_PAGE_DESCRIPTION")); - } - - - public void createControl(Composite parent) - { - Composite composite = ViewUtility.createComposite(parent, 1); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, XSDEditorCSHelpIds.REGEX_TEST_PAGE); - - matchLabel = new Label(composite, SWT.WRAP); - matchLabel.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TESTING_PAGE_DESCRIPTION")); - FontData[] fontData = matchLabel.getFont().getFontData(); - GridData dataF = new GridData(); - dataF.widthHint = 400; - dataF.heightHint = 6 * fontData[0].getHeight(); - matchLabel.setLayoutData(dataF); - - Composite controls = new Composite(composite, SWT.NONE); - GridLayout controlsLayout = new GridLayout(); - controlsLayout.numColumns = 2; - controls.setLayout(controlsLayout); - controls.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - new Label(controls, SWT.LEFT).setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_REGEX_LABEL")); - value = new Text(controls, SWT.BORDER | SWT.READ_ONLY); - value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - - new Label(controls, SWT.LEFT).setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_SAMPLE_TEXT")); - testString = new StyledText(controls, SWT.SINGLE | SWT.BORDER); - PlatformUI.getWorkbench().getHelpSystem().setHelp(testString, XSDEditorCSHelpIds.REGEX_SAMPLE_TEXT); - testString.addListener(SWT.Modify, new TestStringListener()); - testString.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - controls.pack(); - - Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); - GC gc = new GC(separator); - Point pointSize = gc.stringExtent(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TESTING_PAGE_DESCRIPTION")); - GridData gd = new GridData(); - gd.widthHint = pointSize.x / 2 + gc.getAdvanceWidth('M')*11; - gd.horizontalAlignment= GridData.FILL; - separator.setLayoutData(gd); - - composite.pack(); - - setControl(composite); - } - - - private String getPatternValue() - { - return ( (RegexCompositionPage)getPreviousPage() ).getPattern().getLexicalValue(); - } - - private String getFlags() - { - return ( (RegexCompositionPage)getPreviousPage() ).getFlags(); - } - - public void setVisible(boolean visible) - { - super.setVisible(visible); - - getFlags(); - value.setText(TextProcessor.process(getPatternValue())); - updateMatchStatus(); - testString.setFocus(); - } - - class TestStringListener implements Listener - { - public void handleEvent(Event e) - { - updateMatchStatus(); - } - } - - private void updateMatchStatus() - { - if (Pattern.matches(getPatternValue(), testString.getText())) - { -// matchLabel.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_MATCHES")); - setMessage(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_MATCHES"), 1); - } - else - { - setMessage(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_DOES_NOT_MATCH"), 2); -// matchLabel.setText(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_DOES_NOT_MATCH")); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexWizard.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexWizard.java deleted file mode 100644 index d341f661dc..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/RegexWizard.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.wizards; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDPatternFacet; -import org.eclipse.xsd.impl.XSDFactoryImpl; - - -public class RegexWizard extends Wizard -{ - private RegexCompositionPage compositionPage; - private RegexTestingPage testingPage; - - /* The original, unchanged pattern. */ - private XSDPatternFacet originalPattern; - - /* A copy of the original pattern that is passed into the wizard. */ - private XSDPatternFacet modifiedPattern; - - String pattern; - - public RegexWizard(String expr) - { - super(); - setWindowTitle(XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_TITLE")); - setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(XSDEditorPlugin.class, "icons/regx_wiz.png")); - - XSDFactoryImpl factory = new XSDFactoryImpl(); - modifiedPattern = factory.createXSDPatternFacet(); - modifiedPattern.setLexicalValue(expr); - - originalPattern = factory.createXSDPatternFacet(); - originalPattern.setLexicalValue(expr); - - compositionPage = new RegexCompositionPage(modifiedPattern); - addPage(compositionPage); - - testingPage = new RegexTestingPage(); - addPage(testingPage); - } - - public String getPattern() - { - return pattern; - } - - public boolean canFinish() - { - return (compositionPage.getValue().length() > 0); - } - - public boolean performFinish() - { - pattern = modifiedPattern.getLexicalValue(); - return true; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDLocationChoicePage.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDLocationChoicePage.java deleted file mode 100644 index f709f10b7b..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDLocationChoicePage.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.wizards; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.util.ViewUtility; - - -public class XSDLocationChoicePage extends WizardPage -{ - protected Button radioButton1; - protected Button radioButton2; - - public XSDLocationChoicePage() - { - super("XSDLocationChoicePage"); - - this.setTitle(XSDEditorPlugin.getXSDString("_UI_WIZARD_INCLUDE_FILE_TITLE")); - this.setDescription(XSDEditorPlugin.getXSDString("_UI_WIZARD_INCLUDE_FILE_DESC")); - } - - public boolean isPageComplete() - { - return true; - } - - public void createControl(Composite parent) - { - Composite base = new Composite(parent, SWT.NONE); - base.setLayout(new GridLayout()); - - ViewUtility.createLabel(base, XSDEditorPlugin.getXSDString("_UI_LABEL_INCLUDE_URL_FILE")); - Composite radioButtonsGroup = ViewUtility.createComposite(base, 1, true); - - radioButton1 = ViewUtility.createRadioButton(radioButtonsGroup, - XSDEditorPlugin.getXSDString("_UI_RADIO_FILE")); - - radioButton2 = ViewUtility.createRadioButton(radioButtonsGroup, - XSDEditorPlugin.getXSDString("_UI_RADIO_URL")); - - radioButton1.setSelection(true); - - setControl(base); - } - - // actions on finish - public boolean performFinish() - { - return true; - } - - public boolean isURL() - { - return radioButton2.getSelection(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDNewFilePage.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDNewFilePage.java deleted file mode 100644 index f1c1e0b287..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDNewFilePage.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.wizards; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; - - -public class XSDNewFilePage extends WizardNewFileCreationPage -{ - public XSDNewFilePage(IStructuredSelection selection) - { - super(XSDEditorPlugin.getXSDString("_UI_CREATEXSD"), selection); - setTitle(XSDEditorPlugin.getXSDString("_UI_NEW_XML_SCHEMA_TITLE")); - setDescription(XSDEditorPlugin.getXSDString("_UI_CREATE_A_NEW_XML_SCHEMA_DESC")); - } - - public void createControl(Composite parent) - { - // inherit default container and name specification widgets - super.createControl(parent); - - this.setFileName(computeDefaultFileName()); - - setPageComplete(validatePage()); - } - - protected boolean validatePage() - { - Path newName = new Path(getFileName()); - String fullFileName = getFileName(); - String extension = newName.getFileExtension(); - if (extension == null || !extension.equalsIgnoreCase("xsd")) - { - setErrorMessage(XSDEditorPlugin.getXSDString("_ERROR_FILENAME_MUST_END_XSD")); - return false; - } - else - { - setErrorMessage(null); - } - - // check for file should be case insensitive - String sameName = existsFileAnyCase(fullFileName); - if (sameName != null) - { - setErrorMessage(XSDEditorPlugin.getPlugin().getString("_ERROR_FILE_ALREADY_EXISTS", sameName)); //$NON-NLS-1$ - return false; - } - - return super.validatePage(); - } - - public String defaultName = "NewXMLSchema"; //$NON-NLS-1$ - public String defaultFileExtension = ".xsd"; //$NON-NLS-1$ - public String[] filterExtensions = { "*.xsd"}; //$NON-NLS-1$ - - protected String computeDefaultFileName() - { - int count = 0; - String fileName = defaultName + defaultFileExtension; - IPath containerFullPath = getContainerFullPath(); - if (containerFullPath != null) - { - while (true) - { - IPath path = containerFullPath.append(fileName); - if (ResourcesPlugin.getWorkspace().getRoot().exists(path)) - { - count++; - fileName = defaultName + count + defaultFileExtension; - } - else - { - break; - } - } - } - return fileName; - } - - // returns true if file of specified name exists in any case for selected container - protected String existsFileAnyCase(String fileName) - { - if ( (getContainerFullPath() != null) && (getContainerFullPath().isEmpty() == false) - && (fileName.compareTo("") != 0)) - { - //look through all resources at the specified container - compare in upper case - IResource parent = ResourcesPlugin.getWorkspace().getRoot().findMember(getContainerFullPath()); - if (parent instanceof IContainer) - { - IContainer container = (IContainer) parent; - try - { - IResource[] members = container.members(); - String enteredFileUpper = fileName.toUpperCase(); - for (int i=0; i<members.length; i++) - { - String resourceUpperName = members[i].getName().toUpperCase(); - if (resourceUpperName.equals(enteredFileUpper)) - { - return members[i].getName(); - } - } - } - catch (CoreException e) - { - } - } - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDSelectIncludeFileWizard.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDSelectIncludeFileWizard.java deleted file mode 100644 index 40c1bef077..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/wizards/XSDSelectIncludeFileWizard.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.wizards; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.viewers.SelectSingleFilePage; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.util.ViewUtility; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDParser; - - -/** - * Extend the base wizard to select a file from the project or outside the workbench - * and add error handling - */ -public class XSDSelectIncludeFileWizard extends Wizard implements INewWizard -{ - boolean isInclude; - XSDSchema mainSchema; - XSDSchema externalSchema; - - XSDLocationChoicePage choicePage; - XSDSelectSingleFilePage filePage; - XSDURLPage urlPage; - - IFile resultFile; - String resultURL; - String namespace = ""; - - public XSDSelectIncludeFileWizard(XSDSchema mainSchema, boolean isInclude, - String title, String desc, - ViewerFilter filter, - IStructuredSelection selection) - { - super(); - setWindowTitle(title); - setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(XSDEditorPlugin.class, "icons/NewXSD.png")); - - setNeedsProgressMonitor(true); - - // Choice Page - choicePage = new XSDLocationChoicePage(); - - // Select File Page - filePage = new XSDSelectSingleFilePage(PlatformUI.getWorkbench(), selection, true); - filePage.setTitle(title); - filePage.setDescription(desc); - filePage.addFilter(filter); - - // URL Page - urlPage = new XSDURLPage(); - urlPage.setTitle(title); - urlPage.setDescription(XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_URL")); - - this.mainSchema = mainSchema; - this.isInclude = isInclude; - } - - public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) - { - } - - public void addPages() - { - addPage(choicePage); - addPage(filePage); - addPage(urlPage); - } - - public IWizardPage getNextPage(IWizardPage currentPage) - { - WizardPage nextPage = null; - - if (currentPage == choicePage) - { - if (choicePage.isURL()) - { - nextPage = urlPage; - } - else - { - nextPage = filePage; - } - } - return nextPage; - } - - public boolean canFinish() - { - if (!choicePage.isURL()) - { - return filePage.isPageComplete(); - } - return true; - } - - public boolean performFinish() - { - if (choicePage.isURL()) - { - try - { - getContainer().run(false, true, urlPage.getRunnable()); - resultURL = urlPage.getURL(); - } - catch (Exception e) - { - return false; - } - return true; - } - else - { - resultFile = filePage.getFile(); - } - return true; - } - - /** - * Get the MOF object that represents the external file - */ - public XSDSchema getExternalSchema() - { - return externalSchema; - } - - public IFile getResultFile() - { - return resultFile; - } - - public String getURL() - { - return resultURL; - } - - public String getNamespace() - { - return namespace; - } - - /** - * Create a MOF model for the imported file - */ - protected String doLoadExternalModel(IProgressMonitor monitor, String xsdModelFile, String xsdFileName) - { - String errorMessage = null; - String currentNameSpace = mainSchema.getTargetNamespace(); - - monitor.beginTask("Loading XML Schema", 100); - monitor.worked(50); - - XSDParser parser = new XSDParser(); - parser.parse(xsdModelFile); - - externalSchema = parser.getSchema(); - if (externalSchema != null) - { - String extNamespace = externalSchema.getTargetNamespace(); - namespace = extNamespace; - - if (externalSchema.getDiagnostics() != null && - externalSchema.getDiagnostics().size() > 0) - { - errorMessage = XSDEditorPlugin.getPlugin().getString("_UI_INCORRECT_XML_SCHEMA", xsdFileName); - } - else - { - if (isInclude) - { - // Check the namespace to make sure they are the same as current file - if (extNamespace != null) - { - if (currentNameSpace != null && !extNamespace.equals(currentNameSpace)) - { - errorMessage = XSDEditorPlugin.getPlugin().getString("_UI_DIFFERENT_NAME_SPACE", xsdFileName); - } - } - } - else - { - // Check the namespace to make sure they are different from the current file - if (extNamespace != null) - { - if (currentNameSpace != null && extNamespace.equals(currentNameSpace)) - { - errorMessage = XSDEditorPlugin.getPlugin().getString("_UI_SAME_NAME_SPACE", xsdFileName); - } - } - } - } - } - else - { - errorMessage = XSDEditorPlugin.getPlugin().getString("_UI_INCORRECT_XML_SCHEMA", xsdFileName); - } - - monitor.subTask("Finish Loading"); - monitor.worked(80); - - return errorMessage; - } - - - /** - * URL page - */ - class XSDURLPage extends WizardPage - { - Text urlField; - String saveString; - - public XSDURLPage() - { - super("URLPage"); - } - - public void createControl(Composite parent) - { - Composite client = ViewUtility.createComposite(parent,2); - ViewUtility.setComposite(client); - - ViewUtility.createLabel(client, XSDEditorPlugin.getXSDString("_UI_LABEL_URL")); - ViewUtility.createLabel(client, ""); - - urlField = ViewUtility.createTextField(client, 50); - saveString = "http://"; - urlField.setText(saveString); - - setControl(client); - } - - public String getURL() - { - return urlField.getText(); - } - - private boolean openExternalSchema(IProgressMonitor monitor) - { - String text = urlField.getText(); -// if (text.equals(saveString)) -// { -// return false; -// } -// saveString = text; - - if (text.equals("")) - { - setErrorMessage(XSDEditorPlugin.getXSDString("_UI_SPECIFY_URL")); - return false; - } - - if ( !text.startsWith("http://") ) - { - setErrorMessage(XSDEditorPlugin.getXSDString("_UI_URL_START_WITH")); - return false; - } - - setErrorMessage(null); - String errorMessage = doLoadExternalModel(monitor, text, text); - if (errorMessage != null) - { - setErrorMessage(errorMessage); - return false; - } - else - { - return true; - } - } - - public IRunnableWithProgress getRunnable() - { - return new IRunnableWithProgress() - { - public void run(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException - { - if (monitor == null) - { - monitor= new NullProgressMonitor(); - } - monitor.beginTask("", 6); - - boolean ok = openExternalSchema(monitor); - - if (!ok) - { - throw new InvocationTargetException(new java.lang.Error()); - } - - monitor.done(); - } - }; - } - } - - /** - * Select XML Schema File - */ - class XSDSelectSingleFilePage extends SelectSingleFilePage - { - public XSDSelectSingleFilePage(IWorkbench workbench, IStructuredSelection selection, boolean isFileMandatory) - { - super(workbench,selection,isFileMandatory); - } - - private boolean openExternalSchema() - { - // Get the fully-qualified file name - IFile iFile = getFile(); - if (iFile == null) - return false; - - setErrorMessage(null); - - String xsdModelFile = iFile.getLocationURI().toString(); - String xsdFileName = iFile.getName(); - String errorMessage = doLoadExternalModel(new NullProgressMonitor(), xsdModelFile, xsdFileName); - - if (errorMessage != null) - { - setErrorMessage(errorMessage); - return false; - } - else - { - return true; - } - } - - public boolean isPageComplete() - { - if (choicePage.isURL()) - { - return true; - } - - if (super.isPageComplete()) - { - return openExternalSchema(); - } - return super.isPageComplete(); - } - } -} |