diff options
author | Pablo Torregrosa Paez | 2016-05-17 12:43:08 +0000 |
---|---|---|
committer | Pablo Torregrosa Paez | 2016-05-17 12:43:08 +0000 |
commit | ec7864c157561601a275ee707fa12994c80b3679 (patch) | |
tree | 76b0ab697560d1b3e0c4ad6999b445784afa3f55 /target_explorer/plugins | |
parent | ecee54b6511efe441406f4eaaf78af2eec44802b (diff) | |
download | org.eclipse.tcf-ec7864c157561601a275ee707fa12994c80b3679.tar.gz org.eclipse.tcf-ec7864c157561601a275ee707fa12994c80b3679.tar.xz org.eclipse.tcf-ec7864c157561601a275ee707fa12994c80b3679.zip |
Target Explorer: Added "Details" section to OptionalMessageDialog.
Change-Id: Ib02757883f14279e73fea4bb7f63c556ad79fa4a
Signed-off-by: Pablo Torregrosa Paez <pablo.torregrosa@windriver.com>
Diffstat (limited to 'target_explorer/plugins')
5 files changed, 205 insertions, 18 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java index 6c3320e4c..363dcb23d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2016 Wind River Systems, Inc. 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 @@ -42,6 +42,22 @@ public final class StatusHandlerUtil { * @param callback The callback or <code>null</code>. */ public static void handleStatus(IStatus status, Object context, String template, String title, String contextHelpId, Object caller, ICallback callback) { + handleStatus(status, context, template, title, contextHelpId, caller, callback, false); + } + + /** + * Handle the given status for the given context. + * + * @param status The status. Must not be <code>null</code>. + * @param context The context. Must not be <code>null</code>. + * @param template The message template or <code>null</code>. + * @param title The dialog title or <code>null</code>. + * @param contextHelpId The context help id or <code>null</code>. + * @param caller The caller or <code>null</code>. + * @param callback The callback or <code>null</code>. + * @param showDetails If <code>true</code> the exception message will be displayed inside the Details Section. + */ + public static void handleStatus(IStatus status, Object context, String template, String title, String contextHelpId, Object caller, ICallback callback, boolean showDetails) { Assert.isNotNull(status); Assert.isNotNull(context); @@ -53,7 +69,12 @@ public final class StatusHandlerUtil { if (contextHelpId != null) data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, contextHelpId); if (caller != null) data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, caller); - updateMessage(status, template); + String fullMsg = getStatusFullMessage(status); + updateMessage(status, template, fullMsg); + + if (showDetails) { + data.setProperty(IStatusHandlerConstants.PROPERTY_DETAILS_TEXT, fullMsg); + } handlers[0].handleStatus(status, data, callback); } else { @@ -62,9 +83,7 @@ public final class StatusHandlerUtil { } } - private static void updateMessage(IStatus status, String template) { - Assert.isNotNull(status); - + private static String getStatusFullMessage(IStatus status) { StringBuilder message = new StringBuilder(); String msg = status.getMessage(); @@ -94,6 +113,12 @@ public final class StatusHandlerUtil { String fullMsg = null; if (message.length() > 0) fullMsg = message.toString().trim(); + return fullMsg; + } + + private static void updateMessage(IStatus status, String template, String fullMsg) { + Assert.isNotNull(status); + // Apply the template if any if (template != null) fullMsg = NLS.bind(template, fullMsg != null ? fullMsg : ""); //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/interfaces/IStatusHandlerConstants.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/interfaces/IStatusHandlerConstants.java index b77a88973..ddc51ddc5 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/interfaces/IStatusHandlerConstants.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/interfaces/IStatusHandlerConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2016 Wind River Systems, Inc. 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 @@ -64,4 +64,14 @@ public interface IStatusHandlerConstants { * Property: The result of the status handling. */ public final static String PROPERTY_RESULT = "result"; //$NON-NLS-1$ + + /** + * Property: The text to be shown in the Details section of the Dialog. + */ + public final static String PROPERTY_DETAILS_TEXT = "detailsText"; //$NON-NLS-1$ + + /** + * Property: The index of the Details button in the Dialog. + */ + public final static String PROPERTY_DETAILS_BUTTON_INDEX = "detailsButtonIndex"; //$NON-NLS-1$ } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java index 328895bec..d5748a18e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java @@ -183,7 +183,7 @@ public class RenameHandler extends AbstractHandler { String template = NLS.bind(Messages.RenameHandler_error_renameFailed, Messages.PossibleCause); StatusHandlerUtil.handleStatus(StatusHelper.getStatus(e), selection, template, - Messages.RenameHandler_error_title, IContextHelpIds.MESSAGE_RENAME_FAILED, this, null); + Messages.RenameHandler_error_title, IContextHelpIds.MESSAGE_RENAME_FAILED, this, null, true); } } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/dialogs/OptionalMessageDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/dialogs/OptionalMessageDialog.java index b5a93e358..209ae49ad 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/dialogs/OptionalMessageDialog.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/dialogs/OptionalMessageDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2015 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2016 Wind River Systems, Inc. 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 @@ -20,6 +20,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -29,6 +30,7 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.tcf.te.ui.swt.activator.UIPlugin; @@ -49,11 +51,19 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { // section name for the dialog settings stored by this dialog private static final String DIALOG_ID = "OptionalMessageDialog"; //$NON-NLS-1$ + // size of the details text in lines + private static final int TEXT_LINE_COUNT = 15; // context help id for the dialog private String contextHelpId; // the key where the result is stored within the dialog settings section private String key; + // the content of the details text area + private String detailsTextString; + // details text area + private Text detailsTextArea = null; + // index of the details button + private int detailsButtonIndex = -1; /** * Constructor. Message dialog with "do not show again" and optional help @@ -84,6 +94,41 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { * button will be shown. */ public OptionalMessageDialog(Shell parentShell, String title, Image image, String message, int imageType, String[] buttonLabels, int defaultIndex, String key, String contextHelpId) { + this(parentShell, title, image, message, imageType, buttonLabels, defaultIndex, key, contextHelpId, null); + } + + /** + * Constructor. Message dialog with "do not show again" and optional help + * button. The dialog automatically stores the pressed button when "do not + * show again" was selected. The next time the dialogs <code>open()</code> + * method is called it returns the stored value without opening the dialog. + * When the cancel button was pressed, _NO_ value will be stored. + * + * @param parentShell + * The shell. + * @param title + * The title for the message dialog. + * @param image + * The window icon or <code>null</code> if default icon should + * be used. + * @param message + * The dialog message text. + * @param imageType + * The dialog image type (QUESTION, INFORMATION, WARNING, ERROR). + * @param buttonLabels + * The labels for buttons. + * @param defaultIndex + * The default button index. + * @param key + * The unique key for the stored result value (e.g. "<PluginName>.<ActionOrDialogName>"). + * @param contextHelpId + * The optional help context id. If <code>null</code>, no help + * button will be shown. + * @param detailsText + * The content of the Details TextArea. If <code>null</code>, no + * Details TextArea will be shown. + */ + public OptionalMessageDialog(Shell parentShell, String title, Image image, String message, int imageType, String[] buttonLabels, int defaultIndex, String key, String contextHelpId, String detailsText) { super(parentShell, title, @@ -97,6 +142,7 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { this.contextHelpId = contextHelpId; this.key = key == null || key.trim().length() == 0 ? null : key.trim(); + this.detailsTextString = detailsText; if (contextHelpId != null) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parentShell, contextHelpId); @@ -254,6 +300,59 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { } /** + * Creates the details text control. + */ + protected void createDropDownText(Composite parent) { + if (detailsTextString != null) { + detailsTextArea = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY); + detailsTextArea.setFont(parent.getFont()); + detailsTextArea.setText(detailsTextString); + + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL + | GridData.GRAB_VERTICAL); + data.heightHint = detailsTextArea.getLineHeight() * TEXT_LINE_COUNT; + data.horizontalSpan = 2; + detailsTextArea.setLayoutData(data); + } + } + + /** + * Toggles the unfolding of the details area. This is triggered by + * the user pressing the details button. + */ + private void toggleDetailsArea() { + Point windowSize = getShell().getSize(); + Point oldSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); + + if (getButton(detailsButtonIndex) != null) { + if (detailsTextArea != null) { + detailsTextArea.dispose(); + detailsTextArea = null; + getButton(detailsButtonIndex).setText(IDialogConstants.SHOW_DETAILS_LABEL); + } else { + createDropDownText((Composite) getContents()); + getButton(detailsButtonIndex).setText(IDialogConstants.HIDE_DETAILS_LABEL); + } + + Point newSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); + getShell().setSize(new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y))); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.MessageDialogWithToggle#buttonPressed(int) + */ + @Override + protected void buttonPressed(int buttonId) { + if (IDialogConstants.DETAILS_ID == buttonId) { + toggleDetailsArea(); + } else { + super.buttonPressed(buttonId); + } + } + + /** * Opens the dialog only, if no dialog result is stored and this dialog * should be displayed. If a dialog result is stored, this state will be * returned without opening the dialog. When the dialog is closed and "do @@ -340,7 +439,7 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { */ public static int openOkCancelDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId) { if (buttonLabel == null) buttonLabel = new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; - OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, QUESTION, buttonLabel, 0, key, contextHelpId); + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, QUESTION, buttonLabel, 0, key, contextHelpId, null); return dialog.open(); } @@ -385,7 +484,7 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { */ public static int openYesNoCancelDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId) { if (buttonLabel == null) buttonLabel = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; - OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, QUESTION, buttonLabel, 0, key, contextHelpId); + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, QUESTION, buttonLabel, 0, key, contextHelpId, null); return dialog.open(); } @@ -430,7 +529,7 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { */ public static int openYesNoDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId) { if (buttonLabel == null) buttonLabel = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; - OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, QUESTION, buttonLabel, 0, key, contextHelpId); + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, QUESTION, buttonLabel, 0, key, contextHelpId, null); return dialog.open(); } @@ -475,7 +574,7 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { */ public static int openInformationDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId) { if (buttonLabel == null) buttonLabel = new String[] { IDialogConstants.OK_LABEL }; - OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, INFORMATION, buttonLabel, 0, key, contextHelpId); + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, INFORMATION, buttonLabel, 0, key, contextHelpId, null); return dialog.open(); } @@ -520,7 +619,7 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { */ public static int openWarningDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId) { if (buttonLabel == null) buttonLabel = new String[] { IDialogConstants.OK_LABEL }; - OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, WARNING, buttonLabel, 0, key, contextHelpId); + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, WARNING, buttonLabel, 0, key, contextHelpId, null); return dialog.open(); } @@ -565,7 +664,47 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { */ public static int openErrorDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId) { if (buttonLabel == null) buttonLabel = new String[] { IDialogConstants.OK_LABEL }; - OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, ERROR, buttonLabel, 0, key, contextHelpId); + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, ERROR, buttonLabel, 0, key, contextHelpId, null); + return dialog.open(); + } + + /** + * Opens a error dialog with OK. + * + * @param parentShell + * The shell. + * @param title + * The title for the message dialog. + * @param message + * The dialog message text. + * @param buttonLabel + * An string array listing the labels of the message dialog buttons. If <code>null</code>, the default + * labeling, typically "OK" for a single button message dialog, will be applied. + * @param key + * The unique key for the stored result value (e.g. "<PluginName>.<ActionOrDialogName>"). + * @param contextHelpId + * The optional help context id. If <code>null</code>, no help + * button will be shown. + * @param detailsText + * The content of the Details TextArea. If <code>null</code>, no Details TextArea will be shown. + * @param detailsButtonIndex + * The index of the Details Button. + * @return The stored or selected result. + */ + public static int openErrorDialog(Shell parentShell, String title, String message, String[] buttonLabel, String key, String contextHelpId, String detailsText, int detailsButtonIndex) { + int btnIndex = detailsButtonIndex; + if (buttonLabel == null) { + if (detailsText != null) { + buttonLabel = new String[] { IDialogConstants.SHOW_DETAILS_LABEL, IDialogConstants.OK_LABEL }; + btnIndex = 0; + } else { + buttonLabel = new String[] { IDialogConstants.OK_LABEL }; + } + } + OptionalMessageDialog dialog = new OptionalMessageDialog(parentShell, title, null, message, ERROR, buttonLabel, 1, key, contextHelpId, detailsText); + if (detailsText != null) { + dialog.setDetailButtonIndex(btnIndex); + } return dialog.open(); } @@ -675,4 +814,13 @@ public class OptionalMessageDialog extends MessageDialogWithToggle { IDialogSettings settings = UIPlugin.getDefault().getDialogSettings(); settings.addNewSection(DIALOG_ID); } + + /** + * Set the details button index. + * + * @param index of the details button. + */ + public void setDetailButtonIndex(int index) { + detailsButtonIndex = index; + } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/statushandler/DefaultStatusHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/statushandler/DefaultStatusHandler.java index 148535fb3..9ff3ffd35 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/statushandler/DefaultStatusHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/statushandler/DefaultStatusHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2016 Wind River Systems, Inc. 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 @@ -98,6 +98,8 @@ public class DefaultStatusHandler extends AbstractStatusHandler { String contextHelpId = null; String dontAskAgainId = null; Object caller = null; + String detailsText = null; + int detailsButtonIndex = -1; // Unpack the custom data if (data != null) { @@ -106,6 +108,8 @@ public class DefaultStatusHandler extends AbstractStatusHandler { contextHelpId = data.getStringProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID); dontAskAgainId = data.getStringProperty(IStatusHandlerConstants.PROPERTY_DONT_ASK_AGAIN_ID); caller = data.getProperty(IStatusHandlerConstants.PROPERTY_CALLER); + detailsText = data.getStringProperty(IStatusHandlerConstants.PROPERTY_DETAILS_TEXT); + detailsButtonIndex = data.getIntProperty(IStatusHandlerConstants.PROPERTY_DETAILS_BUTTON_INDEX); } if (message != null && pluginId != null) { @@ -160,7 +164,7 @@ public class DefaultStatusHandler extends AbstractStatusHandler { String helpContextId = (contextHelpIds.length > 0) ? contextHelpIds[0] : null; // Show the message dialog finally - result = doOpenMessageDialog(shell, title, message, buttonLabel, severity, dontAskAgainId, helpContextId); + result = doOpenMessageDialog(shell, title, message, buttonLabel, severity, dontAskAgainId, helpContextId, detailsText, detailsButtonIndex); } else { // Not interactive -> Re-pack the status and log it to the error log // Map any non-default status to IStatus.OK @@ -271,7 +275,7 @@ public class DefaultStatusHandler extends AbstractStatusHandler { * @return {@link Integer} containing the id of the button pressed if the severity is {@link IStatusHandlerConstants#QUESTION} * or {@link IStatusHandlerConstants#YES_NO_CANCEL}, <code>null</code> otherwise. */ - protected Object doOpenMessageDialog(Shell shell, String title, String message, String[] buttonLabel, int severity, String keyDontAskAgain, String helpContextId) { + protected Object doOpenMessageDialog(Shell shell, String title, String message, String[] buttonLabel, int severity, String keyDontAskAgain, String helpContextId, String detailsText, int detailsButtonIndex) { Assert.isNotNull(shell); Assert.isNotNull(title); Assert.isNotNull(message); @@ -289,7 +293,7 @@ public class DefaultStatusHandler extends AbstractStatusHandler { OptionalMessageDialog.openWarningDialog(shell, title, message, buttonLabel, keyDontAskAgain, helpContextId); break; case IStatus.ERROR: - OptionalMessageDialog.openErrorDialog(shell, title, message, buttonLabel, keyDontAskAgain, helpContextId); + OptionalMessageDialog.openErrorDialog(shell, title, message, buttonLabel, keyDontAskAgain, helpContextId, detailsText, detailsButtonIndex); break; default: OptionalMessageDialog.openInformationDialog(shell, title, message, buttonLabel, keyDontAskAgain, helpContextId); |