Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarvin Mueller2014-08-28 09:27:53 +0000
committerMarvin Mueller2014-08-28 10:01:17 +0000
commit910c7e5376ca39e361dfd222880ecfe124fcadf9 (patch)
treeddd068facd778d9e7ff3649cdac3e965b43ee7eb /org.eclipse.jubula.client.wiki.ui
parent9344a4993c1ca412e9e1da1002aeb6020cb38da3 (diff)
downloadorg.eclipse.jubula.core-910c7e5376ca39e361dfd222880ecfe124fcadf9.tar.gz
org.eclipse.jubula.core-910c7e5376ca39e361dfd222880ecfe124fcadf9.tar.xz
org.eclipse.jubula.core-910c7e5376ca39e361dfd222880ecfe124fcadf9.zip
Sprint task - Adding description edit dialog and changing behavior of the descriptionView
Diffstat (limited to 'org.eclipse.jubula.client.wiki.ui')
-rw-r--r--org.eclipse.jubula.client.wiki.ui/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jubula.client.wiki.ui/plugin.xml77
-rw-r--r--org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/Activator.java15
-rw-r--r--org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/dialogs/DescriptionEditDialog.java200
-rw-r--r--org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/handlers/EditDescriptionHandler.java83
-rw-r--r--org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/Messages.java6
-rw-r--r--org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/messages.properties6
-rw-r--r--org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/views/DescriptionView.java79
8 files changed, 454 insertions, 14 deletions
diff --git a/org.eclipse.jubula.client.wiki.ui/META-INF/MANIFEST.MF b/org.eclipse.jubula.client.wiki.ui/META-INF/MANIFEST.MF
index 94663e01b..ca907b971 100644
--- a/org.eclipse.jubula.client.wiki.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jubula.client.wiki.ui/META-INF/MANIFEST.MF
@@ -12,6 +12,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.apache.commons.lang;bundle-version="[2.4.0,3.0.0)",
org.eclipse.jubula.client.core;bundle-version="[2.4.0,2.5.0)",
org.eclipse.jubula.ui.compatibility;bundle-version="[2.4.0,2.5.0)",
+ org.eclipse.jubula.client.ui;bundle-version="[2.4.0,2.5.0)",
+ org.eclipse.jubula.client.ui.rcp;bundle-version="[2.4.0,2.5.0)",
org.eclipse.mylyn.wikitext.core;bundle-version="[1.7.0,3.0.0)",
org.eclipse.mylyn.wikitext.confluence.core;bundle-version="[1.7.0,3.0.0)",
org.eclipse.mylyn.wikitext.mediawiki.core;bundle-version="[1.7.0,3.0.0)",
diff --git a/org.eclipse.jubula.client.wiki.ui/plugin.xml b/org.eclipse.jubula.client.wiki.ui/plugin.xml
index 827ed9cc5..f87844f65 100644
--- a/org.eclipse.jubula.client.wiki.ui/plugin.xml
+++ b/org.eclipse.jubula.client.wiki.ui/plugin.xml
@@ -29,4 +29,81 @@
<viewShortcut id="org.eclipse.jubula.client.wiki.ui.views.DescriptionView" />
</perspectiveExtension>
</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.jubula.client.ui.rcp.commands"
+ id="org.eclipse.jubula.client.ui.rcp.commands.EditDescription"
+ name="Edit Description" />
+</extension>
+<extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.jubula.client.wiki.ui.handlers.EditDescriptionHandler"
+ commandId="org.eclipse.jubula.client.ui.rcp.commands.EditDescription">
+ <activeWhen>
+ <and>
+ <or>
+ <with variable="activePartId">
+ <equals value="org.eclipse.jubula.client.ui.rcp.editors.TestCaseEditor" />
+ </with>
+ <with variable="activePartId">
+ <equals value="org.eclipse.jubula.client.ui.rcp.editors.TestSuiteEditor" />
+ </with>
+ <with variable="activePartId">
+ <equals value="org.eclipse.jubula.client.ui.rcp.editors.TestJobEditor" />
+ </with>
+ </or>
+ <count value="1" />
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <or>
+ <instanceof value="org.eclipse.jubula.client.core.model.IExecTestCasePO" />
+ <instanceof value="org.eclipse.jubula.client.core.model.IRefTestSuitePO" />
+ <instanceof value="org.eclipse.jubula.client.core.model.ITestSuitePO" />
+ <instanceof value="org.eclipse.jubula.client.core.model.ITestCasePO" />
+ <instanceof value="org.eclipse.jubula.client.core.model.ITestJobPO" />
+ </or>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
+
+</extension>
+<extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="true"
+ locationURI="menu:edit?before=JubulaEditSeparator1">
+ <command
+ commandId="org.eclipse.jubula.client.ui.rcp.commands.EditDescription"
+ style="push">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.jubula.client.ui.rcp.editors.TestCaseEditor?before=editing">
+ <command
+ commandId="org.eclipse.jubula.client.ui.rcp.commands.EditDescription"
+ style="push">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.jubula.client.ui.rcp.editors.TestSuiteEditor?before=editing">
+ <command
+ commandId="org.eclipse.jubula.client.ui.rcp.commands.EditDescription"
+ style="push">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.jubula.client.ui.rcp.editors.TestJobEditor?before=editing">
+ <command
+ commandId="org.eclipse.jubula.client.ui.rcp.commands.EditDescription"
+ style="push">
+ </command>
+ </menuContribution>
+</extension>
</plugin>
diff --git a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/Activator.java b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/Activator.java
index 07bc9da4c..f21a2226c 100644
--- a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/Activator.java
+++ b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/Activator.java
@@ -10,15 +10,18 @@
*******************************************************************************/
package org.eclipse.jubula.client.wiki.ui;
-import org.osgi.framework.BundleActivator;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* @author BREDEX GmbH
*/
-public class Activator implements BundleActivator {
+public class Activator extends AbstractUIPlugin {
/** context */
private static BundleContext context;
+
+ /** single instance of plugin */
+ private static Activator activator;
/** @return the context */
static BundleContext getContext() {
@@ -28,10 +31,18 @@ public class Activator implements BundleActivator {
/** {@inheritDoc} */
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
+ activator = this;
}
/** {@inheritDoc} */
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
+ /**
+ * gets the plugin activator
+ * @return the plugin activator
+ */
+ public static Activator getActivator() {
+ return activator;
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/dialogs/DescriptionEditDialog.java b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/dialogs/DescriptionEditDialog.java
new file mode 100644
index 000000000..e8e68bcca
--- /dev/null
+++ b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/dialogs/DescriptionEditDialog.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2014 BREDEX GmbH.
+ * 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:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.client.wiki.ui.dialogs;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jubula.client.core.model.INodePO;
+import org.eclipse.jubula.client.ui.utils.DelayableTimer;
+import org.eclipse.jubula.client.wiki.ui.i18n.Messages;
+import org.eclipse.jubula.client.wiki.ui.Activator;
+import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;
+import org.eclipse.mylyn.wikitext.ui.editor.MarkupSourceViewer;
+import org.eclipse.mylyn.wikitext.ui.editor.MarkupSourceViewerConfiguration;
+import org.eclipse.mylyn.wikitext.ui.viewer.MarkupViewer;
+import org.eclipse.mylyn.wikitext.ui.viewer.MarkupViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ *
+ * @author BREDEX GmbH
+ */
+public class DescriptionEditDialog extends TitleAreaDialog {
+
+ /** the wait time(ms) before the preview is updated */
+ private static final int WAIT_BEFORE_UPDATE = 400;
+
+ /** the working node */
+ private INodePO m_workNode;
+
+ /** the description text as document */
+ private IDocument m_description;
+
+ /**
+ *
+ * @param parentShell the parent shell
+ * @param workNode the node which should be worked with
+ */
+ public DescriptionEditDialog(Shell parentShell, INodePO workNode) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ m_workNode = workNode;
+ m_description = new Document(workNode.getDescription());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Control createDialogArea(Composite parent) {
+ final String dialogTitle = Messages.EditDescriptionDialogTitle;
+ setTitle(dialogTitle);
+ setMessage(Messages.EditDescriptionDialogDescription);
+ getShell().setText(dialogTitle);
+
+ SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
+ final GridData sashGridData = createGridData();
+ sashForm.setLayoutData(sashGridData);
+
+ createDialogComponents(sashForm);
+ return sashForm;
+ }
+
+ /**
+ * @param sashForm the parent sash
+ */
+ private void createDialogComponents(SashForm sashForm) {
+ // styles for the viewer and sourceViewer
+ int styles = SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.WRAP
+ | SWT.V_SCROLL;
+
+ // creating group and source viewer
+ Group sourceGroup = new Group(sashForm, SWT.SHADOW_ETCHED_IN);
+ sourceGroup.setText(Messages.EditDescriptionDialogSourceViewer);
+ sourceGroup.setLayout(new GridLayout());
+ MarkupSourceViewer sourceViewer = createsMarkupSourceViewer(
+ sourceGroup, styles);
+
+ // creating group and preview
+ Group previewGroup = new Group(sashForm, SWT.SHADOW_ETCHED_IN);
+ previewGroup.setText(Messages.EditDescriptionDialogPreview);
+ previewGroup.setLayout(new GridLayout());
+ MarkupViewer viewer = createMarkupViewer(previewGroup, styles);
+
+ addDocumentListenerViewer(sourceViewer, viewer);
+ }
+
+ /**
+ * @param sourceViewer the {@link MarkupSourceViewer} which is the source
+ * of the description
+ * @param viewer the {@link MarkupViewer} which should get the new data
+ */
+ private void addDocumentListenerViewer(
+ final MarkupSourceViewer sourceViewer, final MarkupViewer viewer) {
+ final DelayableTimer delayedPreviewTimer = new DelayableTimer(
+ WAIT_BEFORE_UPDATE, new Runnable() {
+ public void run() {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ viewer.setDocument(new Document(m_description
+ .get()));
+ }
+ });
+ }
+ });
+ m_description.addDocumentListener(new IDocumentListener() {
+ public void documentChanged(DocumentEvent event) {
+ delayedPreviewTimer.cancel();
+ delayedPreviewTimer.schedule();
+ }
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ // Nothing before changed
+ }
+ });
+ }
+
+ /**
+ * creates the {@link MarkupSourceViewera} for the description.
+ * @param parent the parent
+ * @param styles styles that should be used for the {@link MarkupSourceViewera}
+ * @return the created {@link MarkupSourceViewera}
+ */
+ private MarkupSourceViewer createsMarkupSourceViewer(Composite parent,
+ int styles) {
+ final MarkupSourceViewer sourceViewer = new MarkupSourceViewer(parent,
+ null, styles, new TracWikiLanguage());
+ sourceViewer.setDocument(m_description);
+ MarkupSourceViewerConfiguration sourceViewerConfig =
+ new MarkupSourceViewerConfiguration(null);
+ sourceViewer.configure(sourceViewerConfig);
+ sourceViewer.getControl().setLayoutData(createGridData());
+ return sourceViewer;
+ }
+
+ /**
+ * creates the {@link MarkupViewer} for the rendered description
+ * @param parent the parent
+ * @param styles styles thaht should be used for the {@link MarkupViewer}
+ * @return the created {@link MarkupViewer}
+ */
+ private MarkupViewer createMarkupViewer(Composite parent, int styles) {
+ final MarkupViewer viewer = new MarkupViewer(parent, null, null, true,
+ styles);
+ MarkupViewerConfiguration viewerConfiguration =
+ new MarkupViewerConfiguration(viewer);
+ viewerConfiguration.setEnableSelfContainedIncrementalFind(true);
+ viewerConfiguration.setDisableHyperlinkModifiers(false);
+ viewer.configure(viewerConfiguration);
+ viewer.setMarkupLanguage(new TracWikiLanguage());
+ viewer.getControl().setLayoutData(createGridData());
+ viewer.setDocument(new Document(m_workNode.getDescription()));
+ return viewer;
+ }
+
+ /**
+ *
+ * @return a {@link GridData} with full grabbing of space
+ */
+ private GridData createGridData() {
+ final GridData areaGridData = new GridData();
+ areaGridData.grabExcessVerticalSpace = true;
+ areaGridData.grabExcessHorizontalSpace = true;
+ areaGridData.horizontalAlignment = GridData.FILL;
+ areaGridData.verticalAlignment = GridData.FILL;
+ return areaGridData;
+ }
+
+ /**
+ * get the description
+ * @return the description
+ */
+ public String getDescription() {
+ return m_description.get();
+ }
+
+ /** {@inheritDoc} */
+ protected IDialogSettings getDialogBoundsSettings() {
+ return Activator.getActivator().getDialogSettings();
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/handlers/EditDescriptionHandler.java b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/handlers/EditDescriptionHandler.java
new file mode 100644
index 000000000..972505879
--- /dev/null
+++ b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/handlers/EditDescriptionHandler.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2014 BREDEX GmbH.
+ * 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:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.client.wiki.ui.handlers;
+
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jubula.client.core.events.DataEventDispatcher;
+import org.eclipse.jubula.client.core.model.INodePO;
+import org.eclipse.jubula.client.core.model.IPersistentObject;
+import org.eclipse.jubula.client.ui.constants.ContextHelpIds;
+import org.eclipse.jubula.client.ui.handlers.AbstractSelectionBasedHandler;
+import org.eclipse.jubula.client.ui.rcp.Plugin;
+import org.eclipse.jubula.client.ui.rcp.controllers.IEditorOperation;
+import org.eclipse.jubula.client.ui.rcp.editors.AbstractJBEditor;
+import org.eclipse.jubula.client.ui.utils.DialogUtils;
+import org.eclipse.jubula.client.wiki.ui.dialogs.DescriptionEditDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+/**
+ *
+ * @author BREDEX GmbH
+ */
+public class EditDescriptionHandler extends AbstractSelectionBasedHandler {
+
+ /** {@inheritDoc} */
+ protected Object executeImpl(ExecutionEvent event) {
+ final AbstractJBEditor editor = (AbstractJBEditor) HandlerUtil
+ .getActiveEditor(event);
+ if (editor != null) {
+ editor.getEditorHelper().doEditorOperation(new IEditorOperation() {
+ public void run(IPersistentObject workingPo) {
+ IStructuredSelection selection = (IStructuredSelection)
+ editor.getSelection();
+ INodePO workNode = (INodePO) selection.getFirstElement();
+ DescriptionEditDialog dialog =
+ new DescriptionEditDialog(getActiveShell(),
+ workNode);
+ dialog.setHelpAvailable(true);
+ dialog.create();
+ DialogUtils.setWidgetNameForModalDialog(dialog);
+ Plugin.getHelpSystem().setHelp(dialog.getShell(),
+ ContextHelpIds.EDIT_DESCRIPTION);
+
+ if (dialog.open() == Window.OK) {
+ performChanges(editor, workNode, dialog);
+ }
+ }
+
+ });
+ }
+ return null;
+ }
+
+ /**
+ * Performs the changes done in the {@link DescriptionEditDialog}
+ * @param editor an editor like {@link TestCaseEditor} or {@link TestSuiteEditor}
+ * @param workNode the {@link INodePO} which should be worked on
+ * @param dialog the {@link DescriptionEditDialog}
+ */
+ private void performChanges(final AbstractJBEditor editor,
+ INodePO workNode, DescriptionEditDialog dialog) {
+ if (StringUtils.isBlank(workNode.getDescription())
+ && StringUtils.isBlank(dialog.getDescription())) {
+ return;
+ }
+ if (StringUtils.equals(workNode.getDescription(),
+ dialog.getDescription())) {
+ return;
+ }
+ workNode.setDescription(dialog.getDescription());
+ editor.getEditorHelper().setDirty(true);
+ DataEventDispatcher.getInstance().dataModified(workNode);
+ }
+}
diff --git a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/Messages.java b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/Messages.java
index 9caa8fbf3..9d913708b 100644
--- a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/Messages.java
+++ b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/Messages.java
@@ -17,7 +17,11 @@ import org.eclipse.osgi.util.NLS;
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.jubula.client.wiki.ui.i18n.messages"; //$NON-NLS-1$
-
+
+ public static String EditDescriptionDialogDescription;
+ public static String EditDescriptionDialogPreview;
+ public static String EditDescriptionDialogSourceViewer;
+ public static String EditDescriptionDialogTitle;
public static String NoDescriptionAvailable;
static {
diff --git a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/messages.properties b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/messages.properties
index 6c10816c7..98d68395a 100644
--- a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/messages.properties
+++ b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/i18n/messages.properties
@@ -5,4 +5,8 @@
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
##############################################################################
-NoDescriptionAvailable=No description available... \ No newline at end of file
+NoDescriptionAvailable=No description available...
+EditDescriptionDialogTitle=Edit description
+EditDescriptionDialogDescription=Edit the description of the Node
+EditDescriptionDialogSourceViewer= Source Editor
+EditDescriptionDialogPreview=Preview \ No newline at end of file
diff --git a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/views/DescriptionView.java b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/views/DescriptionView.java
index 0853fd3b7..a9243e544 100644
--- a/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/views/DescriptionView.java
+++ b/org.eclipse.jubula.client.wiki.ui/src/org/eclipse/jubula/client/wiki/ui/views/DescriptionView.java
@@ -11,13 +11,17 @@
package org.eclipse.jubula.client.wiki.ui.views;
import java.net.URL;
-
import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.URLHyperlink;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jubula.client.core.events.DataChangedEvent;
+import org.eclipse.jubula.client.core.events.DataEventDispatcher;
+import org.eclipse.jubula.client.core.events.DataEventDispatcher.IDataChangedListener;
+import org.eclipse.jubula.client.core.model.IExecTestCasePO;
import org.eclipse.jubula.client.core.model.INodePO;
+import org.eclipse.jubula.client.core.model.IRefTestSuitePO;
import org.eclipse.jubula.client.wiki.ui.i18n.Messages;
import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;
import org.eclipse.mylyn.wikitext.mediawiki.core.MediaWikiLanguage;
@@ -34,11 +38,13 @@ import org.eclipse.ui.part.ViewPart;
/**
* @author BREDEX GmbH
*/
-public class DescriptionView extends ViewPart {
+public class DescriptionView extends ViewPart implements IDataChangedListener {
/** the viewer to display the documentation */
private Browser m_browser;
/** the markup parser to use */
private MarkupParser m_markupParser;
+ /** the selected Node - needed for reloading reasons*/
+ private INodePO m_selectedNode;
/** the m_listener we register with the selection service */
private ISelectionListener m_listener = new ISelectionListener() {
@@ -60,22 +66,21 @@ public class DescriptionView extends ViewPart {
(StructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof INodePO) {
- INodePO node = (INodePO) firstElement;
- final String comment = node.getComment();
- if (StringUtils.isNotEmpty(comment)) {
- m_browser.setText(m_markupParser
- .parseToHtml(comment));
- return;
- }
+ m_selectedNode = (INodePO) firstElement;
+ setDescriptionForBrowser(m_selectedNode);
+ return;
}
+ setBrowserNoDescriptionAvailable();
+ return;
}
- m_browser.setText(Messages.NoDescriptionAvailable);
+ setBrowserNoDescriptionAvailable();
}
};
/** {@inheritDoc} */
public void createPartControl(Composite parent) {
m_browser = new Browser(parent, SWT.NONE);
+ DataEventDispatcher.getInstance().addDataChangedListener(this, true);
/*
* taken from
* org.eclipse.mylyn.internal.wikitext.ui.editor.MarkupEditor
@@ -132,4 +137,58 @@ public class DescriptionView extends ViewPart {
.removeSelectionListener(m_listener);
super.dispose();
}
+
+ /** {@inheritDoc} */
+ public void handleDataChanged(DataChangedEvent... events) {
+ boolean isRefreshNecessary = false;
+ for (DataChangedEvent dataChangedEvent : events) {
+ if (m_selectedNode.equals(dataChangedEvent.getPo())) {
+ isRefreshNecessary = true;
+ }
+ }
+ if (isRefreshNecessary) {
+ setDescriptionForBrowser(m_selectedNode);
+ }
+ }
+
+ /**
+ * gets the description of the referenced {@link ISpecTestCasePO} or {@link ITestSuitePO}
+ * @param node the {@link IExecTestCasePO} or {@link IRefTestSuitePO}
+ * @return the description of the corresponding {@link ISpecTestCasePO} or {@link ITestSuitePO},
+ * may be null
+ */
+ private String getReferenceDescription(INodePO node) {
+ String description = null;
+ if (node instanceof IExecTestCasePO) {
+ IExecTestCasePO exec = (IExecTestCasePO) node;
+ description = exec.getSpecTestCase().getDescription();
+ }
+ if (node instanceof IRefTestSuitePO) {
+ IRefTestSuitePO refTestSuite = (IRefTestSuitePO) node;
+ description = refTestSuite.getTestSuite().getDescription();
+ }
+ return description;
+ }
+
+ /**
+ *
+ * @param element the object to check if there is a description
+ */
+ private void setDescriptionForBrowser(INodePO element) {
+ String description = m_selectedNode.getDescription();
+ if (StringUtils.isBlank(description)) {
+ description = getReferenceDescription(m_selectedNode);
+ }
+ if (StringUtils.isNotBlank(description)) {
+ m_browser.setText(m_markupParser.parseToHtml(description));
+ return;
+ }
+ setBrowserNoDescriptionAvailable();
+ }
+ /**
+ * sets the Browser text to have noc description
+ */
+ private void setBrowserNoDescriptionAvailable() {
+ m_browser.setText(Messages.NoDescriptionAvailable);
+ }
} \ No newline at end of file

Back to the top