Author: elvisisking
Date: 2012-04-13 17:01:21 -0400 (Fri, 13 Apr 2012)
New Revision: 40187
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiMessages.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/MessageSummaryDialog.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/graphics/GraphicsUtils.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/uiMessages.properties
Log:
JBIDE-11528 Add Option To CND Validation Message Dialog To Export The Validation Messages
To A Workspace File. Messages can now be exported to a file sytem file.
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiMessages.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiMessages.java 2012-04-13
21:00:42 UTC (rev 40186)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiMessages.java 2012-04-13
21:01:21 UTC (rev 40187)
@@ -20,6 +20,26 @@
public static String errorDialogTitle;
/**
+ * A message for a button for exporting data to a file.
+ */
+ public static String export;
+
+ /**
+ * The name of the default file name for the dialog that exports messages to a file.
+ */
+ public static String exportMessagesDialogDefaultFileName;
+
+ /**
+ * A title of the exports messages to a file dialog.
+ */
+ public static String exportMessagesDialogTitle;
+
+ /**
+ * A tooltip for a control that exports messages to a file.
+ */
+ public static String exportMessagesToolTip;
+
+ /**
* The title of a generic information message dialog.
*/
public static String infoDialogTitle;
@@ -30,11 +50,22 @@
public static String messageColumnHeader;
/**
+ * A message indicating a <code>null</code> was found. One parameter, a
string identifying the object, is required.
+ */
+ public static String objectIsNull;
+
+ /**
* The title of a generic question message dialog.
*/
public static String questionDialogTitle;
/**
+ * A message indicating a <code>null</code> or empty string was found.
One parameter, a name identifying the string, is
+ * required.
+ */
+ public static String stringIsEmpty;
+
+ /**
* The title of a generic warning message dialog.
*/
public static String warningDialogTitle;
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java 2012-04-13
21:00:42 UTC (rev 40186)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java 2012-04-13
21:01:21 UTC (rev 40187)
@@ -13,6 +13,7 @@
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.TableColumn;
/**
@@ -35,10 +36,11 @@
*
* @param viewerColumn the viewer column (cannot be <code>null</code>)
* @param labelProvider the column label provider (cannot be
<code>null</code>
- * @param headerText the header text (cannot be <code>null</code>)
- * @param headerToolTip (can be <code>null</code>)
+ * @param headerText the header text (can be <code>null</code> or empty)
+ * @param headerToolTip (can be <code>null</code> or empty)
* @param moveable a flag indicating if the column can be moved
* @param resizable a flag indicating if the column can be resized
+ * @throws IllegalArgumentException if either the column or label provider is
<code>null</code>
*/
public static void configureColumn( final TableViewerColumn viewerColumn,
final CellLabelProvider labelProvider,
@@ -46,11 +48,18 @@
final String headerToolTip,
final boolean moveable,
final boolean resizable ) {
+ verifyIsNotNull(viewerColumn, "viewerColumn"); //$NON-NLS-1$
+ verifyIsNotNull(labelProvider, "labelProvider"); //$NON-NLS-1$
+
viewerColumn.setLabelProvider(labelProvider);
// configure column
final TableColumn column = viewerColumn.getColumn();
- column.setText(headerText);
+
+ if (!isEmpty(headerText)) {
+ column.setText(headerText);
+ }
+
column.setToolTipText(headerToolTip);
column.setMoveable(false);
column.setResizable(resizable);
@@ -76,9 +85,7 @@
*/
public static String join( Collection<?> items,
String delimiter ) {
- if (items == null) {
- throw new IllegalArgumentException("items is null"); //$NON-NLS-1$
- }
+ verifyIsNotNull(items, "items"); //$NON-NLS-1$
delimiter = (((delimiter == null) || delimiter.isEmpty()) ?
DEFAULT_JOIN_DELIMITER : delimiter);
StringBuilder builder = new StringBuilder();
@@ -103,9 +110,12 @@
/**
* @param viewers the viewers whose columns will be packed (cannot be
<code>null</code>)
+ * @throws IllegalArgumentException if a viewer is <code>null</code>
*/
public static void pack( final TableViewer... viewers ) {
for (final TableViewer viewer : viewers) {
+ verifyIsNotNull(viewer, "viewer"); //$NON-NLS-1$
+
for (final TableColumn column : viewer.getTable().getColumns()) {
column.pack();
}
@@ -113,6 +123,38 @@
}
/**
+ * @param text the string being checked (can be <code>null</code> or
empty)
+ * @param name the name of the object to use in the error message (cannot be
<code>null</code>)
+ * @throws IllegalArgumentException if the text is <code>null</code> or
empty
+ */
+ public static void verifyIsNotEmpty( final String text,
+ String name ) {
+ if (isEmpty(text)) {
+ if ((name == null) || name.isEmpty()) {
+ name = EMPTY_STRING;
+ }
+
+ throw new IllegalArgumentException(NLS.bind(UiMessages.stringIsEmpty,
name));
+ }
+ }
+
+ /**
+ * @param object the object being checked (can be <code>null</code>)
+ * @param name the name of the object to use in the error message (cannot be
<code>null</code>)
+ * @throws IllegalArgumentException if the object is <code>null</code>
+ */
+ public static void verifyIsNotNull( final Object object,
+ String name ) {
+ if (object == null) {
+ if ((name == null) || name.isEmpty()) {
+ name = EMPTY_STRING;
+ }
+
+ throw new IllegalArgumentException(NLS.bind(UiMessages.objectIsNull, name));
+ }
+ }
+
+ /**
* Don't allow construction.
*/
private UiUtils() {
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/MessageSummaryDialog.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/MessageSummaryDialog.java 2012-04-13
21:00:42 UTC (rev 40186)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/MessageSummaryDialog.java 2012-04-13
21:01:21 UTC (rev 40187)
@@ -7,6 +7,11 @@
*/
package org.jboss.tools.modeshape.ui.forms;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -15,9 +20,13 @@
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.forms.FormDialog;
@@ -25,6 +34,8 @@
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.jboss.tools.modeshape.ui.Activator;
+import org.jboss.tools.modeshape.ui.UiConstants;
import org.jboss.tools.modeshape.ui.UiMessages;
import org.jboss.tools.modeshape.ui.UiUtils;
@@ -48,12 +59,14 @@
* @param messages the messages being displayed (cannot be
<code>null</code>)
*/
public MessageSummaryDialog( final Shell parent,
- final String dialogTitle,
- final String messageAreaTitle,
- final String messageAreaMessage,
- final int messageType,
- final IMessage[] messages ) {
+ final String dialogTitle,
+ final String messageAreaTitle,
+ final String messageAreaMessage,
+ final int messageType,
+ final IMessage[] messages ) {
super(parent);
+ UiUtils.verifyIsNotNull(messages, "messages"); //$NON-NLS-1$
+
this.dialogTitle = dialogTitle;
this.messages = messages;
this.messageAreaTitle = messageAreaTitle;
@@ -69,7 +82,7 @@
@Override
protected void configureShell( final Shell newShell ) {
super.configureShell(newShell);
- newShell.setText(this.dialogTitle);
+ newShell.setText(dialogTitle);
}
/**
@@ -78,8 +91,24 @@
* @see
org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
@Override
- protected void createButtonsForButtonBar( Composite parent ) {
+ protected void createButtonsForButtonBar( final Composite parent ) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+
+ // export button
+ final Button btn = createButton(parent, IDialogConstants.CLIENT_ID,
UiMessages.export, false);
+ btn.setToolTipText(UiMessages.exportMessagesToolTip);
+ btn.addSelectionListener(new SelectionAdapter() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ handleExportMessages();
+ }
+ });
}
/**
@@ -90,8 +119,8 @@
@Override
protected void createFormContent( final IManagedForm managedForm ) {
final ScrolledForm scrolledForm = managedForm.getForm();
- scrolledForm.setText(this.messageAreaTitle); // set header area title
- scrolledForm.setMessage(this.messageAreaMessage, this.messageType,
this.messages);
+ scrolledForm.setText(messageAreaTitle); // set header area title
+ scrolledForm.setMessage(messageAreaMessage, messageType, messages);
scrolledForm.getBody().setLayout(new GridLayout());
scrolledForm.getBody().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
@@ -101,7 +130,7 @@
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
toolkit.paintBordersFor(container);
- int count = this.messages.length;
+ int count = messages.length;
if (count > 20) {
count = 20;
@@ -175,6 +204,51 @@
}
IMessage[] getMessages() {
- return this.messages;
+ return messages;
}
+
+ void handleExportMessages() {
+ final FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
+ dlg.setFilterExtensions(new String[] { "*.txt" }); //$NON-NLS-1$
+ dlg.setText(UiMessages.exportMessagesDialogTitle);
+ dlg.setFileName(UiMessages.exportMessagesDialogDefaultFileName);
+ final String fileName = dlg.open();
+
+ if (fileName != null) {
+ final String delim = " - "; //$NON-NLS-1$
+ final StringBuilder builder = new StringBuilder();
+
+ for (final IMessage message : messages) {
+ final int messageType = message.getMessageType();
+
+ if (messageType == IMessageProvider.ERROR) {
+ builder.append(UiMessages.errorDialogTitle).append(delim);
+ } else if (messageType == IMessageProvider.WARNING) {
+ builder.append(UiMessages.errorDialogTitle).append(delim);
+ } else if (messageType == IMessageProvider.INFORMATION) {
+ builder.append(UiMessages.errorDialogTitle).append(delim);
+ }
+
+ builder.append(message.getMessage()).append('\n');
+ }
+
+ BufferedWriter out = null;
+
+ try {
+ out = new BufferedWriter(new FileWriter(fileName));
+ out.write(builder.toString());
+ out.flush();
+ } catch (final Exception e) {
+ Activator.getSharedInstance().getLog().log(new Status(IStatus.ERROR,
UiConstants.PLUGIN_ID, null, e));
+ } finally {
+ try {
+ if (out != null) {
+ out.close();
+ }
+ } catch (final java.io.IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/graphics/GraphicsUtils.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/graphics/GraphicsUtils.java 2012-04-13
21:00:42 UTC (rev 40186)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/graphics/GraphicsUtils.java 2012-04-13
21:01:21 UTC (rev 40187)
@@ -11,6 +11,7 @@
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.tools.modeshape.ui.UiUtils;
/**
*
@@ -35,9 +36,12 @@
* @param uiPlugin the UI Plug-in instance (cannot be <code>null</code>)
* @param pathToImage the path to the image file relative to the specified
plug-in's folder (can be <code>null</code>)
* @return the requested image or a standard "missing image" image (never
<code>null</code>)
+ * @throws IllegalArgumentException if the plugin is <code>null</code>
*/
public static final Image getImage( final AbstractUIPlugin uiPlugin,
final String pathToImage ) {
+ UiUtils.verifyIsNotNull(uiPlugin, "uiPlugin"); //$NON-NLS-1$
+
final ImageRegistry imageRegistry = uiPlugin.getImageRegistry();
Image image = imageRegistry.get(pathToImage);
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/uiMessages.properties
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/uiMessages.properties 2012-04-13
21:00:42 UTC (rev 40186)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/uiMessages.properties 2012-04-13
21:01:21 UTC (rev 40187)
@@ -5,7 +5,13 @@
# See the AUTHORS.txt file distributed with this work for a full listing of individual
contributors.
errorDialogTitle = Error
+export = Export
+exportMessagesDialogDefaultFileName = messages.txt
+exportMessagesDialogTitle = Export Messages
+exportMessagesToolTip = Save messages to a workspace file
infoDialogTitle = Info
messageColumnHeader = Message
+objectIsNull = Object {0} is null
questionDialogTitle = Question
+stringIsEmpty = String {0} is empty
warningDialogTitle = Warning
\ No newline at end of file