Author: mareshkau
Date: 2010-11-17 06:43:15 -0500 (Wed, 17 Nov 2010)
New Revision: 26664
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/handlers/
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/handlers/VpeCommandsTests.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java
Log:
junit for
https://jira.jboss.org/browse/JBIDE-7475, page design options handler has been
fixed
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF 2010-11-17 10:48:13 UTC
(rev 26663)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF 2010-11-17 11:43:15 UTC
(rev 26664)
@@ -34,6 +34,7 @@
org.jboss.tools.vpe.editor.util,
org.jboss.tools.vpe.editor.wizards,
org.jboss.tools.vpe.editor.xpl,
+ org.jboss.tools.vpe.handlers,
org.jboss.tools.vpe.messages
Require-Bundle: org.eclipse.jface.text,
org.jboss.tools.jst.jsp,
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java 2010-11-17
10:48:13 UTC (rev 26663)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java 2010-11-17
11:43:15 UTC (rev 26664)
@@ -13,11 +13,13 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -66,31 +68,38 @@
@Override
public void setEnabled(Object evaluationContext) {
- IEditorPart activeEditor = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if (activeEditor == null) {
- return;
- }
- IEditorInput input = activeEditor.getEditorInput();
- IFile file = null;
- if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput) input).getFile();
- } else if (input instanceof ILocationProvider) {
- ILocationProvider provider = (ILocationProvider) input;
- IPath path = provider.getPath(input);
- if (path != null) {
- file = FileUtil.getFile(input, path.lastSegment());
+ IEditorPart activeEditor = null;
+ if (evaluationContext instanceof IEvaluationContext) {
+ IEvaluationContext context = (IEvaluationContext) evaluationContext;
+ Object editor = context.getVariable(ISources.ACTIVE_EDITOR_NAME);
+ if(editor instanceof IEditorPart){
+ activeEditor = (IEditorPart) editor;
}
}
boolean isVisualPartVisible=false;
+ boolean isFileExists=false;
+ if (activeEditor != null) {
+
+ IEditorInput input = activeEditor.getEditorInput();
+ IFile file = null;
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
+ } else if (input instanceof ILocationProvider) {
+ ILocationProvider provider = (ILocationProvider) input;
+ IPath path = provider.getPath(input);
+ if (path != null) {
+ file = FileUtil.getFile(input, path.lastSegment());
+ isFileExists = file != null && file.exists();
+ }
+ }
+ isFileExists = file != null && file.exists();
+
if(activeEditor instanceof JSPMultiPageEditor){
- JSPMultiPageEditor jspEditor = (JSPMultiPageEditor) activeEditor;
- if(jspEditor.getVisualEditor().getController()!=null)
- isVisualPartVisible=((VpeController)(jspEditor.getVisualEditor().getController())).isVisualEditorVisible();
+ JSPMultiPageEditor jspEditor = (JSPMultiPageEditor) activeEditor;
+ if(jspEditor.getVisualEditor().getController()!=null)
+ isVisualPartVisible=((VpeController)(jspEditor.getVisualEditor().getController())).isVisualEditorVisible();
}
-
-
- boolean isFileExists = file != null && file.exists();
+ }
boolean enabled=isFileExists&&isVisualPartVisible;
if (isEnabled() != enabled) {
setBaseEnabled(enabled);
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java 2010-11-17
10:48:13 UTC (rev 26663)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java 2010-11-17
11:43:15 UTC (rev 26664)
@@ -185,7 +185,7 @@
// TestUtil.waitForJobs();
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
- IWorkbenchPart part = page.getViewReferences()[0].getPart(false);
+ IWorkbenchPart part = page.getActivePart();
page.activate(part);
// close
page.closeAllEditors(false);
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java 2010-11-17
10:48:13 UTC (rev 26663)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java 2010-11-17
11:43:15 UTC (rev 26664)
@@ -12,11 +12,10 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-
-import org.jboss.tools.vpe.editor.menu.VpePopupMenuTest;
import org.jboss.tools.vpe.ui.test.dialog.VpeEditAnyDialogTest;
import org.jboss.tools.vpe.ui.test.dialog.VpeResourcesDialogTest;
import org.jboss.tools.vpe.ui.test.editor.CustomSashFormTest;
+import org.jboss.tools.vpe.ui.test.handlers.VpeCommandsTests;
import org.jboss.tools.vpe.ui.test.preferences.VpeEditorPreferencesPageTest;
/**
@@ -32,6 +31,7 @@
suite.addTestSuite(CustomSashFormTest.class);
//suite.addTestSuite(VpePopupMenuTest.class);
suite.addTestSuite(VpeEditAnyDialogTest.class);
+ suite.addTestSuite(VpeCommandsTests.class);
return new VpeTestSetup(suite);
}
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/handlers/VpeCommandsTests.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/handlers/VpeCommandsTests.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/handlers/VpeCommandsTests.java 2010-11-17
11:43:15 UTC (rev 26664)
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.ui.test.handlers;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditorPart;
+import org.jboss.tools.vpe.handlers.PageDesignOptionsHandler;
+import org.jboss.tools.vpe.handlers.PreferencesHandler;
+import org.jboss.tools.vpe.handlers.RefreshHandler;
+import org.jboss.tools.vpe.handlers.RotateEditorsHandler;
+import org.jboss.tools.vpe.handlers.ShowBorderHandler;
+import org.jboss.tools.vpe.handlers.ShowBundleAsELHandler;
+import org.jboss.tools.vpe.handlers.ShowNonVisualTagsHandler;
+import org.jboss.tools.vpe.handlers.ShowTextFormattingHandler;
+import org.jboss.tools.vpe.ui.test.TestUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+import org.jboss.tools.vpe.ui.test.VpeUiTests;
+
+/**
+ * Class which created for testing VPE commands behavior,
+ * see
https://jira.jboss.org/browse/JBIDE-7383
+ *
+ * @author mareshkau
+ *
+ */
+public class VpeCommandsTests extends VpeTest{
+
+ private static String[] VPE_COMMAND_ID;
+ private Command[] commands;
+
+ static {
+ VPE_COMMAND_ID = new String[]{
+ PageDesignOptionsHandler.COMMAND_ID,
+ PreferencesHandler.COMMAND_ID,
+ RefreshHandler.COMMAND_ID,
+ RotateEditorsHandler.COMMAND_ID,
+ ShowBorderHandler.COMMAND_ID,
+ ShowBundleAsELHandler.COMMAND_ID,
+ ShowNonVisualTagsHandler.COMMAND_ID,
+ ShowTextFormattingHandler.COMMAND_ID
+ };
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ICommandService commandService =
+ (ICommandService) PlatformUI.getWorkbench()
+ .getService(ICommandService.class);
+ commands = new Command[VPE_COMMAND_ID.length];
+ for(int i=0;i<commands.length;i++){
+ commands[i] = commandService.getCommand(VPE_COMMAND_ID[i]);
+ }
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ IViewReference[] views = page.getViewReferences();
+ for (IViewReference iViewReference : views) {
+ page.hideView(iViewReference);
+ }
+ }
+
+ public VpeCommandsTests(String name) {
+ super(name);
+ }
+
+ /**
+ * Test VPE command state
+ * @throws Throwable
+ */
+ public void testCommandState() throws Throwable {
+ //initially all commands should be disabled
+ checkCommadState(false);
+
+ IFile vpeFile = (IFile) TestUtil.getComponentPath("inputUserName.jsp",
+ VpeUiTests.IMPORT_PROJECT_NAME);
+
+ /*
+ * Open file in the VPE
+ */
+ IEditorInput input = new FileEditorInput(vpeFile);
+ JSPMultiPageEditor multiPageEditor = openEditor(input);
+ TestUtil.delay(500);
+ pageChange(multiPageEditor, 0);
+ checkCommadState(true);
+ pageChange(multiPageEditor, 1);
+ checkCommadState(false);
+ pageChange(multiPageEditor, multiPageEditor.getPreviewIndex());
+ checkCommadState(false);
+ pageChange(multiPageEditor,0);
+ checkCommadState(true);
+ }
+
+ private void pageChange(JSPMultiPageEditor multiPageEditor, int index) throws
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
+ Method pageChange;
+ pageChange = JSPMultiPageEditorPart.class.getDeclaredMethod("setActivePage",
new Class[]{int.class});
+ pageChange.setAccessible(true);
+ pageChange.invoke(multiPageEditor, index);
+ multiPageEditor.pageChange(index);
+ }
+ //checks command state
+ private void checkCommadState(boolean expected){
+ for (Command vpeCommand : commands) {
+ assertEquals("Command "+vpeCommand.getId()+" should be
active",expected,vpeCommand.isEnabled());
+ }
+ }
+}
Property changes on:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/handlers/VpeCommandsTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain