Author: elvisisking
Date: 2012-04-18 15:59:01 -0400 (Wed, 18 Apr 2012)
New Revision: 40305
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java
Log:
JBIDE-11575 The ModeShape Tools JCR CND Preference Page Should Show Notation Type Preview.
Added a preview box to the preference page that changes when the user selects a notation
type. Add a hyperlink in CND Editor to open preferences dialog.
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java 2012-04-18
19:59:01 UTC (rev 40305)
@@ -10,7 +10,7 @@
import org.eclipse.osgi.util.NLS;
/**
- *
+ * i18n messages for the ModeShape JCR plugin.
*/
public final class Messages extends NLS {
@@ -31,11 +31,11 @@
public static String defaultTypeExistsButMarkedAsVariant;
/**
- * A message indicating a child node definition has a default type but that it does
not match a required type. Two parameters, the
- * child node definition name and the default type name, are required.
+ * A message indicating a child node definition has a default type but that it does
not match a required type. Two parameters,
+ * the child node definition name and the default type name, are required.
*/
public static String defaultTypeDoesNotMatchRequiredType;
-
+
/**
* The name for the child definition's default type property.
*/
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java 2012-04-18
19:59:01 UTC (rev 40305)
@@ -228,7 +228,17 @@
final StringBuilder builder = new StringBuilder();
builder.append(NOTATION_PREFIX);
builder.append(this.prefix.toCndNotation(notationType));
+
+ if (NotationType.LONG == notationType) {
+ builder.append(Utils.SPACE_STRING);
+ }
+
builder.append(NOTATION_DELIMITER);
+
+ if (NotationType.LONG == notationType) {
+ builder.append(Utils.SPACE_STRING);
+ }
+
builder.append(Utils.SINGLE_QUOTE);
builder.append(this.uri.get());
builder.append(Utils.SINGLE_QUOTE);
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java 2012-04-18
19:59:01 UTC (rev 40305)
@@ -80,4 +80,11 @@
*/
String SHOW_INHERITED = ICONS_FOLDER + "show-inherited-16x.gif";
//$NON-NLS-1$
}
+
+ /**
+ * Constants relating to JCR preferences.
+ */
+ interface PreferenceIds {
+ String CND_PREFERENCE_PAGE =
"org.jboss.tools.modeshape.jcr.ui.jcrPreferencePage"; //$NON-NLS-1$
+ }
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java 2012-04-18
19:59:01 UTC (rev 40305)
@@ -28,6 +28,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.ControlContribution;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IMessageProvider;
@@ -36,6 +37,8 @@
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
@@ -45,6 +48,7 @@
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableEditor;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.dialogs.SaveAsDialog;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.editors.text.TextEditor;
@@ -56,6 +60,7 @@
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.Form;
+import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.part.FileEditorInput;
import org.jboss.tools.modeshape.jcr.cnd.CndElement.NotationType;
@@ -254,10 +259,33 @@
}
});
- //
- // createActions();
- // contributeToToolBar(form.getToolBarManager());
- // contributeToMenu(form.getMenuManager());
+ form.getToolBarManager().add(new ControlContribution(null) {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createControl( final Composite parent ) {
+ final Hyperlink hlink = getToolkit().createHyperlink(parent,
CndMessages.openCndEditorPreferencesHyperlink,
+ SWT.NULL);
+ hlink.addHyperlinkListener(new HyperlinkAdapter() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.ui.forms.events.HyperlinkAdapter#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
+ */
+ @Override
+ public void linkActivated( final HyperlinkEvent e ) {
+ handleOpenCndPreferencesPage();
+ }
+ });
+ return hlink;
+ }
+ });
+ form.getToolBarManager().update(true);
}
/**
@@ -414,6 +442,11 @@
dialog.open();
}
+ void handleOpenCndPreferencesPage() {
+ PreferencesUtil.createPreferenceDialogOn(getShell(),
JcrUiConstants.PreferenceIds.CND_PREFERENCE_PAGE,
+ new String[] {
JcrUiConstants.PreferenceIds.CND_PREFERENCE_PAGE }, null).open();
+ }
+
/**
* Registers an editor activation listener.
*/
@@ -435,6 +468,7 @@
try {
createCnd();
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ JcrPreferenceStore.get();
} catch (final Exception e) {
throw new PartInitException(CndMessages.errorOpeningCndEditor, e);
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java 2012-04-18
19:59:01 UTC (rev 40305)
@@ -1011,6 +1011,11 @@
public static String openDeclaringNodeTypeToolTip;
/**
+ * A label of a hyperlink that opens the CND Editor preferences.
+ */
+ public static String openCndEditorPreferencesHyperlink;
+
+ /**
* A name for the orderable attribute suitable for a radio or check button.
*/
public static String orderableAttribute;
@@ -1021,6 +1026,16 @@
public static String orderableAttributeToolTip;
/**
+ * A label suitable for a preview control.
+ */
+ public static String previewLabel;
+
+ /**
+ * A message stating that preview is not available.
+ */
+ public static String previewNotAvailableMessage;
+
+ /**
* A label for a primary item control.
*/
public static String primaryItemLabel;
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties 2012-04-18
19:59:01 UTC (rev 40305)
@@ -208,8 +208,11 @@
onParentVersionToolTip = Indicates what happens to the child node/property when the
parent is created
openDeclaringNodeTypeMenuText = Open Declaring Node Type
openDeclaringNodeTypeToolTip = Open the declaring node type in the editor if that node
type is in the CND being edited
+openCndEditorPreferencesHyperlink = Preferences
orderableAttribute = Orderable
orderableAttributeToolTip = Indicates if the node type definition's are ordered
+previewLabel = Preview:
+previewNotAvailableMessage = Preview not available
primaryItemLabel = Primary Item:
primaryItemToolTip = The child node or property made accessible via the API without
having to know it's name
propertyAttributesToolTip = The attributes of a property definition (autocreated,
mandatory, multiple, nofulltext, noqueryorder, abstract, opv, queryops)
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java 2012-04-18
19:57:10 UTC (rev 40304)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java 2012-04-18
19:59:01 UTC (rev 40305)
@@ -7,6 +7,11 @@
*/
package org.jboss.tools.modeshape.jcr.ui.preferences;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
@@ -19,37 +24,63 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.jboss.tools.modeshape.jcr.cnd.CndElement;
+import org.jboss.tools.modeshape.jcr.cnd.CndElement.NotationType;
+import org.jboss.tools.modeshape.jcr.cnd.CndImporter;
+import org.jboss.tools.modeshape.jcr.cnd.CompactNodeTypeDefinition;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceConstants.CndPreference;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceStore;
+import org.jboss.tools.modeshape.jcr.ui.Activator;
+import org.jboss.tools.modeshape.jcr.ui.JcrUiConstants;
import org.jboss.tools.modeshape.jcr.ui.JcrUiUtils;
import org.jboss.tools.modeshape.jcr.ui.cnd.CndMessages;
/**
- *
+ * The preference page that allows editing the settings of how CND files are formatted.
*/
public final class CndPreferencePage extends PreferencePage implements
IWorkbenchPreferencePage {
-//
-// private static String[] QUOTE_CHAR_LABELS = new String[] {
CndMessages.quoteCharNoneChoiceLabel,
-// CndMessages.quoteCharSingleChoiceLabel,
CndMessages.quoteCharDoubleChoiceLabel };
+ private static CompactNodeTypeDefinition _previewCnd;
+
/**
* The editor used to choose the notation type for the CND format.
*/
private Combo cbxNotationType;
-//
-// /**
-// * The editor used to choose the quote character.
-// */
-// private Combo cbxQuoteChar;
private String notationType;
-//
-// private String quoteString;
+ private Text txtPreview;
+
/**
+ * Constructs a CND preference page.
+ */
+ public CndPreferencePage() {
+ if (_previewCnd == null) {
+ _previewCnd = new CompactNodeTypeDefinition();
+
+ final String content = "<ex =
'http://namespace.com/ns'>\n" //$NON-NLS-1$
+ + "[ex:NodeType] > ex:ParentType1, ex:ParentType2 abstract
orderable mixin noquery primaryitem ex:property\n" //$NON-NLS-1$
+ + "- ex:property (STRING) = 'default1',
'default2' mandatory autocreated protected multiple VERSION\n" //$NON-NLS-1$
+ + " queryops '=, <>, <, <=, >, >=,
LIKE' nofulltext noqueryorder < 'constraint1', 'constraint2'"
//$NON-NLS-1$
+ + "+ ex:node (ex:reqType1, ex:reqType2) = ex:defaultType
mandatory autocreated protected sns version"; //$NON-NLS-1$
+
+ CndImporter importer = new CndImporter(true);
+ Collection<Throwable> problems = new ArrayList<Throwable>();
+
+ _previewCnd = importer.importFrom(content, problems, "string");
//$NON-NLS-1$
+
+ if (_previewCnd == null) {
+ for (Throwable e : problems) {
+ Activator.getSharedInstance().getLog().log(new Status(IStatus.ERROR,
JcrUiConstants.PLUGIN_ID, null, e));
+ }
+ }
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see
org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
@@ -94,39 +125,19 @@
});
}
- { // quote chars
-// final Label lbl = new Label(panel, SWT.NONE);
-// lbl.setText(CndMessages.quoteCharPolicyLabel);
-//
-// this.cbxQuoteChar = new Combo(panel, SWT.NONE);
-// this.cbxQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false));
-// this.cbxQuoteChar.setItems(QUOTE_CHAR_LABELS);
-// this.cbxQuoteChar.setToolTipText(CndMessages.quoteCharPolicyToolTip);
-//
-// // set current value
-// this.quoteString = JcrPreferenceStore.get().get(CndPreference.QUOTE_CHAR);
-//
-// if (Utils.DOUBLE_QUOTE.equals(this.quoteString)) {
-// this.cbxQuoteChar.setText(CndMessages.quoteCharDoubleChoiceLabel);
-// } else if (Utils.SINGLE_QUOTE.equals(this.quoteString)) {
-// this.cbxQuoteChar.setText(CndMessages.quoteCharSingleChoiceLabel);
-// } else {
-// this.cbxQuoteChar.setText(CndMessages.quoteCharNoneChoiceLabel);
-// }
-//
-// // add selection listener
-// this.cbxQuoteChar.addSelectionListener(new SelectionAdapter() {
-//
-// /**
-// * {@inheritDoc}
-// *
-// * @see
org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
-// */
-// @Override
-// public void widgetSelected( final SelectionEvent e ) {
-// handleQuotationCharacterChanged();
-// }
-// });
+ { // preview text
+ final Composite previewPanel = new Composite(parent, SWT.NONE);
+ previewPanel.setLayout(new GridLayout());
+ previewPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Label lblPreview = new Label(previewPanel, SWT.NONE);
+ lblPreview.setText(CndMessages.previewLabel);
+
+ this.txtPreview = new Text(previewPanel, SWT.READ_ONLY | SWT.MULTI |
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ this.txtPreview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
this.txtPreview.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
+ ((GridData)this.txtPreview.getLayoutData()).widthHint =
convertWidthInCharsToPixels(120);
+ refreshPreview();
}
return panel;
@@ -171,20 +182,6 @@
public IPreferenceStore getPreferenceStore() {
return null;
}
-//
-// private String getQuoteStringFromSelection() {
-// final String quoteSelection = this.cbxQuoteChar.getText();
-//
-// if (CndMessages.quoteCharNoneChoiceLabel.equals(quoteSelection)) {
-// return Utils.EMPTY_STRING;
-// }
-//
-// if (CndMessages.quoteCharSingleChoiceLabel.equals(quoteSelection)) {
-// return Utils.SINGLE_QUOTE;
-// }
-//
-// return Utils.DOUBLE_QUOTE;
-// }
/**
* {@inheritDoc}
@@ -198,11 +195,8 @@
void handleNotationTypeChanged() {
this.notationType = this.cbxNotationType.getText();
+ refreshPreview();
}
-//
-// void handleQuotationCharacterChanged() {
-// this.quoteString = getQuoteStringFromSelection();
-// }
/**
* {@inheritDoc}
@@ -234,18 +228,6 @@
this.cbxNotationType.setText(defaultNotationType);
}
- { // quote character
-// final String quoteSelection =
prefStore.getDefault(CndPreference.QUOTE_CHAR);
-//
-// if (Utils.EMPTY_STRING.equals(quoteSelection)) {
-// this.cbxQuoteChar.setText(CndMessages.quoteCharNoneChoiceLabel);
-// } else if (Utils.SINGLE_QUOTE.equals(quoteSelection)) {
-// this.cbxQuoteChar.setText(CndMessages.quoteCharSingleChoiceLabel);
-// } else {
-// this.cbxQuoteChar.setText(CndMessages.quoteCharDoubleChoiceLabel);
-// }
- }
-
super.performDefaults();
}
@@ -257,7 +239,14 @@
@Override
public boolean performOk() {
JcrPreferenceStore.get().set(CndPreference.NOTATION_TYPE, this.notationType);
-// JcrPreferenceStore.get().set(CndPreference.QUOTE_CHAR, this.quoteString);
return super.performOk();
}
+
+ private void refreshPreview() {
+ if (_previewCnd == null) {
+ this.txtPreview.setText(CndMessages.previewNotAvailableMessage);
+ } else {
+
this.txtPreview.setText(_previewCnd.toCndNotation(NotationType.valueOf(notationType)));
+ }
+ }
}