Merge "Disable script clearing when the window is minimized Make test for clear script button Change-Id: Iec50cb6837c211eb02e4d2aa8fa71d628af9ad07 Signed-off-by: Galina Shvetsova <galina.shvetsova@xored.com>"
diff --git a/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/ecl/EclEditor.java b/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/ecl/EclEditor.java
index 16c67e5..2a6032a 100644
--- a/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/ecl/EclEditor.java
+++ b/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/ecl/EclEditor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2019 Xored Software Inc and others.
+ * Copyright (c) 2009, 2020 Xored Software Inc and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -151,6 +151,8 @@
 import org.eclipse.ui.IWorkbenchPartConstants;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.IExpansionListener;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.ide.IGotoMarker;
 import org.eclipse.ui.operations.OperationHistoryActionHandler;
@@ -193,7 +195,8 @@
 		return occurrencesFinderJob;
 	}
 
-	public void replaceOccurencesAnnotation(IAnnotationModel annotationModel, Map<Annotation, Position> annotationsToAdd) {
+	public void replaceOccurencesAnnotation(IAnnotationModel annotationModel,
+			Map<Annotation, Position> annotationsToAdd) {
 		((IAnnotationModelExtension) annotationModel).replaceAnnotations(occurrencesAnnotations, annotationsToAdd);
 	}
 
@@ -315,8 +318,7 @@
 	@Override
 	protected IVerticalRulerColumn createAnnotationRulerColumn(
 			CompositeRuler ruler) {
-		AnnotationRulerColumn column = (AnnotationRulerColumn) super
-				.createAnnotationRulerColumn(ruler);
+		AnnotationRulerColumn column = (AnnotationRulerColumn) super.createAnnotationRulerColumn(ruler);
 		column.addAnnotationType(Q7Builder.MARKER_TYPE);
 		return column;
 	}
@@ -365,8 +367,7 @@
 			if (msg.getFeature() != null) {
 				if (msg.getFeature().equals(
 						ScenarioPackage.Literals.SCENARIO__CONTEXTS)
-						|| msg.getFeature().
-								equals(ScenarioPackage.Literals.SCENARIO__VERIFICATIONS)
+						|| msg.getFeature().equals(ScenarioPackage.Literals.SCENARIO__VERIFICATIONS)
 						|| msg.getFeature()
 								.equals(ScenarioPackage.Literals.GROUP_CONTEXT__CONTEXT_REFERENCES)) {
 					checkReferences();
@@ -645,17 +646,17 @@
 
 	@Override
 	public void createPartControl(Composite masterParent) {
-		
+
 		masterParent.setLayout(new FillLayout());
 		Composite parent = new Composite(masterParent, SWT.NONE);
-		
+
 		FormToolkit toolkit = new FormToolkit(parent.getDisplay());
 		GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(parent);
-//		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
+		// parent.setLayoutData(new GridData(GridData.FILL_BOTH));
 
 		Composite top = toolkit.createComposite(parent);
 		top.setLayoutData(new GridData(GridData.FILL_BOTH));
-		
+
 		parent.setData("my_layout_should_be_grid", true);
 
 		header = createEditorHeader();
@@ -674,17 +675,26 @@
 			ToolBar toolBar = manager.createControl(section.getToolbar());
 			toolBar.moveAbove(null);
 
-			IAction clearAction = new Action() {
+			final IAction clearAction = new Action() {
 				@Override
 				public void run() {
 					getViewer().getDocument().set("");
 					// Scenarios.setEclContent(element, "");
 				}
 			};
-			clearAction.setImageDescriptor(Images
-					.getImageDescriptor(Images.PANEL_CLEAR));
-			clearAction
-					.setToolTipText(Messages.ScriptComposite_ClearActionToolTip);
+			clearAction.setImageDescriptor(Images.getImageDescriptor(Images.PANEL_CLEAR));
+			clearAction.setToolTipText(Messages.ScriptComposite_ClearActionToolTip);
+			section.getSection().addExpansionListener(new IExpansionListener() {
+				@Override
+				public void expansionStateChanging(ExpansionEvent e) {
+					clearAction.setEnabled(e.getState());
+				}
+
+				@Override
+				public void expansionStateChanged(ExpansionEvent e) {
+				}
+
+			});
 			manager.add(clearAction);
 
 			manager.update(true);
@@ -878,8 +888,7 @@
 							}
 							return;
 						}
-					}
-					finally {
+					} finally {
 						updateActions();
 					}
 				}
@@ -1438,7 +1447,7 @@
 		EclOpenDeclarationAction action = new EclOpenDeclarationAction(this);
 		action.setActionDefinitionId(GO_TO_DECLARATION_ACTION);
 		setAction(GO_TO_DECLARATION_ACTION, action);
-		
+
 		if (menu != null) {
 			addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, GO_TO_DECLARATION_GROUP);
 			addAction(menu, GO_TO_DECLARATION_GROUP, GO_TO_DECLARATION_ACTION);
diff --git a/rcpttTests/platform_tests/Editing/TestCase/ClearScript.test b/rcpttTests/platform_tests/Editing/TestCase/ClearScript.test
new file mode 100644
index 0000000..f0ae0e8
--- /dev/null
+++ b/rcpttTests/platform_tests/Editing/TestCase/ClearScript.test
@@ -0,0 +1,97 @@
+--- RCPTT testcase ---
+Format-Version: 1.0
+Contexts: _tlWZcGphEeCzId1Gnkds9A,_4zI9AWpgEeCzId1Gnkds9A
+Element-Name: ClearScript
+Element-Type: testcase
+Element-Version: 3.0
+External-Reference: 
+Id: _C5WbwEmvEeq3N-17Rp0qDw
+Save-Time: 2/7/20 9:02 PM
+Testcase-Type: ecl
+
+------=_.description-216f885c-d591-38ce-8ea2-e4f8cb4d6ffa
+Content-Type: text/plain
+Entry-Name: .description
+
+Copyright (c) 2020 Xored Software Inc and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v2.0
+which accompanies this distribution, and is available at
+https://www.eclipse.org/legal/epl-v20.html
+
+Contributors:
+    Xored Software Inc - initial creation and/or initial documentation
+--------------------------------------------------------------------------------
+
+TEST STEPS
+
+1. Create new test case through "New Test Case" window
+2. Verify that new test case is created successfully and is displayed in Q7 Explorer
+3. Open this test case
+4. Verify that test case is empty
+5. Add script
+6. Verify that script is not empty
+7. Clean script through "Clean script"
+8. Verify that script is  empty
+9. Verify that clean button is  enabled
+10. Add script
+11. Verify that script is not empty
+12. Minimize script section through click on "Script"
+13. Verify that clean button is not enabled
+14. Expand script section through click on "Script"
+15. Verify that script is not empty
+------=_.description-216f885c-d591-38ce-8ea2-e4f8cb4d6ffa--
+------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
+Content-Type: text/ecl
+Entry-Name: .content
+
+get-view "Test Explorer" | get-tree | select TestQ7Prj | get-menu "New/Test Case" | click
+with [get-window "New Test Case"] {
+    get-editbox -after [get-label "Name:"] | set-text "Test scenario"
+    get-button Finish | click
+}
+with [get-editor "Test scenario"] {
+    get-editbox -after [get-label "Name:"] | get-property value | equals "Test scenario" | verify-true
+    get-button Record | get-property enablement | equals true | verify-true
+    get-button Replay | get-property enablement | equals true | verify-true
+    get-button | get-property enablement | equals true | verify-true
+    with [get-section Contexts] {
+        get-button "Add..." | get-property enablement | equals true | verify-true
+        get-button Remove | get-property enablement | equals false | verify-true
+        get-button Up | get-property enablement | equals false | verify-true
+        get-button Down | get-property enablement | equals false | verify-true
+    }
+    get-section Script | get-button -index 0 | get-property enablement | equals true | verify-true
+}
+with [get-editor "Test scenario" | get-section Script | get-text-viewer] {
+    type-text "some "
+    show-content-assist
+    type-text "script "
+    show-content-assist
+    type-text "is here"
+    key-type "M1+s"
+}
+get-editor "Test scenario" | get-section Script | get-text-viewer | get-property text | equals "some script is here" 
+    | verify-true
+with [get-editor "Test scenario" | get-section Script] {
+    get-button "Clear Script" | click
+    get-text-viewer | set-caret-pos 1 1
+}
+
+with [get-editor "Test scenario" | get-section Script | get-text-viewer] {
+    type-text "another "
+    show-content-assist
+    type-text script
+    key-type "M1+s"
+}
+with [get-editor "Test scenario" | get-section Script] {
+    get-button "Clear Script" | get-property enablement | equals true | verify-true
+    get-text-viewer | get-property text | equals "another script" | verify-true
+}
+get-editor "Test scenario" | get-section Script | click
+get-editor "Test scenario" | get-section Script | get-button "Clear Script" | get-property enablement | equals false 
+    | verify-true
+get-editor "Test scenario" | get-section Script | click
+get-editor "Test scenario" | get-section Script | get-text-viewer | get-property text | equals "another script" 
+    | verify-true
+------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--