JBoss Tools SVN: r10549 - in trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE: 2774 and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-09-29 14:39:59 -0400 (Mon, 29 Sep 2008)
New Revision: 10549
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/common.xhtml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/jbide2774test.xhtml
Log:
=JBIDE-2774
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/common.xhtml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/common.xhtml (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/common.xhtml 2008-09-29 18:39:59 UTC (rev 10549)
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <f:loadBundle basename="resources" var="msg" />
+ <head>
+ <link />
+ <title><ui:insert name="pageTitle">Page Title</ui:insert></title>
+ <style type="text/css">
+ body {
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-size: 14px;
+ }
+ .header {
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-size: 18px;
+ }
+ .bottom {
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-size: 9px;
+ text-align: center;
+ vertical-align: middle;
+ color: #8E969D;
+ }
+ </style>
+ </head>
+
+<body bgcolor="#ffffff">
+<table style="border:1px solid #CAD6E0" align="center" cellpadding="0" cellspacing="0" border="0" width="400">
+<tbody>
+ <h:outputText value="" />
+ <tr>
+ <td class="header" height="42" align="center" valign="middle" width="100%" bgcolor="#E4EBEB">
+ <ui:insert name="pageHeader">Page Header</ui:insert>
+ </td>
+ </tr>
+ <tr>
+ <td height="1" width="100%" bgcolor="#CAD6E0"></td>
+ </tr>
+
+ <tr>
+ <td width="100%" colspan="2">
+ <table width="100%" style="height:150px" align="left" cellpadding="0" cellspacing="0" border="0">
+ <tbody>
+ <tr>
+ <td align="center" width="100%" valign="middle">
+
+ <ui:insert name="body">Page Body</ui:insert>
+
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2" valign="bottom" height="1" width="100%" bgcolor="#CAD6E0"></td>
+ </tr>
+</tbody>
+</table>
+</body>
+
+</html>
\ No newline at end of file
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/jbide2774test.xhtml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/jbide2774test.xhtml (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/jsfTest/WebContent/pages/JBIDE/2774/jbide2774test.xhtml 2008-09-29 18:39:59 UTC (rev 10549)
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:rich="http://richfaces.org/rich">
+ <f:loadBundle basename="resources" var="msg" />
+ <ui:composition template="./common.xhtml">
+
+ <ui:define name="pageTitle">JSF 1.2 and Facelets under Tomcat. KickStart Application</ui:define>
+
+ <ui:define name="pageHeader">JSF 1.2 Hello Application</ui:define>
+ <ui:define name="body">
+ <h:outputText value="#{msg.greeting}"/>
+ <h:message showSummary="true" showDetail="false" style="color: red; font-weight: bold;" for="name" />
+ <form jsfc="h:form" id="helloForm">
+ <h:outputText value="sdfsdfsd"/>
+ ${msg.prompt} ${person.name}
+ ${msg.} ${person.name} #{msg.prompt}
+ <input label="Name" jsfc="h:inputText" required="true" id="name" value="#{person.name}" />
+ <input label="Name" jsfc="h:inputText" required="true" id="name" value="#{pperson.name}"/>
+ <input type="submit" jsfc="h:commandButton" id="submit"
+ action="greeting" value="Say Hello" />
+ <rich:calendar style=" height : 58px;"></rich:calendar>
+ <h:rtrtrtrtrt >
+ <h:test1 />
+ <h:test2 />
+ </h:rtrtrtrtrt>
+ </form>
+ </ui:define>
+ </ui:composition>
+</html>
16 years, 3 months
JBoss Tools SVN: r10548 - trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-09-29 14:38:54 -0400 (Mon, 29 Sep 2008)
New Revision: 10548
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624Test.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2774Test.java
Removed:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624.java
Log:
=JBIDE-2774
Deleted: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624.java 2008-09-29 18:35:17 UTC (rev 10547)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624.java 2008-09-29 18:38:54 UTC (rev 10548)
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-
-package org.jboss.tools.jsf.vpe.jsf.test.jbide;
-
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.part.FileEditorInput;
-import org.jboss.tools.common.resref.core.ResourceReference;
-import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
-import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
-import org.jboss.tools.vpe.editor.VpeController;
-import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
-import org.jboss.tools.vpe.ui.test.TestUtil;
-import org.jboss.tools.vpe.ui.test.VpeTest;
-import org.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMNode;
-
-
-/**
- * Test case for testing JBIDE-2624
- *
- * @author Eugene Stherbin
- *
- */
-public class JBIDE2624 extends VpeTest {
-
- /**
- * @param name
- */
- public JBIDE2624(String name) {
- super(name);
- }
-
- public void testJBide2624() throws CoreException {
- // get test page path
- setException(null);
- IFile file = (IFile) TestUtil.getComponentPath("JBIDE/2624/greeting.xhtml", //$NON-NLS-1$
- JsfAllTests.IMPORT_PROJECT_NAME);
- assertNotNull("Could not open specified file " + file.getFullPath(), //$NON-NLS-1$
- file);
-
- IEditorInput input = new FileEditorInput(file);
-
- assertNotNull("Editor input is null", input); //$NON-NLS-1$
-
- // open and get editor
- JSPMultiPageEditor part = openEditor(input);
-
- VpeController vpeController = getVpeController(part);
-
- nsIDOMDocument document = getVpeVisualDocument(part);
-
- nsIDOMElement element = document.getDocumentElement();
-
- List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
-
- TestUtil.findAllElementsByName(element, elements, HTML.TAG_TABLE);
-
- assertTrue("Faceletes loaded, but shouldn't", elements.size() == 0); //$NON-NLS-1$
- ResourceReference[] resourceReference = new ResourceReference[1];
- resourceReference[0] = new ResourceReference(file.getParent().getLocation().toString() + File.separator + "templates",
- ResourceReference.PROJECT_SCOPE);
- RelativeFolderReferenceList.getInstance().setAllResources(file, resourceReference);
- TestUtil.delay(1000);
- vpeController.visualRefresh();
- TestUtil.delay(1000);
- document = getVpeVisualDocument(part);
- element = document.getDocumentElement();
- elements = new ArrayList<nsIDOMNode>();
- TestUtil.findAllElementsByName(element, elements, HTML.TAG_TABLE);
-
- assertTrue("Faceletes wasn't loaded from specified path", elements.size() >= 1); //$NON-NLS-1$
-
- }
-
-}
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624Test.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624Test.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2624Test.java 2008-09-29 18:38:54 UTC (rev 10548)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+
+package org.jboss.tools.jsf.vpe.jsf.test.jbide;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.common.resref.core.ResourceReference;
+import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
+import org.jboss.tools.vpe.ui.test.TestUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+
+
+/**
+ * Test case for testing JBIDE-2624
+ *
+ * @author Eugene Stherbin
+ *
+ */
+public class JBIDE2624Test extends VpeTest {
+
+ /**
+ * @param name
+ */
+ public JBIDE2624Test(String name) {
+ super(name);
+ }
+
+ public void testJBide2624() throws CoreException {
+ // get test page path
+ setException(null);
+ IFile file = (IFile) TestUtil.getComponentPath("JBIDE/2624/greeting.xhtml", //$NON-NLS-1$
+ JsfAllTests.IMPORT_PROJECT_NAME);
+ assertNotNull("Could not open specified file " + file.getFullPath(), //$NON-NLS-1$
+ file);
+
+ IEditorInput input = new FileEditorInput(file);
+
+ assertNotNull("Editor input is null", input); //$NON-NLS-1$
+
+ // open and get editor
+ JSPMultiPageEditor part = openEditor(input);
+
+ VpeController vpeController = getVpeController(part);
+
+ nsIDOMDocument document = getVpeVisualDocument(part);
+
+ nsIDOMElement element = document.getDocumentElement();
+
+ List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
+
+ TestUtil.findAllElementsByName(element, elements, HTML.TAG_TABLE);
+
+ assertTrue("Faceletes loaded, but shouldn't", elements.size() == 0); //$NON-NLS-1$
+ ResourceReference[] resourceReference = new ResourceReference[1];
+ resourceReference[0] = new ResourceReference(file.getParent().getLocation().toString() + File.separator + "templates",
+ ResourceReference.PROJECT_SCOPE);
+ RelativeFolderReferenceList.getInstance().setAllResources(file, resourceReference);
+ TestUtil.delay(1000);
+ vpeController.visualRefresh();
+ TestUtil.delay(1000);
+ document = getVpeVisualDocument(part);
+ element = document.getDocumentElement();
+ elements = new ArrayList<nsIDOMNode>();
+ TestUtil.findAllElementsByName(element, elements, HTML.TAG_TABLE);
+
+ assertTrue("Faceletes wasn't loaded from specified path", elements.size() >= 1); //$NON-NLS-1$
+
+ }
+
+}
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2774Test.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2774Test.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2774Test.java 2008-09-29 18:38:54 UTC (rev 10548)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+* Copyright (c) 2007-2008 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.jsf.vpe.jsf.test.jbide;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.ui.test.TestUtil;
+import org.jboss.tools.vpe.ui.test.VpeTest;
+
+/**
+ * Test class for JBIDE-2774
+ * @author mareshkau
+ *
+ */
+public class JBIDE2774Test extends VpeTest {
+
+ /**
+ *
+ * @param name
+ */
+ public JBIDE2774Test(String name) {
+ super(name);
+ }
+
+ /**
+ * Test case for jbide-2774
+ *
+ * @throws Throwable
+ */
+ public void testJBIDE2774() throws Throwable {
+ setException(null);
+
+ // get test page path
+ IFile file = (IFile) TestUtil.getComponentPath("JBIDE/2774/jbide2774test.xhtml", //$NON-NLS-1$
+ JsfAllTests.IMPORT_PROJECT_NAME);
+
+ IEditorInput input = new FileEditorInput(file);
+
+ // open and get editor
+ JSPMultiPageEditor part = openEditor(input);
+
+
+ int offcet = TestUtil.getLinePositionOffcet(part.getSourceEditor().getTextViewer(), 21, 25);
+ //sets selection
+ part.getSourceEditor().getTextViewer().setSelectedRange(offcet, 2);
+
+ Point selectionRangeBeforeRefresh = part.getSourceEditor().getTextViewer().getSelectedRange();
+ // get controller
+ VpeController controller = getVpeController(part);
+ assertNotNull(controller);
+
+ controller.visualRefresh();
+ TestUtil.delay(500);
+ Point selectionRangeAfterRefresh = part.getSourceEditor().getTextViewer().getSelectedRange();
+
+ assertEquals("Selection should be before and after refresh equals", selectionRangeBeforeRefresh,selectionRangeAfterRefresh); //$NON-NLS-1$
+
+ if(getException()!=null) {
+ throw getException();
+ }
+ }
+
+}
16 years, 3 months
JBoss Tools SVN: r10547 - in trunk: vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-09-29 14:35:17 -0400 (Mon, 29 Sep 2008)
New Revision: 10547
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
Log:
JBIDE-2774
Modified: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2008-09-29 18:32:42 UTC (rev 10546)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2008-09-29 18:35:17 UTC (rev 10547)
@@ -36,7 +36,8 @@
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE2582Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE2584Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE2594Test;
-import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE2624;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE2624Test;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE2774Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE675Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE788Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE924Test;
@@ -94,9 +95,10 @@
suite.addTestSuite(JBIDE2594Test.class);
suite.addTestSuite(JBIDE924Test.class);
suite.addTestSuite(JBIDE2526Test.class);
- suite.addTestSuite(JBIDE2624.class);
+ suite.addTestSuite(JBIDE2624Test.class);
suite.addTestSuite(JBIDE1805Test.class);
suite.addTestSuite(JsfComponentContentTest.class);
+ suite.addTestSuite(JBIDE2774Test.class);
// $JUnit-END$
// added by Max Areshkau
// add here projects which should be imported for junit tests
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-09-29 18:32:42 UTC (rev 10546)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-09-29 18:35:17 UTC (rev 10547)
@@ -3283,28 +3283,39 @@
}
public void reinit() {
-
- visualBuilder.setSelectionRectangle(null);
- visualEditor.setEditorDomEventListener(this);
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel != null) {
- IDOMDocument sourceDocument = sourceModel.getDocument();
- visualBuilder.rebuildDom(sourceDocument);
- } else {
- visualBuilder.rebuildDom(null);
+ try {
+ if(!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ visualBuilder.setSelectionRectangle(null);
+ visualEditor.setEditorDomEventListener(this);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel != null) {
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.rebuildDom(sourceDocument);
+ } else {
+ visualBuilder.rebuildDom(null);
+ }
+ //reinits selection controller+ controller
+ visualEditor.reinitDesignMode();
+ visualSelectionController = new VpeSelectionController(visualEditor.getEditor().getSelectionController());
+
+ selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
+ visualBuilder, visualSelectionController);
+
+ selectionManager = new SelectionManager(pageContext,
+ sourceEditor, visualSelectionController);
+
+ keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
+ pageContext,visualSelectionController);
+ //restore selection in visula part
+ sourceSelectionChanged();
+ }finally {
+
+ switcher.stopActiveEditor();
}
- //reinits selection controller+ controller
- visualEditor.reinitDesignMode();
- visualSelectionController = new VpeSelectionController(visualEditor.getEditor().getSelectionController());
-
- selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
- visualBuilder, visualSelectionController);
-
- selectionManager = new SelectionManager(pageContext,
- sourceEditor, visualSelectionController);
-
- keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
- pageContext,visualSelectionController);
+
}
/**
16 years, 3 months
JBoss Tools SVN: r10546 - in trunk/as/plugins: org.jboss.ide.eclipse.archives.webtools/META-INF and 5 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-09-29 14:32:42 -0400 (Mon, 29 Sep 2008)
New Revision: 10546
Added:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/icons/multiple_files.gif
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetViewProvider.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/FilesetViewProvider.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
Log:
JBIDE-2798 - as.ui not resolving on its own. Fix was to move code to the archives / wtp integration plugin
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF 2008-09-29 17:50:09 UTC (rev 10545)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF 2008-09-29 18:32:42 UTC (rev 10546)
@@ -16,7 +16,9 @@
org.eclipse.wst.common.modulecore;bundle-version="1.1.200",
org.apache.ant;bundle-version="1.7.0",
org.jboss.ide.eclipse.as.core;bundle-version="1.0.0",
- org.eclipse.ui.ide;bundle-version="3.4.0"
+ org.eclipse.ui.ide;bundle-version="3.4.0",
+ org.jboss.ide.eclipse.as.ui;bundle-version="1.0.0",
+ org.eclipse.core.filesystem;bundle-version="1.2.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.jboss.ide.eclipse.archives.webtools,
Added: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/icons/multiple_files.gif
===================================================================
(Binary files differ)
Property changes on: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/icons/multiple_files.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml 2008-09-29 17:50:09 UTC (rev 10545)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml 2008-09-29 18:32:42 UTC (rev 10546)
@@ -5,9 +5,9 @@
point="org.eclipse.wst.server.core.moduleTypes">
<moduleType
id="jboss.package"
- name="Project Package"/>
+ name="Project Package"/>
</extension>
-
+
<extension
point="org.jboss.ide.eclipse.archives.core.archiveTypes">
<packageType
@@ -49,8 +49,8 @@
types="jboss.package"
versions="1.0"/>
</moduleFactory>
- </extension>
-
+ </extension>
+
<extension
point="org.jboss.ide.eclipse.archives.ui.nodePopupMenus">
<nodeContribution
@@ -91,4 +91,13 @@
priority="5">
</publisher>
</extension>
+ <extension
+ point="org.jboss.ide.eclipse.as.ui.ServerViewExtension">
+ <ViewProvider
+ description="A front end to open, edit, or view files in your server's directories."
+ icon="icons/multiple_files.gif"
+ id="org.jboss.ide.eclipse.as.ui.FilesetViewProvider"
+ name="File Filters"
+ providerClass="org.jboss.ide.eclipse.archives.webtools.ui.FilesetViewProvider"/>
+ </extension>
</plugin>
Added: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetViewProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetViewProvider.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetViewProvider.java 2008-09-29 18:32:42 UTC (rev 10546)
@@ -0,0 +1,765 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+* This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildException;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.runtime.content.IContentTypeMatcher;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+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.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.FileStoreEditorInput;
+import org.eclipse.ui.internal.Workbench;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
+import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
+import org.jboss.ide.eclipse.archives.ui.util.composites.FilesetPreviewComposite;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
+import org.jboss.ide.eclipse.as.ui.Messages;
+import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
+import org.jboss.ide.eclipse.as.ui.views.server.extensions.SimplePropertiesViewExtension;
+
+/**
+ *
+ * @author Rob Stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public class FilesetViewProvider extends SimplePropertiesViewExtension {
+
+ private static final String FILESET_KEY = "org.jboss.ide.eclipse.as.ui.views.server.providers.FilesetViewProvider.PropertyKey";
+
+ private Action createFilter, deleteFilter, editFilter, deleteFileAction, editFileAction;
+
+ private FilesetContentProvider contentProvider;
+ private LabelProvider labelProvider;
+ private Fileset[] filesets;
+ private Object[] selection;
+
+ public FilesetViewProvider() {
+ contentProvider = new FilesetContentProvider();
+ labelProvider = new FilesetLabelProvider();
+ createActions();
+ }
+
+ protected boolean supports(IServer server) {
+ return server != null && (isJBossDeployable(server) || server.getRuntime() != null);
+ }
+
+ protected void createActions() {
+ createFilter = new Action() {
+ public void run() {
+ IDeployableServer server = (IDeployableServer)contentProvider.server.loadAdapter(IDeployableServer.class, new NullProgressMonitor());
+ String location = null;
+ if( server != null )
+ location = server.getConfigDirectory();
+ else
+ location = contentProvider.server.getRuntime().getLocation().toOSString();
+
+ if( location != null ) {
+ FilesetDialog d = new FilesetDialog(new Shell(), location);
+ if( d.open() == Window.OK ) {
+ Fileset fs = d.getFileset();
+ Fileset[] filesetsNew = new Fileset[filesets.length + 1];
+ System.arraycopy(filesets, 0, filesetsNew, 0, filesets.length);
+ filesetsNew[filesetsNew.length-1] = fs;
+ filesets = filesetsNew;
+ saveFilesets();
+ }
+ }
+ }
+ };
+ createFilter.setText(Messages.FilesetsCreateFilter);
+ deleteFilter = new Action() {
+ public void run() {
+ if( selection.length == 1 && selection[0] instanceof Fileset ) {
+ try {
+ ArrayList<Fileset> asList = new ArrayList<Fileset>(Arrays.asList(filesets));
+ asList.remove(selection[0]);
+ filesets = asList.toArray(new Fileset[asList.size()]);
+ saveFilesets();
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+ deleteFilter.setText(Messages.FilesetsDeleteFilter);
+ editFilter = new Action() {
+ public void run() {
+ Fileset sel = selection.length == 1 && selection[0] instanceof Fileset ? (Fileset)selection[0] : null;
+ if( sel == null ) return;
+ FilesetDialog d = new FilesetDialog(new Shell(), sel);
+ if( d.open() == Window.OK ) {
+ Fileset ret = d.getFileset();
+ sel.setName(ret.getName());
+ sel.setFolder(ret.getFolder());
+ sel.setIncludesPattern(ret.getIncludesPattern());
+ sel.setExcludesPattern(ret.getExcludesPattern());
+ saveFilesets();
+ }
+ }
+ };
+ editFilter.setText(Messages.FilesetsEditFilter);
+ deleteFileAction = new Action() {
+ public void run() {
+ try {
+ Shell shell = Workbench.getInstance().getActiveWorkbenchWindow().getShell();
+ File[] files = getSelectedFiles();
+ MessageBox mb = new MessageBox(shell,SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
+ mb.setText("Delete Files?");
+ mb.setMessage("Are you sure you want to delete the selected files?");
+ if( mb.open() == SWT.OK) {
+ for( int i = 0; i < files.length; i++ )
+ FileUtil.safeDelete(files[i]);
+ refreshViewer();
+ }
+ } catch( Exception e ) {
+ }
+ }
+ };
+ deleteFileAction.setText(Messages.FilesetsDeleteFile);
+ editFileAction = new Action() {
+ public void run() {
+ File[] files = getSelectedFiles();
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ for( int i = 0; i < files.length; i++ ) {
+ try {
+ IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(files[i].getAbsolutePath()));
+ IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(files[i]);
+ if( eclipseFile != null ) {
+ IEditorInput input = new FileEditorInput(eclipseFile);
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(files[i].getName());
+ if( desc != null )
+ page.openEditor(input, desc.getId());
+ } else if( fileStore != null ){
+ IEditorInput input = new FileStoreEditorInput(fileStore);
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(files[i].getName());
+ if( desc != null )
+ page.openEditor(input, desc.getId());
+ }
+ } catch( Exception e ) {
+ IStatus status = new Status(IStatus.ERROR, JBossServerUIPlugin.PLUGIN_ID, "Cannot open file", e);
+ JBossServerUIPlugin.getDefault().getLog().log(status);
+ }
+ }
+ }
+ };
+ editFileAction.setText(Messages.FilesetsEditFile);
+ }
+
+ protected File[] getSelectedFiles() {
+ ArrayList<File> tmp = new ArrayList<File>();
+ for( int i = 0; i < selection.length; i++ ) {
+ tmp.add(((PathWrapper)selection[i]).getPath().toFile());
+ }
+ return (File[]) tmp.toArray(new File[tmp.size()]);
+ }
+
+ public static class PathWrapper {
+ private IPath path;
+ private IPath folder;
+ public PathWrapper(IPath path, IPath folder) {
+ this.path = path;
+ this.folder = folder;
+ }
+ /**
+ * @return the folder
+ */
+ public IPath getFolder() {
+ return folder;
+ }
+ /**
+ * @return the path
+ */
+ public IPath getPath() {
+ return folder.append(path);
+ }
+
+ public String getLocalizedResourceName() {
+ return path.toOSString();
+ }
+ }
+
+ public static class FolderWrapper extends PathWrapper {
+ private HashMap<String, FolderWrapper> childrenFolders;
+ private ArrayList<PathWrapper> children;
+ public FolderWrapper(IPath path, IPath folder) {
+ super(path, folder);
+ children = new ArrayList<PathWrapper>();
+ childrenFolders = new HashMap<String, FolderWrapper>();
+ }
+ public void addChild(IPath path) {
+ if( path.segmentCount() == 1 ) {
+ children.add(new PathWrapper(path, getFolder().append(getLocalizedResourceName())));
+ } else {
+ addPath(children, childrenFolders, path, getFolder().append(getLocalizedResourceName()));
+ }
+ }
+ public Object[] getChildren() {
+ return children.toArray(new Object[children.size()]);
+ }
+ }
+
+ private static void addPath(ArrayList<PathWrapper> children, HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
+ try {
+ FolderWrapper fw = null;
+ if( !folders.containsKey(path.segment(0))) {
+ fw = new FolderWrapper(path.removeLastSegments(path.segmentCount()-1), folder);
+ folders.put(path.segment(0), fw);
+ children.add(fw);
+ } else {
+ fw = folders.get( path.segment(0));
+ }
+ fw.addChild(path.removeFirstSegments(1));
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ public class FilesetContentProvider implements ITreeContentProvider {
+ public IServer server;
+ public Object[] getChildren(Object parentElement) {
+ if( parentElement instanceof ServerViewProvider ) {
+ return filesets == null ? new Object[]{} : filesets;
+ } else if( parentElement instanceof Fileset ) {
+ Fileset fs = (Fileset)parentElement;
+ IPath[] paths = null;
+ try {
+ paths = findPaths(fs.getFolder(),
+ fs.getIncludesPattern(),
+ fs.getExcludesPattern());
+ } catch( BuildException be ) {
+ return new Object[]{};
+ }
+
+ HashMap<String, FolderWrapper> folders = new HashMap<String, FolderWrapper>();
+ ArrayList<PathWrapper> wrappers = new ArrayList<PathWrapper>();
+ for( int i = 0; i < paths.length; i++ ) {
+ if( paths[i].segmentCount() == 1 ) {
+ wrappers.add(new PathWrapper(paths[i], new Path(fs.getFolder())));
+ } else {
+ addPath(wrappers, folders, paths[i], new Path(fs.getFolder()));
+ }
+ }
+ return wrappers.toArray(new Object[wrappers.size()]);
+ } else if( parentElement instanceof FolderWrapper ) {
+ return ((FolderWrapper)parentElement).getChildren();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0 ? true : false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return null;
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if( newInput instanceof IServer ) {
+ server = (IServer)newInput;
+ loadFilesets();
+ }
+ }
+ }
+
+ public void loadFilesets() {
+ IServer server = contentProvider.server;
+ if( server != null ) {
+ ServerAttributeHelper helper = ServerAttributeHelper.createHelper(server);
+ List tmp = helper.getAttribute(FILESET_KEY, new ArrayList());
+ String[] asStrings = (String[]) tmp.toArray(new String[tmp.size()]);
+ filesets = new Fileset[asStrings.length];
+ for( int i = 0; i < asStrings.length; i++ ) {
+ filesets[i] = new Fileset(asStrings[i]);
+ }
+ }
+ }
+
+ public void saveFilesets() {
+ IServer server = contentProvider.server;
+ if( server != null ) {
+ ArrayList<String> list = new ArrayList<String>();
+ for( int i = 0; i < filesets.length; i++ ) {
+ list.add(filesets[i].toString());
+ }
+ ServerAttributeHelper helper = ServerAttributeHelper.createHelper(server);
+ helper.setAttribute(FILESET_KEY, list);
+ helper.save();
+ }
+ }
+
+ public class Fileset implements Cloneable {
+ private String name, folder, includesPattern, excludesPattern;
+ public Fileset() {
+ }
+ public Fileset(String string) {
+ try {
+ name = folder = includesPattern =excludesPattern = "";
+ String[] parts = string.split("\n");
+ name = parts[0];
+ folder = parts[1];
+ includesPattern = parts[2];
+ excludesPattern = parts[3];
+ } catch( ArrayIndexOutOfBoundsException aioobe) {}
+ }
+
+ public Fileset(String name, String folder, String inc, String exc) {
+ this.name = name;
+ this.folder = folder;
+ includesPattern = inc;
+ excludesPattern = exc;
+ }
+ public String toString() {
+ return name + "\n" + folder + "\n" + includesPattern + "\n" + excludesPattern;
+ }
+ /**
+ * @return the folder
+ */
+ public String getFolder() {
+ return folder == null ? "" : folder;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name == null ? "" : name;
+ }
+ /**
+ * @return the excludesPattern
+ */
+ public String getExcludesPattern() {
+ return excludesPattern == null ? "" : excludesPattern;
+ }
+ /**
+ * @return the includesPattern
+ */
+ public String getIncludesPattern() {
+ return includesPattern == null ? "" : includesPattern;
+ }
+
+ /**
+ * @param excludesPattern the excludesPattern to set
+ */
+ public void setExcludesPattern(String excludesPattern) {
+ this.excludesPattern = excludesPattern;
+ }
+
+ /**
+ * @param folder the folder to set
+ */
+ public void setFolder(String folder) {
+ this.folder = folder;
+ }
+
+ /**
+ * @param includesPattern the includesPattern to set
+ */
+ public void setIncludesPattern(String includesPattern) {
+ this.includesPattern = includesPattern;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch( Exception e ) {}
+ return null;
+ }
+
+ public boolean equals(Object other) {
+ if( !(other instanceof Fileset)) return false;
+ if( other == this ) return true;
+ Fileset o = (Fileset)other;
+ return o.getName().equals(getName()) && o.getFolder().equals(getFolder())
+ && o.getIncludesPattern().equals(getIncludesPattern()) && o.getExcludesPattern().equals(getExcludesPattern());
+ }
+ public int hashCode() {
+ return (name + "::_::" + folder + "::_::" + includesPattern + "::_::" + excludesPattern + "::_::").hashCode();
+ }
+ }
+
+ public class FilesetLabelProvider extends LabelProvider {
+
+ private LocalResourceManager resourceManager;
+
+ public FilesetLabelProvider() {
+ super();
+ this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
+ }
+
+ public Image getImage(Object element) {
+ if( element instanceof Fileset ) {
+ return PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJ_FOLDER);
+ } else if( element instanceof FolderWrapper ) {
+ return PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJ_FOLDER);
+ } else if( element instanceof PathWrapper ) {
+ String fileName = ((PathWrapper)element).getPath().toOSString();
+ IContentTypeManager manager = Platform.getContentTypeManager();
+ IContentTypeMatcher matcher = manager.getMatcher(null, null);
+ IContentType contentType = matcher.findContentTypeFor(fileName);
+ ImageDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry()
+ .getImageDescriptor(fileName, contentType);
+ if (descriptor == null) {
+ descriptor = PlatformUI.getWorkbench().getSharedImages()
+ .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
+ }
+ return resourceManager.createImage(descriptor);
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ if( element instanceof PathWrapper ) return ((PathWrapper)element).getLocalizedResourceName();
+ if( element instanceof Fileset ) return ((Fileset)element).getName() + " " + ((Fileset)element).getFolder();
+ return element == null ? "" : element.toString();//$NON-NLS-1$
+ }
+
+
+ public void dispose() {
+ resourceManager.dispose();
+ resourceManager = null;
+ super.dispose();
+ }
+
+ }
+
+ public void fillContextMenu(Shell shell, IMenuManager menu, Object[] selection) {
+ this.selection = selection;
+ if( selection.length == 1 && selection[0] instanceof ServerViewProvider ) {
+ menu.add(createFilter);
+ } else if( selection.length == 1 && selection[0] instanceof Fileset ) {
+ menu.add(editFilter);
+ menu.add(deleteFilter);
+ } else if( allPathWrappers(selection) ) {
+ editFileAction.setEnabled(canEdit(selection));
+ deleteFileAction.setEnabled(canDelete(selection));
+ menu.add(editFileAction);
+ menu.add(deleteFileAction);
+ }
+ }
+
+ protected boolean allPathWrappers(Object[] list) {
+ boolean result = true;
+ for( int i = 0; i < list.length; i++ )
+ result &= list[i] instanceof PathWrapper;
+ return result;
+ }
+
+ protected boolean canDelete(Object[] list ) {
+ boolean result = true;
+ for( int i = 0; i < list.length; i++ )
+ result &= ((PathWrapper)selection[i]).getPath().toFile().exists();
+ return result;
+ }
+
+ protected boolean canEdit(Object[] list) {
+ for( int i = 0; i < list.length; i++ )
+ if( canEdit(((PathWrapper)selection[i]).getPath().toFile()))
+ return true;
+ return false;
+ }
+
+ protected boolean canEdit(File file) {
+ IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath()));
+ IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(file);
+ boolean editable = false;
+ if( eclipseFile != null ) {
+ IEditorInput input = new FileEditorInput(eclipseFile);
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(file.getName());
+ if( input != null && desc != null )
+ editable = true;
+ } else if( fileStore != null ){
+ IEditorInput input = new FileStoreEditorInput(fileStore);
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(file.getName());
+ if( input != null && desc != null )
+ editable = true;
+ }
+ return editable;
+ }
+
+ public ITreeContentProvider getContentProvider() {
+ return contentProvider;
+ }
+
+ public LabelProvider getLabelProvider() {
+ return labelProvider;
+ }
+
+ public Properties getProperties(Object selected) {
+ return null;
+ }
+
+ public String[] getPropertyKeys(Object selected) {
+ return null;
+ }
+
+ private IPath[] findPaths(String dir, String includes, String excludes) {
+ IPath[] paths = new IPath[0];
+ try {
+ if( dir != null ) {
+ DirectoryScanner scanner =
+ DirectoryScannerFactory.createDirectoryScanner(dir, null, includes, excludes, null, false, 1, true);
+ if( scanner != null ) {
+ String[] files = scanner.getIncludedFiles();
+ paths = new IPath[files.length];
+ for( int i = 0; i < files.length; i++ ) {
+ paths[i] = new Path(files[i]);
+ }
+ }
+ }
+ } catch( IllegalStateException ise ) {}
+ return paths;
+ }
+
+ protected class FilesetDialog extends TitleAreaDialog {
+ protected Fileset fileset;
+ private String name, dir, includes, excludes;
+ private Button browse;
+ private Text includesText, excludesText, folderText, nameText;
+ private Composite main;
+ private FilesetPreviewComposite preview;
+ protected FilesetDialog(Shell parentShell, String defaultLocation) {
+ super(parentShell);
+ this.fileset = new Fileset();
+ this.fileset.setFolder(defaultLocation);
+
+ }
+ protected FilesetDialog(Shell parentShell, Fileset fileset) {
+ super(parentShell);
+ this.fileset = (Fileset)fileset.clone();
+ }
+ protected Point getInitialSize() {
+ //return new Point(400, 150);
+ Point p = super.getInitialSize();
+ return new Point(500, p.y);
+ }
+ protected int getShellStyle() {
+ return super.getShellStyle() | SWT.RESIZE;
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.FilesetsNewFileset);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ setTitle("File filter");
+ setMessage("Creates a new file filter");
+
+ Composite sup = (Composite) super.createDialogArea(parent);
+ main = new Composite(sup, SWT.NONE);
+ main.setLayout(new GridLayout(3, false));
+ main.setLayoutData(new GridData(GridData.FILL_BOTH));
+ fillArea(main);
+
+ nameText.setText(fileset.getName());
+ folderText.setText(fileset.getFolder());
+ includesText.setText(fileset.getIncludesPattern());
+ excludesText.setText(fileset.getExcludesPattern());
+
+ addListeners();
+ return sup;
+ }
+
+ protected void addListeners() {
+ ModifyListener mListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ textModified();
+ }
+ };
+ nameText.addModifyListener(mListener);
+ folderText.addModifyListener(mListener);
+ includesText.addModifyListener(mListener);
+ excludesText.addModifyListener(mListener);
+
+ browse.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog d = new DirectoryDialog(new Shell());
+ d.setFilterPath(folderText.getText());
+ String x = d.open();
+ if( x != null )
+ folderText.setText(x);
+ }
+ });
+ }
+
+ protected void textModified() {
+ name = nameText.getText();
+ dir = folderText.getText();
+ includes = includesText.getText();
+ excludes = excludesText.getText();
+ fileset.setName(name);
+ fileset.setFolder(dir);
+ fileset.setIncludesPattern(includes);
+ fileset.setExcludesPattern(excludes);
+ updatePreview();
+ }
+ protected void fillArea(Composite main) {
+ Label nameLabel = new Label(main, SWT.NONE);
+ nameLabel.setText(Messages.FilesetsNewName);
+
+ nameText = new Text(main, SWT.BORDER);
+ nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ Label folderLabel = new Label(main, SWT.NONE);
+ folderLabel.setText(Messages.FilesetsNewRootDir);
+
+ folderText = new Text(main, SWT.BORDER);
+ folderText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ browse = new Button(main, SWT.PUSH);
+ browse.setText(Messages.FilesetsNewBrowse);
+
+ Label includesLabel = new Label(main, SWT.NONE);
+ includesLabel.setText(Messages.FilesetsNewIncludes);
+
+ includesText = new Text(main, SWT.BORDER);
+ includesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ Label excludeLabel= new Label(main, SWT.NONE);
+ excludeLabel.setText(Messages.FilesetsNewExcludes);
+
+ excludesText = new Text(main, SWT.BORDER);
+ excludesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ Group previewWrapper = new Group(main, SWT.NONE);
+
+ previewWrapper.setLayout(new GridLayout());
+ GridLayout gridLayout = new GridLayout();
+ //gridLayout.numColumns = 3;
+ //gridLayout.verticalSpacing = 9;
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ data.horizontalSpan = 3;
+ data.minimumHeight = 200;
+
+ previewWrapper.setLayoutData(data);
+ previewWrapper.setText(Messages.FilesetsNewPreview);
+
+ previewWrapper.setLayout(new FillLayout());
+ preview = new FilesetPreviewComposite(previewWrapper, SWT.NONE);
+ }
+
+ private void updatePreview() {
+ preview.setInput(findPaths(dir, includes, excludes));
+ }
+
+ public String getDir() {
+ return dir;
+ }
+ public String getExcludes() {
+ return excludes;
+ }
+ public String getIncludes() {
+ return includes;
+ }
+ public String getName() {
+ return name;
+ }
+ public Fileset getFileset() {
+ return fileset;
+ }
+
+ }
+
+}
Property changes on: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetViewProvider.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/META-INF/MANIFEST.MF 2008-09-29 17:50:09 UTC (rev 10545)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/META-INF/MANIFEST.MF 2008-09-29 18:32:42 UTC (rev 10546)
@@ -41,12 +41,11 @@
org.eclipse.core.variables,
org.eclipse.search,
org.apache.ant,
- org.jboss.ide.eclipse.as.core,
- org.jboss.ide.eclipse.archives.core,
- org.jboss.ide.eclipse.archives.ui
+ org.jboss.ide.eclipse.as.core
Eclipse-LazyStart: true
Export-Package: org.jboss.ide.eclipse.as.ui,
org.jboss.ide.eclipse.as.ui.dialogs,
+ org.jboss.ide.eclipse.as.ui.views.server.extensions,
org.jboss.ide.eclipse.as.ui.wizards
Bundle-ClassPath: jbossui.jar
Bundle-Activator: org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/FilesetViewProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/FilesetViewProvider.java 2008-09-29 17:50:09 UTC (rev 10545)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/FilesetViewProvider.java 2008-09-29 18:32:42 UTC (rev 10546)
@@ -1,765 +0,0 @@
-/**
- * JBoss, a Division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
-* This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as.ui.views.server.providers;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.tools.ant.BuildException;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.content.IContentTypeManager;
-import org.eclipse.core.runtime.content.IContentTypeMatcher;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FillLayout;
-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.Control;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.MessageBox;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.FileStoreEditorInput;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
-import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
-import org.jboss.ide.eclipse.archives.ui.util.composites.FilesetPreviewComposite;
-import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
-import org.jboss.ide.eclipse.as.core.util.FileUtil;
-import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
-import org.jboss.ide.eclipse.as.ui.Messages;
-import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
-import org.jboss.ide.eclipse.as.ui.views.server.extensions.SimplePropertiesViewExtension;
-import org.jboss.tools.as.wst.server.ui.views.server.JBossServerView;
-
-/**
- *
- * @author Rob Stryker <rob.stryker(a)redhat.com>
- *
- */
-public class FilesetViewProvider extends SimplePropertiesViewExtension {
-
- private static final String FILESET_KEY = "org.jboss.ide.eclipse.as.ui.views.server.providers.FilesetViewProvider.PropertyKey";
-
- private Action createFilter, deleteFilter, editFilter, deleteFileAction, editFileAction;
-
- private FilesetContentProvider contentProvider;
- private LabelProvider labelProvider;
- private Fileset[] filesets;
- private Object[] selection;
-
- public FilesetViewProvider() {
- contentProvider = new FilesetContentProvider();
- labelProvider = new FilesetLabelProvider();
- createActions();
- }
-
- protected boolean supports(IServer server) {
- return server != null && (isJBossDeployable(server) || server.getRuntime() != null);
- }
-
- protected void createActions() {
- createFilter = new Action() {
- public void run() {
- IDeployableServer server = (IDeployableServer)contentProvider.server.loadAdapter(IDeployableServer.class, new NullProgressMonitor());
- String location = null;
- if( server != null )
- location = server.getConfigDirectory();
- else
- location = contentProvider.server.getRuntime().getLocation().toOSString();
-
- if( location != null ) {
- FilesetDialog d = new FilesetDialog(new Shell(), location);
- if( d.open() == Window.OK ) {
- Fileset fs = d.getFileset();
- Fileset[] filesetsNew = new Fileset[filesets.length + 1];
- System.arraycopy(filesets, 0, filesetsNew, 0, filesets.length);
- filesetsNew[filesetsNew.length-1] = fs;
- filesets = filesetsNew;
- saveFilesets();
- }
- }
- }
- };
- createFilter.setText(Messages.FilesetsCreateFilter);
- deleteFilter = new Action() {
- public void run() {
- if( selection.length == 1 && selection[0] instanceof Fileset ) {
- try {
- ArrayList<Fileset> asList = new ArrayList<Fileset>(Arrays.asList(filesets));
- asList.remove(selection[0]);
- filesets = asList.toArray(new Fileset[asList.size()]);
- saveFilesets();
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
- }
- };
- deleteFilter.setText(Messages.FilesetsDeleteFilter);
- editFilter = new Action() {
- public void run() {
- Fileset sel = selection.length == 1 && selection[0] instanceof Fileset ? (Fileset)selection[0] : null;
- if( sel == null ) return;
- FilesetDialog d = new FilesetDialog(new Shell(), sel);
- if( d.open() == Window.OK ) {
- Fileset ret = d.getFileset();
- sel.setName(ret.getName());
- sel.setFolder(ret.getFolder());
- sel.setIncludesPattern(ret.getIncludesPattern());
- sel.setExcludesPattern(ret.getExcludesPattern());
- saveFilesets();
- }
- }
- };
- editFilter.setText(Messages.FilesetsEditFilter);
- deleteFileAction = new Action() {
- public void run() {
- try {
- Shell shell = JBossServerView.getDefault().getSite().getShell();
- File[] files = getSelectedFiles();
- MessageBox mb = new MessageBox(shell,SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
- mb.setText("Delete Files?");
- mb.setMessage("Are you sure you want to delete the selected files?");
- if( mb.open() == SWT.OK) {
- for( int i = 0; i < files.length; i++ )
- FileUtil.safeDelete(files[i]);
- refreshViewer();
- }
- } catch( Exception e ) {
- }
- }
- };
- deleteFileAction.setText(Messages.FilesetsDeleteFile);
- editFileAction = new Action() {
- public void run() {
- File[] files = getSelectedFiles();
- IWorkbench wb = PlatformUI.getWorkbench();
- IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
- IWorkbenchPage page = win.getActivePage();
- for( int i = 0; i < files.length; i++ ) {
- try {
- IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(files[i].getAbsolutePath()));
- IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(files[i]);
- if( eclipseFile != null ) {
- IEditorInput input = new FileEditorInput(eclipseFile);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(files[i].getName());
- if( desc != null )
- page.openEditor(input, desc.getId());
- } else if( fileStore != null ){
- IEditorInput input = new FileStoreEditorInput(fileStore);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(files[i].getName());
- if( desc != null )
- page.openEditor(input, desc.getId());
- }
- } catch( Exception e ) {
- IStatus status = new Status(IStatus.ERROR, JBossServerUIPlugin.PLUGIN_ID, "Cannot open file", e);
- JBossServerUIPlugin.getDefault().getLog().log(status);
- }
- }
- }
- };
- editFileAction.setText(Messages.FilesetsEditFile);
- }
-
- protected File[] getSelectedFiles() {
- ArrayList<File> tmp = new ArrayList<File>();
- for( int i = 0; i < selection.length; i++ ) {
- tmp.add(((PathWrapper)selection[i]).getPath().toFile());
- }
- return (File[]) tmp.toArray(new File[tmp.size()]);
- }
-
- public static class PathWrapper {
- private IPath path;
- private IPath folder;
- public PathWrapper(IPath path, IPath folder) {
- this.path = path;
- this.folder = folder;
- }
- /**
- * @return the folder
- */
- public IPath getFolder() {
- return folder;
- }
- /**
- * @return the path
- */
- public IPath getPath() {
- return folder.append(path);
- }
-
- public String getLocalizedResourceName() {
- return path.toOSString();
- }
- }
-
- public static class FolderWrapper extends PathWrapper {
- private HashMap<String, FolderWrapper> childrenFolders;
- private ArrayList<PathWrapper> children;
- public FolderWrapper(IPath path, IPath folder) {
- super(path, folder);
- children = new ArrayList<PathWrapper>();
- childrenFolders = new HashMap<String, FolderWrapper>();
- }
- public void addChild(IPath path) {
- if( path.segmentCount() == 1 ) {
- children.add(new PathWrapper(path, getFolder().append(getLocalizedResourceName())));
- } else {
- addPath(children, childrenFolders, path, getFolder().append(getLocalizedResourceName()));
- }
- }
- public Object[] getChildren() {
- return children.toArray(new Object[children.size()]);
- }
- }
-
- private static void addPath(ArrayList<PathWrapper> children, HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
- try {
- FolderWrapper fw = null;
- if( !folders.containsKey(path.segment(0))) {
- fw = new FolderWrapper(path.removeLastSegments(path.segmentCount()-1), folder);
- folders.put(path.segment(0), fw);
- children.add(fw);
- } else {
- fw = folders.get( path.segment(0));
- }
- fw.addChild(path.removeFirstSegments(1));
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
-
- public class FilesetContentProvider implements ITreeContentProvider {
- public IServer server;
- public Object[] getChildren(Object parentElement) {
- if( parentElement instanceof ServerViewProvider ) {
- return filesets == null ? new Object[]{} : filesets;
- } else if( parentElement instanceof Fileset ) {
- Fileset fs = (Fileset)parentElement;
- IPath[] paths = null;
- try {
- paths = findPaths(fs.getFolder(),
- fs.getIncludesPattern(),
- fs.getExcludesPattern());
- } catch( BuildException be ) {
- return new Object[]{};
- }
-
- HashMap<String, FolderWrapper> folders = new HashMap<String, FolderWrapper>();
- ArrayList<PathWrapper> wrappers = new ArrayList<PathWrapper>();
- for( int i = 0; i < paths.length; i++ ) {
- if( paths[i].segmentCount() == 1 ) {
- wrappers.add(new PathWrapper(paths[i], new Path(fs.getFolder())));
- } else {
- addPath(wrappers, folders, paths[i], new Path(fs.getFolder()));
- }
- }
- return wrappers.toArray(new Object[wrappers.size()]);
- } else if( parentElement instanceof FolderWrapper ) {
- return ((FolderWrapper)parentElement).getChildren();
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- return null;
- }
-
- public boolean hasChildren(Object element) {
- return getChildren(element).length > 0 ? true : false;
- }
-
- public Object[] getElements(Object inputElement) {
- return null;
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if( newInput instanceof IServer ) {
- server = (IServer)newInput;
- loadFilesets();
- }
- }
- }
-
- public void loadFilesets() {
- IServer server = contentProvider.server;
- if( server != null ) {
- ServerAttributeHelper helper = ServerAttributeHelper.createHelper(server);
- List tmp = helper.getAttribute(FILESET_KEY, new ArrayList());
- String[] asStrings = (String[]) tmp.toArray(new String[tmp.size()]);
- filesets = new Fileset[asStrings.length];
- for( int i = 0; i < asStrings.length; i++ ) {
- filesets[i] = new Fileset(asStrings[i]);
- }
- }
- }
-
- public void saveFilesets() {
- IServer server = contentProvider.server;
- if( server != null ) {
- ArrayList<String> list = new ArrayList<String>();
- for( int i = 0; i < filesets.length; i++ ) {
- list.add(filesets[i].toString());
- }
- ServerAttributeHelper helper = ServerAttributeHelper.createHelper(server);
- helper.setAttribute(FILESET_KEY, list);
- helper.save();
- }
- }
-
- public class Fileset implements Cloneable {
- private String name, folder, includesPattern, excludesPattern;
- public Fileset() {
- }
- public Fileset(String string) {
- try {
- name = folder = includesPattern =excludesPattern = "";
- String[] parts = string.split("\n");
- name = parts[0];
- folder = parts[1];
- includesPattern = parts[2];
- excludesPattern = parts[3];
- } catch( ArrayIndexOutOfBoundsException aioobe) {}
- }
-
- public Fileset(String name, String folder, String inc, String exc) {
- this.name = name;
- this.folder = folder;
- includesPattern = inc;
- excludesPattern = exc;
- }
- public String toString() {
- return name + "\n" + folder + "\n" + includesPattern + "\n" + excludesPattern;
- }
- /**
- * @return the folder
- */
- public String getFolder() {
- return folder == null ? "" : folder;
- }
- /**
- * @return the name
- */
- public String getName() {
- return name == null ? "" : name;
- }
- /**
- * @return the excludesPattern
- */
- public String getExcludesPattern() {
- return excludesPattern == null ? "" : excludesPattern;
- }
- /**
- * @return the includesPattern
- */
- public String getIncludesPattern() {
- return includesPattern == null ? "" : includesPattern;
- }
-
- /**
- * @param excludesPattern the excludesPattern to set
- */
- public void setExcludesPattern(String excludesPattern) {
- this.excludesPattern = excludesPattern;
- }
-
- /**
- * @param folder the folder to set
- */
- public void setFolder(String folder) {
- this.folder = folder;
- }
-
- /**
- * @param includesPattern the includesPattern to set
- */
- public void setIncludesPattern(String includesPattern) {
- this.includesPattern = includesPattern;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- public Object clone() {
- try {
- return super.clone();
- } catch( Exception e ) {}
- return null;
- }
-
- public boolean equals(Object other) {
- if( !(other instanceof Fileset)) return false;
- if( other == this ) return true;
- Fileset o = (Fileset)other;
- return o.getName().equals(getName()) && o.getFolder().equals(getFolder())
- && o.getIncludesPattern().equals(getIncludesPattern()) && o.getExcludesPattern().equals(getExcludesPattern());
- }
- public int hashCode() {
- return (name + "::_::" + folder + "::_::" + includesPattern + "::_::" + excludesPattern + "::_::").hashCode();
- }
- }
-
- public class FilesetLabelProvider extends LabelProvider {
-
- private LocalResourceManager resourceManager;
-
- public FilesetLabelProvider() {
- super();
- this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
- }
-
- public Image getImage(Object element) {
- if( element instanceof Fileset ) {
- return PlatformUI.getWorkbench().getSharedImages()
- .getImage(ISharedImages.IMG_OBJ_FOLDER);
- } else if( element instanceof FolderWrapper ) {
- return PlatformUI.getWorkbench().getSharedImages()
- .getImage(ISharedImages.IMG_OBJ_FOLDER);
- } else if( element instanceof PathWrapper ) {
- String fileName = ((PathWrapper)element).getPath().toOSString();
- IContentTypeManager manager = Platform.getContentTypeManager();
- IContentTypeMatcher matcher = manager.getMatcher(null, null);
- IContentType contentType = matcher.findContentTypeFor(fileName);
- ImageDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry()
- .getImageDescriptor(fileName, contentType);
- if (descriptor == null) {
- descriptor = PlatformUI.getWorkbench().getSharedImages()
- .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
- }
- return resourceManager.createImage(descriptor);
- }
- return null;
- }
-
- public String getText(Object element) {
- if( element instanceof PathWrapper ) return ((PathWrapper)element).getLocalizedResourceName();
- if( element instanceof Fileset ) return ((Fileset)element).getName() + " " + ((Fileset)element).getFolder();
- return element == null ? "" : element.toString();//$NON-NLS-1$
- }
-
-
- public void dispose() {
- resourceManager.dispose();
- resourceManager = null;
- super.dispose();
- }
-
- }
-
- public void fillContextMenu(Shell shell, IMenuManager menu, Object[] selection) {
- this.selection = selection;
- if( selection.length == 1 && selection[0] instanceof ServerViewProvider ) {
- menu.add(createFilter);
- } else if( selection.length == 1 && selection[0] instanceof Fileset ) {
- menu.add(editFilter);
- menu.add(deleteFilter);
- } else if( allPathWrappers(selection) ) {
- editFileAction.setEnabled(canEdit(selection));
- deleteFileAction.setEnabled(canDelete(selection));
- menu.add(editFileAction);
- menu.add(deleteFileAction);
- }
- }
-
- protected boolean allPathWrappers(Object[] list) {
- boolean result = true;
- for( int i = 0; i < list.length; i++ )
- result &= list[i] instanceof PathWrapper;
- return result;
- }
-
- protected boolean canDelete(Object[] list ) {
- boolean result = true;
- for( int i = 0; i < list.length; i++ )
- result &= ((PathWrapper)selection[i]).getPath().toFile().exists();
- return result;
- }
-
- protected boolean canEdit(Object[] list) {
- for( int i = 0; i < list.length; i++ )
- if( canEdit(((PathWrapper)selection[i]).getPath().toFile()))
- return true;
- return false;
- }
-
- protected boolean canEdit(File file) {
- IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath()));
- IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(file);
- boolean editable = false;
- if( eclipseFile != null ) {
- IEditorInput input = new FileEditorInput(eclipseFile);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(file.getName());
- if( input != null && desc != null )
- editable = true;
- } else if( fileStore != null ){
- IEditorInput input = new FileStoreEditorInput(fileStore);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(file.getName());
- if( input != null && desc != null )
- editable = true;
- }
- return editable;
- }
-
- public ITreeContentProvider getContentProvider() {
- return contentProvider;
- }
-
- public LabelProvider getLabelProvider() {
- return labelProvider;
- }
-
- public Properties getProperties(Object selected) {
- return null;
- }
-
- public String[] getPropertyKeys(Object selected) {
- return null;
- }
-
- private IPath[] findPaths(String dir, String includes, String excludes) {
- IPath[] paths = new IPath[0];
- try {
- if( dir != null ) {
- DirectoryScanner scanner =
- DirectoryScannerFactory.createDirectoryScanner(dir, null, includes, excludes, null, false, 1, true);
- if( scanner != null ) {
- String[] files = scanner.getIncludedFiles();
- paths = new IPath[files.length];
- for( int i = 0; i < files.length; i++ ) {
- paths[i] = new Path(files[i]);
- }
- }
- }
- } catch( IllegalStateException ise ) {}
- return paths;
- }
-
- protected class FilesetDialog extends TitleAreaDialog {
- protected Fileset fileset;
- private String name, dir, includes, excludes;
- private Button browse;
- private Text includesText, excludesText, folderText, nameText;
- private Composite main;
- private FilesetPreviewComposite preview;
- protected FilesetDialog(Shell parentShell, String defaultLocation) {
- super(parentShell);
- this.fileset = new Fileset();
- this.fileset.setFolder(defaultLocation);
-
- }
- protected FilesetDialog(Shell parentShell, Fileset fileset) {
- super(parentShell);
- this.fileset = (Fileset)fileset.clone();
- }
- protected Point getInitialSize() {
- //return new Point(400, 150);
- Point p = super.getInitialSize();
- return new Point(500, p.y);
- }
- protected int getShellStyle() {
- return super.getShellStyle() | SWT.RESIZE;
- }
-
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setText(Messages.FilesetsNewFileset);
- }
-
- protected Control createDialogArea(Composite parent) {
- setTitle("File filter");
- setMessage("Creates a new file filter");
-
- Composite sup = (Composite) super.createDialogArea(parent);
- main = new Composite(sup, SWT.NONE);
- main.setLayout(new GridLayout(3, false));
- main.setLayoutData(new GridData(GridData.FILL_BOTH));
- fillArea(main);
-
- nameText.setText(fileset.getName());
- folderText.setText(fileset.getFolder());
- includesText.setText(fileset.getIncludesPattern());
- excludesText.setText(fileset.getExcludesPattern());
-
- addListeners();
- return sup;
- }
-
- protected void addListeners() {
- ModifyListener mListener = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- textModified();
- }
- };
- nameText.addModifyListener(mListener);
- folderText.addModifyListener(mListener);
- includesText.addModifyListener(mListener);
- excludesText.addModifyListener(mListener);
-
- browse.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog d = new DirectoryDialog(new Shell());
- d.setFilterPath(folderText.getText());
- String x = d.open();
- if( x != null )
- folderText.setText(x);
- }
- });
- }
-
- protected void textModified() {
- name = nameText.getText();
- dir = folderText.getText();
- includes = includesText.getText();
- excludes = excludesText.getText();
- fileset.setName(name);
- fileset.setFolder(dir);
- fileset.setIncludesPattern(includes);
- fileset.setExcludesPattern(excludes);
- updatePreview();
- }
- protected void fillArea(Composite main) {
- Label nameLabel = new Label(main, SWT.NONE);
- nameLabel.setText(Messages.FilesetsNewName);
-
- nameText = new Text(main, SWT.BORDER);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- Label folderLabel = new Label(main, SWT.NONE);
- folderLabel.setText(Messages.FilesetsNewRootDir);
-
- folderText = new Text(main, SWT.BORDER);
- folderText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- browse = new Button(main, SWT.PUSH);
- browse.setText(Messages.FilesetsNewBrowse);
-
- Label includesLabel = new Label(main, SWT.NONE);
- includesLabel.setText(Messages.FilesetsNewIncludes);
-
- includesText = new Text(main, SWT.BORDER);
- includesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- Label excludeLabel= new Label(main, SWT.NONE);
- excludeLabel.setText(Messages.FilesetsNewExcludes);
-
- excludesText = new Text(main, SWT.BORDER);
- excludesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- Group previewWrapper = new Group(main, SWT.NONE);
-
- previewWrapper.setLayout(new GridLayout());
- GridLayout gridLayout = new GridLayout();
- //gridLayout.numColumns = 3;
- //gridLayout.verticalSpacing = 9;
-
- GridData data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- data.horizontalSpan = 3;
- data.minimumHeight = 200;
-
- previewWrapper.setLayoutData(data);
- previewWrapper.setText(Messages.FilesetsNewPreview);
-
- previewWrapper.setLayout(new FillLayout());
- preview = new FilesetPreviewComposite(previewWrapper, SWT.NONE);
- }
-
- private void updatePreview() {
- preview.setInput(findPaths(dir, includes, excludes));
- }
-
- public String getDir() {
- return dir;
- }
- public String getExcludes() {
- return excludes;
- }
- public String getIncludes() {
- return includes;
- }
- public String getName() {
- return name;
- }
- public Fileset getFileset() {
- return fileset;
- }
-
- }
-
-}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2008-09-29 17:50:09 UTC (rev 10545)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2008-09-29 18:32:42 UTC (rev 10546)
@@ -5,9 +5,9 @@
<extension-point id="EventLogLabelProvider" name="org.jboss.ide.as.ui.eventLogLabelProvider" schema="schema/EventLogLabelProvider.exsd"/>
<extension-point id="EventLogMajorType" name="org.jboss.ide.eclipse.as.ui.eventLogMajorType" schema="schema/EventLogMajorType.exsd"/>
<extension-point id="ServerEditorPortSection" name="org.jboss.ide.as.ui.editor.portSection" schema="schema/ServerEditorPortSection.exsd"/>
-
+
<extension
- point="org.eclipse.wst.server.ui.serverImages">
+ point="org.eclipse.wst.server.ui.serverImages">
<image
icon="icons/jboss.gif"
typeIds="org.jboss.ide.eclipse.as.32"
@@ -68,9 +68,9 @@
<extension point="org.eclipse.ui.startup">
<startup />
- </extension>
-
-
+ </extension>
+
+
<extension
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
@@ -79,9 +79,9 @@
id="org.jboss.ide.eclipse.as.core.jbossLaunchTabGroup"
type="org.jboss.ide.eclipse.as.core.server.startupConfiguration"/>
</extension>
-
+
<extension
point="org.eclipse.wst.server.ui.serverImages">
<image
@@ -102,24 +102,16 @@
class="org.jboss.tools.as.wst.server.ui.views.server.preferencepages.ViewPreferencePage"
id="org.jboss.ide.eclipse.as.ui.jbossServerViewPrefPage"
name="JBoss Server View"/>
- </extension>
+ </extension>
- <extension point="org.eclipse.wst.common.project.facet.core.runtimes">
+ <extension point="org.eclipse.wst.common.project.facet.core.runtimes">
<adapter>
- <runtime-component id="org.jboss.ide.eclipse.as.runtime.component"/>
<factory class="org.eclipse.jst.server.ui.internal.RuntimeLabelProvider$Factory"/>
<type class="org.eclipse.wst.common.project.facet.ui.IRuntimeComponentLabelProvider"/>
</adapter>
</extension>
-
-
-
-
-
-
-
<extension
point="org.eclipse.ui.views">
<view
@@ -130,10 +122,10 @@
id="org.jboss.ide.eclipse.as.ui.views.JBossServerView"
name="JBoss Server View"/>
</extension>
-
-
-
-
+
+
+
+
<extension
point="org.jboss.ide.eclipse.as.ui.ServerViewExtension">
<ViewProvider
@@ -155,12 +147,6 @@
name="XML Configuration"
providerClass="org.jboss.ide.eclipse.as.ui.views.server.providers.DescriptorXPathViewProvider"/>
<ViewProvider
- description="A front end to open, edit, or view files in your server's directories."
- icon="icons/multiple_files.gif"
- id="org.jboss.ide.eclipse.as.ui.FilesetViewProvider"
- name="File Filters"
- providerClass="org.jboss.ide.eclipse.as.ui.views.server.providers.FilesetViewProvider"/>
- <ViewProvider
description="Lists inactive categories and allows you to turn them back on."
icon="icons/ignore.gif"
id="org.jboss.ide.eclipse.as.ui.InactiveExtensionsProvider"
@@ -181,7 +167,7 @@
listener="org.jboss.ide.eclipse.as.ui.views.server.TwiddlePollerListener"
pollerType="org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller"/>
</extension>
- -->
+ -->
<extension
point="org.eclipse.ui.perspectiveExtensions">
@@ -193,7 +179,7 @@
relative="org.eclipse.ui.views.TaskList"/>
</perspectiveExtension>
</extension>
-
+
<extension
point="org.eclipse.ui.perspectives">
<perspective
@@ -265,40 +251,27 @@
id="org.jboss.ide.eclipse.as.ui.launchConfigurationImage1"/>
</extension>
-<!--
<extension
- point="org.jboss.ide.eclipse.firstrun.FirstRunWizardPage">
- <UpgradeWizard
- WizardPage="org.jboss.ide.eclipse.as.ui.upgrades.UpdatePage20"
- fromVersion="1.6.*"
- id="org.jboss.ide.eclipse.as.ui.firstrun.16.20"
- toVersion="2.0.0.*"
- weight="50"/>
- </extension>
- -->
-
- <extension
point="org.eclipse.help.contexts">
<contexts
file="InlineDocs/Twiddle/twiddleContext.xml">
</contexts>
</extension>
-
-
- <extension point="org.eclipse.ui.popupMenus">
+
+ <extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id="org.jboss.ide.eclipse.as.ui.popups.makeDeployable.contrib"
nameFilter="*"
objectClass="org.eclipse.core.resources.IFile">
<action
- id="org.jboss.ide.eclipse.as.ui.popups.makeDeployable.action"
+ id="org.jboss.ide.eclipse.as.ui.popups.makeDeployable.action"
label="Make Publishable"
icon="icons/publish.gif"
- menubarPath="additions"
- class="org.jboss.ide.eclipse.as.ui.actions.DeployAction">
- </action>
- </objectContribution>
+ menubarPath="additions"
+ class="org.jboss.ide.eclipse.as.ui.actions.DeployAction">
+ </action>
+ </objectContribution>
</extension>
<extension
point="org.eclipse.ui.console.consolePatternMatchListeners">
@@ -350,5 +323,5 @@
</section>
</extension>
-
+
</plugin>
16 years, 3 months
JBoss Tools SVN: r10545 - in trunk: common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgolovin
Date: 2008-09-29 13:50:09 -0400 (Mon, 29 Sep 2008)
New Revision: 10545
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java
Log:
fix JUnit test errors. Patch from Snjezana was applied for:
1) deleting projects
The waitForIdle() method must be called after the r.delete() method in the AbstractSeamFacetTest.tearDown() method.
2) possible deadlock in the AbstractExtendedXMLFileImpl.runCheckerOnLoad() method
This method executes some workspace operations using the Display.getDefault().asyncExec() method what causes a deadlock. Eclipse tries to solve this deadlock by deleting all locks in the UI (main) thread and sometimes doesn't succeed.
The solution is to execute these operations using the WorkspaceJob job.
Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java 2008-09-29 17:43:14 UTC (rev 10544)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java 2008-09-29 17:50:09 UTC (rev 10545)
@@ -1,154 +1,174 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and 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
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.model;
-
-import java.util.*;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.ui.internal.decorators.DecoratorManager;
-import org.eclipse.ui.progress.UIJob;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-import org.osgi.framework.Bundle;
-
-public class XJob extends WorkspaceJob {
- public static Object FAMILY_XJOB = new Object();
-
- public interface XRunnable extends Runnable {
- public String getId();
- }
-
- static XJob JOB = new XJob();
-
- public static void addRunnable(XRunnable runnable) {
- JOB.addRunnableInternal(runnable);
- }
-
- public static void addRunnableWithPriority(XRunnable runnable) {
- JOB.addRunnableInternalWithPriority(runnable);
- }
-
- public static void waitForJob() throws InterruptedException {
- Object[] o = {
- XJob.FAMILY_XJOB, ResourcesPlugin.FAMILY_AUTO_REFRESH, ResourcesPlugin.FAMILY_AUTO_BUILD
- };
- while(true) {
- boolean stop = true;
- for (int i = 0; i < o.length; i++) {
- Job[] js = Platform.getJobManager().find(o[i]);
- if(js != null && js.length > 0) {
- Platform.getJobManager().join(o[i], new NullProgressMonitor());
- stop = false;
- }
- }
- if(stop) {
- Job running = getJobRunning(10);
- if(running != null) {
- running.join();
- stop = false;
- }
- }
- if(stop) break;
- }
- }
-
- public static Job getJobRunning(int iterationLimit) {
- Job[] js = Platform.getJobManager().find(null);
- Job dm = null;
- if(js != null) for (int i = 0; i < js.length; i++) {
- if(js[i].getState() == Job.RUNNING && js[i].getThread() != Thread.currentThread()) {
- if(js[i] instanceof UIJob) continue;
- if(js[i].belongsTo(DecoratorManager.FAMILY_DECORATE)) {
- dm = js[i];
- continue;
- }
- //TODO keep watching
- return js[i];
- }
- }
- if(dm != null) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //ignore
- }
- if(iterationLimit > 0)
- return getJobRunning(iterationLimit - 1);
- }
- return null;
-
- }
-
- Set<String> ids = new HashSet<String>();
- List<XRunnable> list = new ArrayList<XRunnable>();
-
- public XJob() {
- super("JBoss Tools Model Update");
- setSystem(true);
- }
-
- public boolean belongsTo(Object family) {
- return family == FAMILY_XJOB;
- }
-
- void addRunnableInternal(XRunnable runnable) {
- synchronized (this) {
- if(ids.contains(runnable.getId())) return;
- ids.add(runnable.getId());
- list.add(runnable);
- }
- if(getState() == Job.NONE) {
- schedule(1000);
- }
- }
-
- void addRunnableInternalWithPriority(XRunnable runnable) {
- synchronized (this) {
- if(ids.contains(runnable.getId())) return;
- ids.add(runnable.getId());
- list.add(0, runnable);
- }
- if(getState() == Job.NONE) {
- schedule(0);
- }
- }
-
- @Override
- public IStatus runInWorkspace(IProgressMonitor monitor)
- throws CoreException {
- while(true) {
- XRunnable r = null;
- synchronized (this) {
- if(list.size() == 0) break;
- r = list.remove(0);
- }
- monitor.subTask(r.getId());
- int state = 0;
- Bundle b = Platform.getBundle("org.jboss.tools.common.model");
- state = b==null ? -1 : b.getState();
- if(state == Bundle.ACTIVE) {
- r.run();
- }
- synchronized (this) {
- ids.remove(r.getId());
- }
- }
- return Status.OK_STATUS;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model;
+
+import java.util.*;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.internal.decorators.DecoratorManager;
+import org.eclipse.ui.progress.UIJob;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.osgi.framework.Bundle;
+
+public class XJob extends WorkspaceJob {
+ public static Object FAMILY_XJOB = new Object();
+
+ private static boolean suspended = false;
+
+ public interface XRunnable extends Runnable {
+ public String getId();
+ }
+
+ static XJob JOB = new XJob();
+
+ public static void addRunnable(XRunnable runnable) {
+ JOB.addRunnableInternal(runnable);
+ }
+
+ public static void addRunnableWithPriority(XRunnable runnable) {
+ JOB.addRunnableInternalWithPriority(runnable);
+ }
+
+ public static void waitForJob() throws InterruptedException {
+ Object[] o = {
+ XJob.FAMILY_XJOB, ResourcesPlugin.FAMILY_AUTO_REFRESH, ResourcesPlugin.FAMILY_AUTO_BUILD
+ };
+ while(true) {
+ boolean stop = true;
+ for (int i = 0; i < o.length; i++) {
+ Job[] js = Platform.getJobManager().find(o[i]);
+ if(js != null && js.length > 0) {
+ Platform.getJobManager().join(o[i], new NullProgressMonitor());
+ stop = false;
+ }
+ }
+ if(stop) {
+ Job running = getJobRunning(10);
+ if(running != null) {
+ running.join();
+ stop = false;
+ }
+ }
+ if(stop) break;
+ }
+ }
+
+ public static Job getJobRunning(int iterationLimit) {
+ Job[] js = Platform.getJobManager().find(null);
+ Job dm = null;
+ if(js != null) for (int i = 0; i < js.length; i++) {
+ if(js[i].getState() == Job.RUNNING && js[i].getThread() != Thread.currentThread()) {
+ if(js[i] instanceof UIJob) continue;
+ if(js[i].belongsTo(DecoratorManager.FAMILY_DECORATE)) {
+ dm = js[i];
+ continue;
+ }
+ //TODO keep watching
+ return js[i];
+ }
+ }
+ if(dm != null) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ if(iterationLimit > 0)
+ return getJobRunning(iterationLimit - 1);
+ }
+ return null;
+
+ }
+
+ Set<String> ids = new HashSet<String>();
+ List<XRunnable> list = new ArrayList<XRunnable>();
+
+ public XJob() {
+ super("JBoss Tools Model Update");
+ setSystem(true);
+ }
+
+ public boolean belongsTo(Object family) {
+ return family == FAMILY_XJOB;
+ }
+
+ void addRunnableInternal(XRunnable runnable) {
+ if (!isSuspended()) {
+ synchronized (this) {
+ if (ids.contains(runnable.getId()))
+ return;
+ ids.add(runnable.getId());
+ list.add(runnable);
+ }
+ if (getState() == Job.NONE) {
+ schedule(1000);
+ }
+ }
+ }
+
+ void addRunnableInternalWithPriority(XRunnable runnable) {
+ if (!isSuspended()) {
+ synchronized (this) {
+ if (ids.contains(runnable.getId()))
+ return;
+ ids.add(runnable.getId());
+ list.add(0, runnable);
+ }
+ if (getState() == Job.NONE) {
+ schedule(0);
+ }
+ }
+ }
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ while(true) {
+ XRunnable r = null;
+ synchronized (this) {
+ if(list.size() == 0) break;
+ r = list.remove(0);
+ }
+ // monitor.subTask(r.getId()) is irrelevant for system jobs
+ //monitor.subTask(r.getId());
+ // XJob is a class from the org.jboss.tools.common.model plugin. This plugin must be active
+ //int state = 0;
+ //Bundle b = Platform.getBundle("org.jboss.tools.common.model");
+ //state = b==null ? -1 : b.getState();
+ //if(state == Bundle.ACTIVE) {
+ if (!isSuspended()) {
+ r.run();
+ }
+ //}
+ synchronized (this) {
+ ids.remove(r.getId());
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ public static boolean isSuspended() {
+ return suspended;
+ }
+
+ public static void setSuspended(boolean suspended) {
+ XJob.suspended = suspended;
+ }
+
+}
Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2008-09-29 17:43:14 UTC (rev 10544)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2008-09-29 17:50:09 UTC (rev 10545)
@@ -1,345 +1,361 @@
-/*
- * Created on February 20, 2003, 4:02 PM
- */
-
-package org.jboss.tools.common.model.filesystems.impl;
-
-import java.io.StringReader;
-import java.util.*;
-
-import org.eclipse.swt.widgets.Display;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.jboss.tools.common.meta.XAttribute;
-import org.jboss.tools.common.model.*;
-import org.jboss.tools.common.model.engines.impl.EnginesLoader;
-import org.jboss.tools.common.model.filesystems.BodySource;
-import org.jboss.tools.common.model.filesystems.impl.AbstractXMLFileImpl;
-import org.jboss.tools.common.model.loaders.*;
-import org.jboss.tools.common.model.markers.ConstraintChecker;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-import org.jboss.tools.common.model.impl.*;
-import org.jboss.tools.common.model.util.*;
-
-/**
- *
- * @author valera & glory
- */
-public class AbstractExtendedXMLFileImpl extends AbstractXMLFileImpl {
- private static final long serialVersionUID = 7942041044569562286L;
- ConstraintChecker constraintChecker = new ConstraintChecker(this);
-
- public AbstractExtendedXMLFileImpl() {}
-
- public boolean hasChildren() {
- return true;
- }
-
- private static String ns = ".NAME.EXTENSION.overlapped.expanded._body_.actualBodyTimeStamp.correctBody.forceLoad.";
-
- public String get(String name) {
- if(name.equals("_hasErrors_")) {
- return super.get("isIncorrect");
- }
- if (getParent() != null && ns.indexOf("." + name + ".") < 0) {
- if(loadAttributeSeparately(name)) return super.get(name);
- loadChildren();
-
- }
- return super.get(name);
- }
-
- /**
- * Used to avoid file loading when only one attribute is required.
- * This must be used with caution. Now only uri attribute in tld
- * is processed as most critical.
- * @param xmlname
- * @return
- */
- protected boolean shouldLoadAttributeSeparately(String xmlname) {
- return false;
- }
-
- /**
- * @see shouldLoadAttributeSeparately.
- * @param xmlname
- * @return
- */
- private boolean loadAttributeSeparately(String xmlname) {
- BodySource source = getBodySource();
- if(source == null) return true;
- if(!shouldLoadAttributeSeparately(xmlname)) return false;
- if(xmlname == null || xmlname.length() == 0) return false;
- String oldvalue = super.get(xmlname);
- if(oldvalue != null && oldvalue.length() > 0) return true;
- String body = source.get();
- Document doc = XMLUtil.getDocument(new StringReader(body));
- if(doc == null) return false;
- Element element = doc.getDocumentElement();
- if(element == null) return false;
- XModelObjectLoaderUtil util = new XModelObjectLoaderUtil();
- util.setSaveEntity(false);
- String value = util.getAttribute(element, xmlname);
- if(value == null || value.length() == 0) return false;
- super.set(xmlname, value);
- return true;
- }
-
- public boolean isObjectEditable() {
- return super.isObjectEditable() && (!"yes".equals(get("_hasErrors_")));
- }
-
- protected void loadChildren() {
- BodySource source = getBodySource();
- if (source == null) return;
- super.setBodySource(null);
- XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(this);
- String body = source.get();
- XModelObjectLoaderUtil.setTempBody(this, body);
- loader.load(this);
- if(!isIncorrect() && !isOverlapped()) {
- runCheckerOnLoad();
- }
- }
-
- void runCheckerOnLoad() {
- if(!isActive()) return;
- XModelObject s = getParent();
- while(s != null && s.getFileType() != XModelObject.SYSTEM) s = s.getParent();
- if(s == null || !s.getModelEntity().getName().equals("FileSystemFolder")) {
- return;
- }
- Runnable r = new Runnable() {
- public void run() {
- getResourceMarkers().clear();
- constraintChecker.check();
- }
- };
- Display.getDefault().asyncExec(r);
- }
-
- public void set(String name, String value) {
- super.set(name, value);
- if("incorrectBody".equals(name) && value.length() > 0) {
- set("isIncorrect", "yes");
-// setErrors(value, hasDTD(), !hasDTD()); //never validate dtd
- int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
- if(EntityXMLRegistration.isSystemId(value)) resolution = EntityXMLRegistration.UNRESOLVED;
- setErrors(value, resolution == EntityXMLRegistration.DTD, resolution == EntityXMLRegistration.SCHEMA);
- }
- }
-
- public String getAsText() {
- return get("body");
- }
-
- public void edit(String body) throws XModelException {
- edit(body, false);
- }
-
- protected boolean isForceLoadOn() {
- return "true".equals(get("forceLoad"));
- }
-
- public void edit(String body, boolean update) throws XModelException {
- if(body == null) return;
- if(!isForceLoadOn() && body.equals(getAsText())) return;
-
- String entity = getModel().getEntityRecognizer().getEntityName(getAttributeValue("extension"), body);
- if(!entity.equals(getModelEntity().getName())) {
- String[] errors = (body.length() == 0) ? null : XMLUtil.getXMLErrors(new java.io.StringReader(body), false);
- if(errors == null || errors.length == 0) errors = new String[]{"Doctype has been changed. Please save file for the change to take effect in object model. :0:0"};
- setErrors(body, errors);
- XModelImpl m = (XModelImpl)getModel();
- m.fireStructureChanged(this);
- if(!isOverlapped()) getResourceMarkers().update();
- return;
- }
-
- boolean errors1 = ("yes".equals(get("_hasErrors_")));
- AbstractExtendedXMLFileImpl f = getUpdatedFile(body, true);
- if(f == null) return;
- f.getChildren();
-
- XModelObjectImpl p = (XModelObjectImpl)getParent();
- XModelImpl m = (XModelImpl)getModel();
- boolean isOverlapped = isOverlapped();
- if(!isOverlapped) getResourceMarkers().clear();
- if(f.isIncorrect()) {
- getChildren();
- boolean fire = this.loaderError == null && f.loaderError != null;
- this.loaderError = f.loaderError;
- super.set("incorrectBody", f.get("incorrectBody"));
- super.set("isIncorrect", "yes");
- if(f.get("errors") != null) super.set("errors", f.get("errors"));
-
- if(fire) changeTimeStamp();
- if(f.get("actualBodyTimeStamp") != null && !"-1".equals(f.get("actualBodyTimeStamp"))) {
- mergeAll(f, update);
- }
- m.fireStructureChanged(this);
- if(!isOverlapped) getResourceMarkers().update();
- } else if(isMergingChanges()) {
- set("correctBody", body);
- set("actualBodyTimeStamp", "0");
- mergeAll(f, update);
- set("actualBodyTimeStamp", "" + getTimeStamp());
- if(errors1) m.fireStructureChanged(this);
- if(!isOverlapped) constraintChecker.check();
- } else {
- //old edit by replace
- p.removeChild_0(this);
- p.addChild_0(f);
- m.fireStructureChanged(p);
- f.setModified(true);
- if(!isOverlapped) f.getResourceMarkers().update();
- }
- }
-
- protected void safeChangeTimeStamp() {
- boolean b = ("" + getTimeStamp()).equals(get("actualBodyTimeStamp"));
- changeTimeStamp();
- if(b) set("actualBodyTimeStamp", "" + getTimeStamp());
- }
- protected void mergeAll(XModelObject f, boolean update) throws XModelException {
- merge(f, !update);
- }
-
- protected boolean isMergingChanges() {
- return true;
- }
-
- protected String getProcessEntity() {
- return null;
- }
-
- protected boolean hasDTD() {
- return true;
- }
-
- private AbstractExtendedXMLFileImpl getUpdatedFile(String body, boolean fire) {
- boolean errors1 = ("yes".equals(get("_hasErrors_")));
- loaderError = null;
-// setErrors(body, hasDTD(), !hasDTD()); //never validate dtd
- int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
- if(EntityXMLRegistration.isSystemId(body)) resolution = EntityXMLRegistration.UNRESOLVED;
- setErrors(body, resolution == EntityXMLRegistration.DTD, resolution == EntityXMLRegistration.SCHEMA);
- boolean errors2 = (get("errors") != null && get("errors").length() > 0);
- if(errors1 && errors2) {
- super.set("incorrectBody".intern(), body);
- if(fire) {
- changeTimeStamp();
- if(isActive()) ((XModelImpl)getModel()).fireNodeChanged(this, getPath());
- setModified(true);
- }
- }
- AbstractExtendedXMLFileImpl f = (AbstractExtendedXMLFileImpl)getModel().createModelObject(getModelEntity().getName(), null);
- f.setAttributeValue("name", getAttributeValue("name"));
- f.setAttributeValue("extension", getAttributeValue("extension"));
- if(errors2) {
- f.set("incorrectBody", body);
- f.set("errors", super.get("errors"));
- }
- f.setBodySource(new SFBodySource(body));
- return f;
- }
-
- protected final void merge(XModelObject update, boolean fire) throws XModelException {
- if(!"yes".equals(update.get("isIncorrect"))) {
- super.set("incorrectBody", "");
- super.set("isIncorrect","no");
- super.set("errors", "");
- loaderError = null;
- }
- if(update instanceof AbstractExtendedXMLFileImpl) {
- loaderError = ((AbstractExtendedXMLFileImpl)update).loaderError;
- }
- Map<String,XModelObject> map = getChildrenForSaveAsMap();
- Set<String> set = null;
- XModelObject[] cs = update.getChildren();
- String entity = getProcessEntity();
- for (int i = 0; i < cs.length; i++) {
- if(entity != null && entity.equals(cs[i].getModelEntity().getName())) continue;
- XModelObject c = getChildByPath(cs[i].getPathPart());
- if(c == null) {
- if(set == null) set = EnginesLoader.getChildrenToRemove(map, update);
- c = EnginesLoader.findAppropriateChild(set, cs[i], map);
- if(c == null) {
- c = cs[i].copy();
- addChild(c);
- } else {
- EnginesLoader.merge(c, cs[i], fire);
- }
- } else if(c.getModelEntity().getName().equals(cs[i].getModelEntity().getName())) {
- EnginesLoader.merge(c, cs[i], fire);
- } else {
- removeChild(c);
- addChild(cs[i].copy());
- }
- map.remove(c.getPathPart());
- }
- Iterator<XModelObject> it = map.values().iterator();
- while(it.hasNext()) {
- ((XModelObject)it.next()).removeFromParent();
- }
- boolean doFire = false;
- for (int i = 0; i < cs.length; i++) {
- XModelObject c = getChildByPath(cs[i].getPathPart());
- if(c == null) continue;
- int ci = getIndexOfChild(c);
- if(ci == i) continue;
- doFire = true;
- move(ci, i, false);
- }
- if(fire && doFire) ((XModelImpl)getModel()).fireStructureChanged(this);
- mergeAttributes(update, fire);
- }
-
- static String NO_MERGE_ATTRIBUTES = ".name.extension._lateload.isIncorrect.incorrectBody.expand.";
- void mergeAttributes(XModelObject update, boolean fire) throws XModelException {
- XAttribute[] as = update.getModelEntity().getAttributes();
- for (int i = 0; i < as.length; i++) {
- String n = as[i].getName();
- if(NO_MERGE_ATTRIBUTES.indexOf("." + n + ".") >= 0) continue;
- XModelObjectLoaderUtil.mergeAttributeComment(this, update, as[i], fire);
- String ov = getAttributeValue(n);
- String nv = update.getAttributeValue(n);
- if(ov == null || ov.equals(nv)) continue;
- if(fire) {
- getModel().changeObjectAttribute(this, n, nv);
- } else {
- setAttributeValue(n, nv);
- }
- }
- XModelObjectLoaderUtil.mergeFinalComment(this, update, fire);
- }
-
- private Map<String,XModelObject> getChildrenForSaveAsMap() {
- String entity = getProcessEntity();
- XModelObject[] cs = getChildrenForSave();
- Map<String,XModelObject> map = new HashMap<String,XModelObject>();
- for (int i = 0; i < cs.length; i++) {
- if(entity != null && entity.equals(cs[i].getModelEntity().getName())) continue;
- map.put(cs[i].getPathPart(), cs[i]);
- }
- return map;
- }
-
-}
-
-class SFBodySource implements BodySource {
- String body;
-
- public SFBodySource(String body) {
- this.body = body;
- }
-
- public String get() {
- return body;
- }
-
- public boolean write(Object object) {
- return true;
- }
-}
+/*
+ * Created on February 20, 2003, 4:02 PM
+ */
+
+package org.jboss.tools.common.model.filesystems.impl;
+
+import java.io.StringReader;
+import java.util.*;
+
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.widgets.Display;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.model.engines.impl.EnginesLoader;
+import org.jboss.tools.common.model.filesystems.BodySource;
+import org.jboss.tools.common.model.filesystems.impl.AbstractXMLFileImpl;
+import org.jboss.tools.common.model.loaders.*;
+import org.jboss.tools.common.model.markers.ConstraintChecker;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.jboss.tools.common.model.impl.*;
+import org.jboss.tools.common.model.util.*;
+
+/**
+ *
+ * @author valera & glory
+ */
+public class AbstractExtendedXMLFileImpl extends AbstractXMLFileImpl {
+ private static final long serialVersionUID = 7942041044569562286L;
+ ConstraintChecker constraintChecker = new ConstraintChecker(this);
+
+ public AbstractExtendedXMLFileImpl() {}
+
+ public boolean hasChildren() {
+ return true;
+ }
+
+ private static String ns = ".NAME.EXTENSION.overlapped.expanded._body_.actualBodyTimeStamp.correctBody.forceLoad.";
+
+ public String get(String name) {
+ if(name.equals("_hasErrors_")) {
+ return super.get("isIncorrect");
+ }
+ if (getParent() != null && ns.indexOf("." + name + ".") < 0) {
+ if(loadAttributeSeparately(name)) return super.get(name);
+ loadChildren();
+
+ }
+ return super.get(name);
+ }
+
+ /**
+ * Used to avoid file loading when only one attribute is required.
+ * This must be used with caution. Now only uri attribute in tld
+ * is processed as most critical.
+ * @param xmlname
+ * @return
+ */
+ protected boolean shouldLoadAttributeSeparately(String xmlname) {
+ return false;
+ }
+
+ /**
+ * @see shouldLoadAttributeSeparately.
+ * @param xmlname
+ * @return
+ */
+ private boolean loadAttributeSeparately(String xmlname) {
+ BodySource source = getBodySource();
+ if(source == null) return true;
+ if(!shouldLoadAttributeSeparately(xmlname)) return false;
+ if(xmlname == null || xmlname.length() == 0) return false;
+ String oldvalue = super.get(xmlname);
+ if(oldvalue != null && oldvalue.length() > 0) return true;
+ String body = source.get();
+ Document doc = XMLUtil.getDocument(new StringReader(body));
+ if(doc == null) return false;
+ Element element = doc.getDocumentElement();
+ if(element == null) return false;
+ XModelObjectLoaderUtil util = new XModelObjectLoaderUtil();
+ util.setSaveEntity(false);
+ String value = util.getAttribute(element, xmlname);
+ if(value == null || value.length() == 0) return false;
+ super.set(xmlname, value);
+ return true;
+ }
+
+ public boolean isObjectEditable() {
+ return super.isObjectEditable() && (!"yes".equals(get("_hasErrors_")));
+ }
+
+ protected void loadChildren() {
+ BodySource source = getBodySource();
+ if (source == null) return;
+ super.setBodySource(null);
+ XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(this);
+ String body = source.get();
+ XModelObjectLoaderUtil.setTempBody(this, body);
+ loader.load(this);
+ if(!isIncorrect() && !isOverlapped()) {
+ runCheckerOnLoad();
+ }
+ }
+ WorkspaceJob checkerOnLoad = new WorkspaceJob("Checking on load...") {
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ getResourceMarkers().clear();
+ constraintChecker.check();
+ return Status.OK_STATUS;
+ }
+
+ };
+ void runCheckerOnLoad() {
+ if(!isActive()) return;
+ XModelObject s = getParent();
+ while(s != null && s.getFileType() != XModelObject.SYSTEM) s = s.getParent();
+ if(s == null || !s.getModelEntity().getName().equals("FileSystemFolder")) {
+ return;
+ }
+ /*Runnable r = new Runnable() {
+ public void run() {
+ getResourceMarkers().clear();
+ constraintChecker.check();
+ }
+ };
+ Display.getDefault().asyncExec(r);*/
+ checkerOnLoad.schedule();
+ }
+
+ public void set(String name, String value) {
+ super.set(name, value);
+ if("incorrectBody".equals(name) && value.length() > 0) {
+ set("isIncorrect", "yes");
+// setErrors(value, hasDTD(), !hasDTD()); //never validate dtd
+ int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
+ if(EntityXMLRegistration.isSystemId(value)) resolution = EntityXMLRegistration.UNRESOLVED;
+ setErrors(value, resolution == EntityXMLRegistration.DTD, resolution == EntityXMLRegistration.SCHEMA);
+ }
+ }
+
+ public String getAsText() {
+ return get("body");
+ }
+
+ public void edit(String body) throws XModelException {
+ edit(body, false);
+ }
+
+ protected boolean isForceLoadOn() {
+ return "true".equals(get("forceLoad"));
+ }
+
+ public void edit(String body, boolean update) throws XModelException {
+ if(body == null) return;
+ if(!isForceLoadOn() && body.equals(getAsText())) return;
+
+ String entity = getModel().getEntityRecognizer().getEntityName(getAttributeValue("extension"), body);
+ if(!entity.equals(getModelEntity().getName())) {
+ String[] errors = (body.length() == 0) ? null : XMLUtil.getXMLErrors(new java.io.StringReader(body), false);
+ if(errors == null || errors.length == 0) errors = new String[]{"Doctype has been changed. Please save file for the change to take effect in object model. :0:0"};
+ setErrors(body, errors);
+ XModelImpl m = (XModelImpl)getModel();
+ m.fireStructureChanged(this);
+ if(!isOverlapped()) getResourceMarkers().update();
+ return;
+ }
+
+ boolean errors1 = ("yes".equals(get("_hasErrors_")));
+ AbstractExtendedXMLFileImpl f = getUpdatedFile(body, true);
+ if(f == null) return;
+ f.getChildren();
+
+ XModelObjectImpl p = (XModelObjectImpl)getParent();
+ XModelImpl m = (XModelImpl)getModel();
+ boolean isOverlapped = isOverlapped();
+ if(!isOverlapped) getResourceMarkers().clear();
+ if(f.isIncorrect()) {
+ getChildren();
+ boolean fire = this.loaderError == null && f.loaderError != null;
+ this.loaderError = f.loaderError;
+ super.set("incorrectBody", f.get("incorrectBody"));
+ super.set("isIncorrect", "yes");
+ if(f.get("errors") != null) super.set("errors", f.get("errors"));
+
+ if(fire) changeTimeStamp();
+ if(f.get("actualBodyTimeStamp") != null && !"-1".equals(f.get("actualBodyTimeStamp"))) {
+ mergeAll(f, update);
+ }
+ m.fireStructureChanged(this);
+ if(!isOverlapped) getResourceMarkers().update();
+ } else if(isMergingChanges()) {
+ set("correctBody", body);
+ set("actualBodyTimeStamp", "0");
+ mergeAll(f, update);
+ set("actualBodyTimeStamp", "" + getTimeStamp());
+ if(errors1) m.fireStructureChanged(this);
+ if(!isOverlapped) constraintChecker.check();
+ } else {
+ //old edit by replace
+ p.removeChild_0(this);
+ p.addChild_0(f);
+ m.fireStructureChanged(p);
+ f.setModified(true);
+ if(!isOverlapped) f.getResourceMarkers().update();
+ }
+ }
+
+ protected void safeChangeTimeStamp() {
+ boolean b = ("" + getTimeStamp()).equals(get("actualBodyTimeStamp"));
+ changeTimeStamp();
+ if(b) set("actualBodyTimeStamp", "" + getTimeStamp());
+ }
+ protected void mergeAll(XModelObject f, boolean update) throws XModelException {
+ merge(f, !update);
+ }
+
+ protected boolean isMergingChanges() {
+ return true;
+ }
+
+ protected String getProcessEntity() {
+ return null;
+ }
+
+ protected boolean hasDTD() {
+ return true;
+ }
+
+ private AbstractExtendedXMLFileImpl getUpdatedFile(String body, boolean fire) {
+ boolean errors1 = ("yes".equals(get("_hasErrors_")));
+ loaderError = null;
+// setErrors(body, hasDTD(), !hasDTD()); //never validate dtd
+ int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
+ if(EntityXMLRegistration.isSystemId(body)) resolution = EntityXMLRegistration.UNRESOLVED;
+ setErrors(body, resolution == EntityXMLRegistration.DTD, resolution == EntityXMLRegistration.SCHEMA);
+ boolean errors2 = (get("errors") != null && get("errors").length() > 0);
+ if(errors1 && errors2) {
+ super.set("incorrectBody".intern(), body);
+ if(fire) {
+ changeTimeStamp();
+ if(isActive()) ((XModelImpl)getModel()).fireNodeChanged(this, getPath());
+ setModified(true);
+ }
+ }
+ AbstractExtendedXMLFileImpl f = (AbstractExtendedXMLFileImpl)getModel().createModelObject(getModelEntity().getName(), null);
+ f.setAttributeValue("name", getAttributeValue("name"));
+ f.setAttributeValue("extension", getAttributeValue("extension"));
+ if(errors2) {
+ f.set("incorrectBody", body);
+ f.set("errors", super.get("errors"));
+ }
+ f.setBodySource(new SFBodySource(body));
+ return f;
+ }
+
+ protected final void merge(XModelObject update, boolean fire) throws XModelException {
+ if(!"yes".equals(update.get("isIncorrect"))) {
+ super.set("incorrectBody", "");
+ super.set("isIncorrect","no");
+ super.set("errors", "");
+ loaderError = null;
+ }
+ if(update instanceof AbstractExtendedXMLFileImpl) {
+ loaderError = ((AbstractExtendedXMLFileImpl)update).loaderError;
+ }
+ Map<String,XModelObject> map = getChildrenForSaveAsMap();
+ Set<String> set = null;
+ XModelObject[] cs = update.getChildren();
+ String entity = getProcessEntity();
+ for (int i = 0; i < cs.length; i++) {
+ if(entity != null && entity.equals(cs[i].getModelEntity().getName())) continue;
+ XModelObject c = getChildByPath(cs[i].getPathPart());
+ if(c == null) {
+ if(set == null) set = EnginesLoader.getChildrenToRemove(map, update);
+ c = EnginesLoader.findAppropriateChild(set, cs[i], map);
+ if(c == null) {
+ c = cs[i].copy();
+ addChild(c);
+ } else {
+ EnginesLoader.merge(c, cs[i], fire);
+ }
+ } else if(c.getModelEntity().getName().equals(cs[i].getModelEntity().getName())) {
+ EnginesLoader.merge(c, cs[i], fire);
+ } else {
+ removeChild(c);
+ addChild(cs[i].copy());
+ }
+ map.remove(c.getPathPart());
+ }
+ Iterator<XModelObject> it = map.values().iterator();
+ while(it.hasNext()) {
+ ((XModelObject)it.next()).removeFromParent();
+ }
+ boolean doFire = false;
+ for (int i = 0; i < cs.length; i++) {
+ XModelObject c = getChildByPath(cs[i].getPathPart());
+ if(c == null) continue;
+ int ci = getIndexOfChild(c);
+ if(ci == i) continue;
+ doFire = true;
+ move(ci, i, false);
+ }
+ if(fire && doFire) ((XModelImpl)getModel()).fireStructureChanged(this);
+ mergeAttributes(update, fire);
+ }
+
+ static String NO_MERGE_ATTRIBUTES = ".name.extension._lateload.isIncorrect.incorrectBody.expand.";
+ void mergeAttributes(XModelObject update, boolean fire) throws XModelException {
+ XAttribute[] as = update.getModelEntity().getAttributes();
+ for (int i = 0; i < as.length; i++) {
+ String n = as[i].getName();
+ if(NO_MERGE_ATTRIBUTES.indexOf("." + n + ".") >= 0) continue;
+ XModelObjectLoaderUtil.mergeAttributeComment(this, update, as[i], fire);
+ String ov = getAttributeValue(n);
+ String nv = update.getAttributeValue(n);
+ if(ov == null || ov.equals(nv)) continue;
+ if(fire) {
+ getModel().changeObjectAttribute(this, n, nv);
+ } else {
+ setAttributeValue(n, nv);
+ }
+ }
+ XModelObjectLoaderUtil.mergeFinalComment(this, update, fire);
+ }
+
+ private Map<String,XModelObject> getChildrenForSaveAsMap() {
+ String entity = getProcessEntity();
+ XModelObject[] cs = getChildrenForSave();
+ Map<String,XModelObject> map = new HashMap<String,XModelObject>();
+ for (int i = 0; i < cs.length; i++) {
+ if(entity != null && entity.equals(cs[i].getModelEntity().getName())) continue;
+ map.put(cs[i].getPathPart(), cs[i]);
+ }
+ return map;
+ }
+
+}
+
+class SFBodySource implements BodySource {
+ String body;
+
+ public SFBodySource(String body) {
+ this.body = body;
+ }
+
+ public String get() {
+ return body;
+ }
+
+ public boolean write(Object object) {
+ return true;
+ }
+}
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF 2008-09-29 17:43:14 UTC (rev 10544)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF 2008-09-29 17:50:09 UTC (rev 10545)
@@ -1,37 +1,38 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Seam Core Tests Plug-in
-Bundle-SymbolicName: org.jboss.tools.seam.core.test;singleton:=true
-Bundle-Version: 2.0.0
-Bundle-ClassPath: seam-core-tests.jar
-Bundle-Vendor: Red Hat, Inc.
-Export-Package: org.jboss.tools.seam.core.test,
- org.jboss.tools.seam.core.test.project.facet,
- org.jboss.tools.seam.core.test.refactoring
-Require-Bundle:
- org.junit,
- org.eclipse.core.runtime,
- org.eclipse.core.resources,
- org.jboss.tools.common.model,
- org.jboss.tools.seam.core,
- org.jboss.tools.seam.xml,
- org.jboss.tools.common.test,
- org.jboss.tools.jsf,
- org.eclipse.wst.common.project.facet.core,
- org.jboss.tools.tests,
- org.eclipse.ui.workbench,
- org.eclipse.wst.common.modulecore,
- org.eclipse.wst.common.frameworks,
- org.eclipse.jface,
- org.jboss.tools.jst.firstrun,
- org.eclipse.wst.server.core,
- org.eclipse.datatools.connectivity,
- org.eclipse.ltk.core.refactoring,
- org.eclipse.ltk.ui.refactoring,
- org.eclipse.jdt.core,
- org.eclipse.jdt.ui,
- org.eclipse.ui.ide,
- org.eclipse.jface,
- org.eclipse.jdt.core.manipulation,
- org.eclipse.jst.jsf.core
-Provide-Package: org.jboss.tools.seam.core.test
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Seam Core Tests Plug-in
+Bundle-SymbolicName: org.jboss.tools.seam.core.test;singleton:=true
+Bundle-Version: 2.0.0
+Bundle-ClassPath: seam-core-tests.jar
+Bundle-Vendor: Red Hat, Inc.
+Export-Package: org.jboss.tools.seam.core.test,
+ org.jboss.tools.seam.core.test.project.facet,
+ org.jboss.tools.seam.core.test.refactoring
+Require-Bundle:
+ org.junit,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.jboss.tools.common.model,
+ org.jboss.tools.seam.core,
+ org.jboss.tools.seam.xml,
+ org.jboss.tools.common.test,
+ org.jboss.tools.jsf,
+ org.eclipse.wst.common.project.facet.core,
+ org.jboss.tools.tests,
+ org.eclipse.ui.workbench,
+ org.eclipse.wst.common.modulecore,
+ org.eclipse.wst.common.frameworks,
+ org.eclipse.jface,
+ org.jboss.tools.jst.firstrun,
+ org.eclipse.wst.server.core,
+ org.eclipse.datatools.connectivity,
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.ltk.ui.refactoring,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.jface,
+ org.eclipse.jdt.core.manipulation,
+ org.eclipse.jst.jsf.core,
+ org.eclipse.wst.validation
+Provide-Package: org.jboss.tools.seam.core.test
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2008-09-29 17:43:14 UTC (rev 10544)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2008-09-29 17:50:09 UTC (rev 10545)
@@ -102,17 +102,18 @@
// Wait until all jobs is finished to avoid delete project problems
- ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- waitForIdle();
boolean oldAutoBuilding = true;
Exception last = null;
try {
- oldAutoBuilding = ResourcesUtils.setBuildAutomatically(false);
+ oldAutoBuilding = ResourcesUtils.setBuildAutomatically(false);
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ waitForIdle();
for (IResource r : this.resourcesToCleanup) {
try {
- System.out.println("Deleting " + r);
- r.getProject().close(null);
+ //System.out.println("Deleting " + r);
+ //r.getProject().close(null);
r.delete(true, null);
+ waitForIdle();
} catch(Exception e) {
System.out.println("Error deleting " + r);
e.printStackTrace();
@@ -132,7 +133,11 @@
public static void waitForIdle() {
long start = System.currentTimeMillis();
- while (!EditorTestHelper.allJobsQuiet()) {
+ // Job.getJobManager().isIdle() is more efficient than EditorTestHelper.allJobsQuiet()
+ // EditorTestHelper.allJobsQuiet() isn't thread-safe
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=198241 is fixed
+ //while (!EditorTestHelper.allJobsQuiet()) {
+ while (!Job.getJobManager().isIdle()) {
delay(500);
if ( (System.currentTimeMillis()-start) > MAX_IDLE )
throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
@@ -245,22 +250,22 @@
assertNotNull("seam home folder was null!", folder);
assertTrue(folder.getAbsolutePath() + " does not exist", folder.exists());
- System.out.println("Listing " + folder);
+ //System.out.println("Listing " + folder);
File[] list = folder.listFiles();
for (int i = 0; i < list.length; i++) {
File string = list[i];
- System.out.println(i + ": " + string.getName() +(string.isDirectory()?" (dir)":""));
+ //System.out.println(i + ": " + string.getName() +(string.isDirectory()?" (dir)":""));
}
File seamgen = new File(folder, "seam-gen");
assertNotNull("seam gen folder was null!", seamgen);
assertTrue(seamgen.getName() + " seamgen does not exist", seamgen.exists());
- System.out.println("Listing seamgen " + seamgen);
+ //System.out.println("Listing seamgen " + seamgen);
list = seamgen.listFiles();
for (int i = 0; i < list.length; i++) {
File string = list[i];
- System.out.println(i + ": " + string.getName() +(string.isDirectory()?" (dir)":""));
+ //System.out.println(i + ": " + string.getName() +(string.isDirectory()?" (dir)":""));
}
}
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2008-09-29 17:43:14 UTC (rev 10544)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2008-09-29 17:50:09 UTC (rev 10545)
@@ -1,299 +1,330 @@
-/*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.core.test.project.facet;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceProxy;
-import org.eclipse.core.resources.IResourceProxyVisitor;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-import org.jboss.tools.seam.core.SeamProjectsSet;
-import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
-import org.jboss.tools.seam.core.project.facet.SeamVersion;
-import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
-
-public class Seam2FacetInstallDelegateTest extends AbstractSeamFacetTest {
-
- protected static final String SEAM_2_0_0 = "Seam 2.0.0";
- IFacetedProject warProject;
- IFacetedProject earProject;
-
- private IProjectFacet seam2Facet;
- private IProjectFacetVersion seam2FacetVersion;
-
- public Seam2FacetInstallDelegateTest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- assertSeamHomeAvailable();
-
- seam2Facet = ProjectFacetsManager.getProjectFacet("jst.seam");
- seam2FacetVersion = seam2Facet.getVersion("2.0");
-
-
- File folder = getSeamHomeFolder();
-
- SeamRuntimeManager.getInstance().addRuntime(SEAM_2_0_0, folder.getAbsolutePath(), SeamVersion.SEAM_2_0, true);
- SeamRuntimeManager.getInstance().findRuntimeByName(SEAM_2_0_0);
-
- warProject = createSeamWarProject("warprj");
- earProject = createSeamEarProject("earprj");
-
- warProject.getProject().getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
-
-
-
- super.setUp();
- }
-
- @Override
- protected File getSeamHomeFolder() {
- return new File(System.getProperty("jbosstools.test.seam.2.0.1.GA.home",
- "E:\\Java\\JBoss\\Seam\\jboss-seam-2.0.1.GA"));
- }
-
- @Override
- protected IDataModel createSeamDataModel(String deployType) {
-
- IDataModel dataModel = super.createSeamDataModel(deployType);
- dataModel.setStringProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME, SEAM_2_0_0);
-
- return dataModel;
- }
-
-
- public void testWarLibs() throws CoreException {
-
- Set<String> seamgenlibs = new HashSet<String>();
-
-
- seamgenlibs.add("antlr-runtime.jar");
- seamgenlibs.add("commons-beanutils.jar");
- seamgenlibs.add("commons-digester.jar");
- seamgenlibs.add("drools-compiler.jar");
- seamgenlibs.add("drools-core.jar");
- seamgenlibs.add("core.jar");
- seamgenlibs.add("jboss-el.jar");
- seamgenlibs.add("jboss-seam-debug.jar");
- seamgenlibs.add("jboss-seam-ioc.jar");
- seamgenlibs.add("jboss-seam.jar");
- seamgenlibs.add("jboss-seam-mail.jar");
- seamgenlibs.add("jboss-seam-pdf.jar");
- seamgenlibs.add("jboss-seam-remoting.jar");
- seamgenlibs.add("jboss-seam-ui.jar");
- seamgenlibs.add("jbpm-jpdl.jar");
- seamgenlibs.add("jsf-facelets.jar");
- seamgenlibs.add("mvel14.jar");
- seamgenlibs.add("richfaces-api.jar");
- seamgenlibs.add("richfaces-impl.jar");
- seamgenlibs.add("richfaces-ui.jar");
-
- final IContainer warLibs = (IContainer) warProject.getProject().findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class);
- assertOnlyContainsTheseFiles(seamgenlibs, warLibs);
-
-
- }
-
- public void testEarLibs() throws CoreException {
-
- IProject war = earProject.getProject();
-
- SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earProject.getProject());
-
- IProject ear = seamProjectsSet.getEarProject();
-
- Set<String> onlyInWar = new HashSet<String>();
- Set<String> onlyInEar = new HashSet<String>();
- Set<String> onlyInEjbSrc = new HashSet<String>();
-
- onlyInEar.add("jboss-seam.jar");
- onlyInEar.add("antlr-runtime.jar");
- onlyInEar.add("drools-compiler.jar");
- onlyInEar.add("drools-core.jar");
- onlyInEar.add("jboss-el.jar");
- onlyInEar.add("mvel14.jar");
- onlyInEar.add("richfaces-api.jar");
- onlyInEar.add("jbpm-jpdl.jar");
- onlyInEar.add("META-INF");
-
- onlyInWar.add("commons-beanutils.jar");
- onlyInWar.add("commons-digester.jar");
- onlyInWar.add("jboss-seam-debug.jar");
- onlyInWar.add("jboss-seam-ioc.jar");
- onlyInWar.add("jboss-seam-mail.jar");
- onlyInWar.add("jboss-seam-pdf.jar");
- onlyInWar.add("jboss-seam-remoting.jar");
- onlyInWar.add("jboss-seam-ui.jar");
- onlyInWar.add("jsf-facelets.jar");
- onlyInWar.add("richfaces-impl.jar");
- onlyInWar.add("richfaces-ui.jar");
-
- final IContainer earLibs = (IContainer) ear.findMember("EarContent").getAdapter(IContainer.class);
-
- assertOnlyContainsTheseFiles(onlyInEar, earLibs);
-
- final IContainer earMeta = (IContainer) ear.findMember("EarContent/META-INF").getAdapter(IContainer.class);
-
- Set onlyInEarMeta = new HashSet();
-
- onlyInEarMeta.add("jboss-app.xml");
- onlyInEarMeta.add("application.xml");
-
- assertOnlyContainsTheseFiles(onlyInEarMeta, earMeta);
-
- assertOnlyContainsTheseFiles(onlyInWar, (IContainer)war.findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class));
-
- IProject ejb = seamProjectsSet.getEjbProject();
-
- onlyInEjbSrc.add("security.drl");
- onlyInEjbSrc.add("seam.properties");
- onlyInEjbSrc.add("import.sql");
- onlyInEjbSrc.add("components.properties");
- onlyInEjbSrc.add("META-INF"); // JBIDE-2431: META-INF dir is always created by Seam 2.0 seamgen
- onlyInEjbSrc.add("org"); // JBIDE-2431: org dir is always created by Seam 2.0 seamgen
-
- assertOnlyContainsTheseFiles(onlyInEjbSrc, (IContainer)ejb.findMember("ejbModule").getAdapter(IContainer.class));
- }
-
-
- /**
- * Fails if set of fileNames is not found in dir or some other filename is found in dir.
- * @param fileNames set of strings
- * @param dir directory to scan
- * @throws CoreException
- */
- protected void assertOnlyContainsTheseFiles(Set<String> fileNames,
- final IResource dir) throws CoreException {
-
- final Set<String> foundFiles = new HashSet<String>();
- dir.accept(new IResourceProxyVisitor() {
-
- public boolean visit(IResourceProxy proxy) throws CoreException {
- if(dir.getName().equals(proxy.getName())) return true;
- foundFiles.add(proxy.getName());
- return false;
- }
-
- }, IResource.DEPTH_ZERO);
-
- if(!foundFiles.containsAll(fileNames)) {
- fileNames.removeAll(foundFiles);
- fail("Did not find " + fileNames + " in " + dir);
- }
-
- foundFiles.removeAll(fileNames);
-
- assertTrue("Found additional files (" + foundFiles + " in " + dir + " at " + dir.getLocation(), foundFiles.isEmpty());
- }
-
- public void testBootstrapDirPresent() throws CoreException, IOException {
-
- SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
-
- IProject testProject = warPs.getTestProject();
- assertTrue(testProject.exists());
-
- assertNotNull(testProject.findMember("bootstrap"));
- assertNotNull(testProject.findMember("bootstrap/data"));
-
- assertNull("embedded-ejb should not be installed for seam2", testProject.findMember("embedded-ejb"));
-
- }
-
- public void testTestLibs() throws CoreException, IOException {
-
- SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
-
- IProject testProject = warPs.getTestProject();
- assertTrue(testProject.exists());
-
- Set<String> libs = new HashSet<String>();
- libs.add("testng.jar");
- libs.add("hibernate-all.jar");
-// libs.add("jboss-deployers.jar"); // JBIDE-2431: There is no such jar created by Seam 2.0 seamgen
- libs.add("jboss-embedded-all.jar");
- libs.add("thirdparty-all.jar");
- libs.add("jboss-embedded-api.jar");
- libs.add("core.jar");
-
- assertOnlyContainsTheseFiles(libs, testProject.findMember("lib"));
-
- // JBIDE-2431: The following block is commented because it duplicates the call to assertOnlyContainsTheseFiles()
-/*
- assertNotNull(testProject.findMember("lib/testng.jar"));
- assertNotNull(testProject.findMember("lib/hibernate-all.jar"));
-// assertNotNull(testProject.findMember("lib/jboss-deployers.jar")); // JBIDE-2431: There is no such jar created by Seam 2.0 seamgen
- assertNotNull(testProject.findMember("lib/jboss-embedded-all.jar"));
- assertNotNull(testProject.findMember("lib/thirdparty-all.jar"));
- assertNotNull(testProject.findMember("lib/core.jar")); // JBIDE-2431: lib/core.jar file is always created by Seam 2.0 seamgen
-*/
- }
-
- public void testSeamProperties() {
- SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
-
- IProject warProject = warPs.getWarProject();
- assertTrue(warProject.exists());
-
- assertNotNull(warProject.findMember("src/model/seam.properties"));
- IResource findMember = warProject.findMember("src/action/seam.properties");
- assertNotNull(findMember);
- assertTrue(findMember instanceof IFile);
-
- }
-
- public void testJbpmPresent() throws CoreException, IOException {
-
- SeamProjectsSet earPs = new SeamProjectsSet(earProject.getProject());
-
- IProject project = earPs.getEarProject();
- assertTrue(project.exists());
-
- assertNotNull(project.findMember("EarContent/jbpm-jpdl.jar"));
-
- }
-
- public void testDroolsPresent() throws CoreException, IOException {
-
-
- IProject earRoot = earProject.getProject();
- SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earRoot);
-
- // JBIDE-2431: security.drl is always created in <EJBProject>/ejbModule directory by Seam 2.0 seamgen
- IProject ejbProject = seamProjectsSet.getEjbProject();
- assertNotNull(ejbProject.findMember("ejbModule/security.drl"));
-
- }
-
- public void testCreateEar() throws CoreException, IOException {
-
-
- }
-
- @Override
- protected IProjectFacetVersion getSeamFacetVersion() {
- return seam2FacetVersion;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.test.project.facet;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.EventManager;
+import org.eclipse.wst.validation.internal.ValOperationManager;
+import org.jboss.tools.common.model.XJob;
+import org.jboss.tools.seam.core.SeamProjectsSet;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
+import org.jboss.tools.seam.core.project.facet.SeamVersion;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+
+public class Seam2FacetInstallDelegateTest extends AbstractSeamFacetTest {
+
+ protected static final String SEAM_2_0_0 = "Seam 2.0.0";
+ IFacetedProject warProject;
+ IFacetedProject earProject;
+
+ private IProjectFacet seam2Facet;
+ private IProjectFacetVersion seam2FacetVersion;
+ private boolean suspendAllValidation;
+ private boolean suspendXJobs;
+
+ public Seam2FacetInstallDelegateTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ suspendAllValidation = ValidationFramework.getDefault().isSuspended();
+ ValidationFramework.getDefault().suspendAllValidation(true);
+
+ ws.removeResourceChangeListener( EventManager.getManager() );
+ ws.removeResourceChangeListener( ValOperationManager.getDefault() );
+ //EventManager.getManager().shutdown();
+
+ suspendXJobs = XJob.isSuspended();
+ XJob.setSuspended(true);
+ assertSeamHomeAvailable();
+
+ seam2Facet = ProjectFacetsManager.getProjectFacet("jst.seam");
+ seam2FacetVersion = seam2Facet.getVersion("2.0");
+
+
+ File folder = getSeamHomeFolder();
+
+ SeamRuntimeManager.getInstance().addRuntime(SEAM_2_0_0, folder.getAbsolutePath(), SeamVersion.SEAM_2_0, true);
+ SeamRuntimeManager.getInstance().findRuntimeByName(SEAM_2_0_0);
+
+ warProject = createSeamWarProject("warprj");
+ earProject = createSeamEarProject("earprj");
+
+ warProject.getProject().getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+
+
+
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ ValidationFramework.getDefault().suspendAllValidation(suspendAllValidation);
+ XJob.setSuspended(suspendXJobs);
+
+ ws.addResourceChangeListener(EventManager.getManager(),
+ IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE |
+ IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_CHANGE);
+ ws.addResourceChangeListener(ValOperationManager.getDefault(),
+ IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_BUILD);
+
+ }
+
+ @Override
+ protected File getSeamHomeFolder() {
+ return new File(System.getProperty("jbosstools.test.seam.2.0.1.GA.home",
+ "E:\\Java\\JBoss\\Seam\\jboss-seam-2.0.1.GA"));
+ }
+
+ @Override
+ protected IDataModel createSeamDataModel(String deployType) {
+
+ IDataModel dataModel = super.createSeamDataModel(deployType);
+ dataModel.setStringProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME, SEAM_2_0_0);
+
+ return dataModel;
+ }
+
+
+ public void testWarLibs() throws CoreException {
+
+ Set<String> seamgenlibs = new HashSet<String>();
+
+
+ seamgenlibs.add("antlr-runtime.jar");
+ seamgenlibs.add("commons-beanutils.jar");
+ seamgenlibs.add("commons-digester.jar");
+ seamgenlibs.add("drools-compiler.jar");
+ seamgenlibs.add("drools-core.jar");
+ seamgenlibs.add("core.jar");
+ seamgenlibs.add("jboss-el.jar");
+ seamgenlibs.add("jboss-seam-debug.jar");
+ seamgenlibs.add("jboss-seam-ioc.jar");
+ seamgenlibs.add("jboss-seam.jar");
+ seamgenlibs.add("jboss-seam-mail.jar");
+ seamgenlibs.add("jboss-seam-pdf.jar");
+ seamgenlibs.add("jboss-seam-remoting.jar");
+ seamgenlibs.add("jboss-seam-ui.jar");
+ seamgenlibs.add("jbpm-jpdl.jar");
+ seamgenlibs.add("jsf-facelets.jar");
+ seamgenlibs.add("mvel14.jar");
+ seamgenlibs.add("richfaces-api.jar");
+ seamgenlibs.add("richfaces-impl.jar");
+ seamgenlibs.add("richfaces-ui.jar");
+
+ final IContainer warLibs = (IContainer) warProject.getProject().findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class);
+ assertOnlyContainsTheseFiles(seamgenlibs, warLibs);
+
+
+ }
+
+ public void testEarLibs() throws CoreException {
+
+ IProject war = earProject.getProject();
+
+ SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earProject.getProject());
+
+ IProject ear = seamProjectsSet.getEarProject();
+
+ Set<String> onlyInWar = new HashSet<String>();
+ Set<String> onlyInEar = new HashSet<String>();
+ Set<String> onlyInEjbSrc = new HashSet<String>();
+
+ onlyInEar.add("jboss-seam.jar");
+ onlyInEar.add("antlr-runtime.jar");
+ onlyInEar.add("drools-compiler.jar");
+ onlyInEar.add("drools-core.jar");
+ onlyInEar.add("jboss-el.jar");
+ onlyInEar.add("mvel14.jar");
+ onlyInEar.add("richfaces-api.jar");
+ onlyInEar.add("jbpm-jpdl.jar");
+ onlyInEar.add("META-INF");
+
+ onlyInWar.add("commons-beanutils.jar");
+ onlyInWar.add("commons-digester.jar");
+ onlyInWar.add("jboss-seam-debug.jar");
+ onlyInWar.add("jboss-seam-ioc.jar");
+ onlyInWar.add("jboss-seam-mail.jar");
+ onlyInWar.add("jboss-seam-pdf.jar");
+ onlyInWar.add("jboss-seam-remoting.jar");
+ onlyInWar.add("jboss-seam-ui.jar");
+ onlyInWar.add("jsf-facelets.jar");
+ onlyInWar.add("richfaces-impl.jar");
+ onlyInWar.add("richfaces-ui.jar");
+
+ final IContainer earLibs = (IContainer) ear.findMember("EarContent").getAdapter(IContainer.class);
+
+ assertOnlyContainsTheseFiles(onlyInEar, earLibs);
+
+ final IContainer earMeta = (IContainer) ear.findMember("EarContent/META-INF").getAdapter(IContainer.class);
+
+ Set onlyInEarMeta = new HashSet();
+
+ onlyInEarMeta.add("jboss-app.xml");
+ onlyInEarMeta.add("application.xml");
+
+ assertOnlyContainsTheseFiles(onlyInEarMeta, earMeta);
+
+ assertOnlyContainsTheseFiles(onlyInWar, (IContainer)war.findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class));
+
+ IProject ejb = seamProjectsSet.getEjbProject();
+
+ onlyInEjbSrc.add("security.drl");
+ onlyInEjbSrc.add("seam.properties");
+ onlyInEjbSrc.add("import.sql");
+ onlyInEjbSrc.add("components.properties");
+ onlyInEjbSrc.add("META-INF"); // JBIDE-2431: META-INF dir is always created by Seam 2.0 seamgen
+ onlyInEjbSrc.add("org"); // JBIDE-2431: org dir is always created by Seam 2.0 seamgen
+
+ assertOnlyContainsTheseFiles(onlyInEjbSrc, (IContainer)ejb.findMember("ejbModule").getAdapter(IContainer.class));
+ }
+
+
+ /**
+ * Fails if set of fileNames is not found in dir or some other filename is found in dir.
+ * @param fileNames set of strings
+ * @param dir directory to scan
+ * @throws CoreException
+ */
+ protected void assertOnlyContainsTheseFiles(Set<String> fileNames,
+ final IResource dir) throws CoreException {
+
+ final Set<String> foundFiles = new HashSet<String>();
+ dir.accept(new IResourceProxyVisitor() {
+
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ if(dir.getName().equals(proxy.getName())) return true;
+ foundFiles.add(proxy.getName());
+ return false;
+ }
+
+ }, IResource.DEPTH_ZERO);
+
+ if(!foundFiles.containsAll(fileNames)) {
+ fileNames.removeAll(foundFiles);
+ fail("Did not find " + fileNames + " in " + dir);
+ }
+
+ foundFiles.removeAll(fileNames);
+
+ assertTrue("Found additional files (" + foundFiles + " in " + dir + " at " + dir.getLocation(), foundFiles.isEmpty());
+ }
+
+ public void testBootstrapDirPresent() throws CoreException, IOException {
+
+ SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
+
+ IProject testProject = warPs.getTestProject();
+ assertTrue(testProject.exists());
+
+ assertNotNull(testProject.findMember("bootstrap"));
+ assertNotNull(testProject.findMember("bootstrap/data"));
+
+ assertNull("embedded-ejb should not be installed for seam2", testProject.findMember("embedded-ejb"));
+
+ }
+
+ public void testTestLibs() throws CoreException, IOException {
+
+ SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
+
+ IProject testProject = warPs.getTestProject();
+ assertTrue(testProject.exists());
+
+ Set<String> libs = new HashSet<String>();
+ libs.add("testng.jar");
+ libs.add("hibernate-all.jar");
+// libs.add("jboss-deployers.jar"); // JBIDE-2431: There is no such jar created by Seam 2.0 seamgen
+ libs.add("jboss-embedded-all.jar");
+ libs.add("thirdparty-all.jar");
+ libs.add("jboss-embedded-api.jar");
+ libs.add("core.jar");
+
+ assertOnlyContainsTheseFiles(libs, testProject.findMember("lib"));
+
+ // JBIDE-2431: The following block is commented because it duplicates the call to assertOnlyContainsTheseFiles()
+/*
+ assertNotNull(testProject.findMember("lib/testng.jar"));
+ assertNotNull(testProject.findMember("lib/hibernate-all.jar"));
+// assertNotNull(testProject.findMember("lib/jboss-deployers.jar")); // JBIDE-2431: There is no such jar created by Seam 2.0 seamgen
+ assertNotNull(testProject.findMember("lib/jboss-embedded-all.jar"));
+ assertNotNull(testProject.findMember("lib/thirdparty-all.jar"));
+ assertNotNull(testProject.findMember("lib/core.jar")); // JBIDE-2431: lib/core.jar file is always created by Seam 2.0 seamgen
+*/
+ }
+
+ public void testSeamProperties() {
+ SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
+
+ IProject warProject = warPs.getWarProject();
+ assertTrue(warProject.exists());
+
+ assertNotNull(warProject.findMember("src/model/seam.properties"));
+ IResource findMember = warProject.findMember("src/action/seam.properties");
+ assertNotNull(findMember);
+ assertTrue(findMember instanceof IFile);
+
+ }
+
+ public void testJbpmPresent() throws CoreException, IOException {
+
+ SeamProjectsSet earPs = new SeamProjectsSet(earProject.getProject());
+
+ IProject project = earPs.getEarProject();
+ assertTrue(project.exists());
+
+ assertNotNull(project.findMember("EarContent/jbpm-jpdl.jar"));
+
+ }
+
+ public void testDroolsPresent() throws CoreException, IOException {
+
+
+ IProject earRoot = earProject.getProject();
+ SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earRoot);
+
+ // JBIDE-2431: security.drl is always created in <EJBProject>/ejbModule directory by Seam 2.0 seamgen
+ IProject ejbProject = seamProjectsSet.getEjbProject();
+ assertNotNull(ejbProject.findMember("ejbModule/security.drl"));
+
+ }
+
+ public void testCreateEar() throws CoreException, IOException {
+
+
+ }
+
+ @Override
+ protected IProjectFacetVersion getSeamFacetVersion() {
+ return seam2FacetVersion;
+ }
+}
16 years, 3 months
JBoss Tools SVN: r10544 - trunk/vpe/plugins/org.jboss.tools.vpe/resources/meta.
by jbosstools-commits@lists.jboss.org
Author: dgolovin
Date: 2008-09-29 13:43:14 -0400 (Mon, 29 Sep 2008)
New Revision: 10544
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/resources/meta/vpe.meta
Log:
fix class name error
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/resources/meta/vpe.meta
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/resources/meta/vpe.meta 2008-09-29 16:00:28 UTC (rev 10543)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/resources/meta/vpe.meta 2008-09-29 17:43:14 UTC (rev 10544)
@@ -572,7 +572,7 @@
</XActionItem>
<XActionItem kind="list" name="EditActions">
<XActionItem HandlerClassName="%SpecialWizard%" ICON="action.empty"
- PROPERTIES="support=org.jboss.tools.vpe.resref.VpeAddReferencceSupport"
+ PROPERTIES="support=org.jboss.tools.vpe.resref.VpeAddReferenceSupport"
displayName="Edit TLD Reference..." kind="action" name="EditItem">
<EntityData EntityName="VPETLDReferenceExt">
<AttributeData AttributeName="location"/>
16 years, 3 months
JBoss Tools SVN: r10543 - in trunk: seam/plugins/org.jboss.tools.seam.core and 3 other directories.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2008-09-29 12:00:28 -0400 (Mon, 29 Sep 2008)
New Revision: 10543
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam1ProjectCreator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2ProjectCreator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamProjectCreator.java
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2FacetInstallDelegate.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetAbstractInstallDelegate.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegate.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamProjectWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2731 Moved seam test project creation from facet to wizard.
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -67,12 +67,18 @@
}
public static IProject importExistingProject(IProject project, String location, String name) throws CoreException {
+ return importExistingProject(project, location, name, new NullProgressMonitor(), true);
+ }
+
+ public static IProject importExistingProject(IProject project, String location, String name, IProgressMonitor monitor, boolean refreshWorkspace) throws CoreException {
IPath path = new Path(location).append(".project");
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(path);
description.setName(name);
- project.create(description, new NullProgressMonitor());
- project.open(IResource.NONE, new NullProgressMonitor());
- ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ project.create(description, monitor);
+ project.open(IResource.NONE, monitor);
+ if(refreshWorkspace) {
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
return project;
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-09-29 16:00:28 UTC (rev 10543)
@@ -49,40 +49,52 @@
facet="jst.seam"
version="1.2">
<constraint>
- <and>
- <requires
- facet="jst.web"
- version="[2.5">
- </requires>
- <requires
- facet="jst.jsf"
- version="[1.2">
- </requires>
- <requires
- facet="jst.java"
- version="5.0">
- </requires>
- </and>
+ <or>
+ <requires
+ facet="jst.ejb"
+ version="[3.0">
+ </requires>
+ <and>
+ <requires
+ facet="jst.web"
+ version="[2.5">
+ </requires>
+ <requires
+ facet="jst.jsf"
+ version="[1.2">
+ </requires>
+ <requires
+ facet="jst.java"
+ version="5.0">
+ </requires>
+ </and>
+ </or>
</constraint>
</project-facet-version>
<project-facet-version
facet="jst.seam"
version="2.0">
<constraint>
- <and>
- <requires
- facet="jst.web"
- version="[2.5">
- </requires>
- <requires
- facet="jst.jsf"
- version="[1.2">
- </requires>
- <requires
- facet="jst.java"
- version="[5.0">
- </requires>
- </and>
+ <or>
+ <requires
+ facet="jst.ejb"
+ version="[3.0">
+ </requires>
+ <and>
+ <requires
+ facet="jst.web"
+ version="[2.5">
+ </requires>
+ <requires
+ facet="jst.jsf"
+ version="[1.2">
+ </requires>
+ <requires
+ facet="jst.java"
+ version="5.0">
+ </requires>
+ </and>
+ </or>
</constraint>
</project-facet-version>
<action
@@ -176,10 +188,10 @@
<static-preset
id="jst.seam.preset">
<label>Dynamic Web Project with Seam 1.2</label>
- <facet id="jst.java" version="5.0" />
+ <facet id="jst.java" version="5.0"/>
<facet id="jst.web" version="2.5"/>
- <facet id="jst.jsf" version="1.2" />
- <facet id="jst.seam" version="1.2" />
+ <facet id="jst.jsf" version="1.2"/>
+ <facet id="jst.seam" version="1.2"/>
<description>
Configures a Dynamic Web application to use Seam v1.2
</description>
@@ -187,10 +199,10 @@
<static-preset
id="jst.seam2.preset">
<label>Dynamic Web Project with Seam 2.0</label>
- <facet id="jst.java" version="5.0" />
+ <facet id="jst.java" version="5.0"/>
<facet id="jst.web" version="2.5"/>
- <facet id="jst.jsf" version="1.2" />
- <facet id="jst.seam" version="2.0" />
+ <facet id="jst.jsf" version="1.2"/>
+ <facet id="jst.seam" version="2.0"/>
<description>
Configures a Dynamic Web application to use Seam v2.0
</description>
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam1ProjectCreator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam1ProjectCreator.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam1ProjectCreator.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -0,0 +1,115 @@
+ /*******************************************************************************
+ * Copyright (c) 2008 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.project.facet;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.tools.ant.types.FilterSet;
+import org.apache.tools.ant.types.FilterSetCollection;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+
+/**
+ * @author Alexey Kazakov
+ * This class helps New Seam Wizard Page to create EJB, EAR and test projects for seam 1.2 WAR project.
+ */
+public class Seam1ProjectCreator extends SeamProjectCreator {
+
+ protected static AntCopyUtils.FileSet JBOSS_TEST_LIB_FILESET = new AntCopyUtils.FileSet()
+ .include("testng-.*-jdk15\\.jar") //$NON-NLS-1$
+ .include("myfaces-api-.*\\.jar") //$NON-NLS-1$
+ .include("myfaces-impl-.*\\.jar") //$NON-NLS-1$
+ .include("servlet-api\\.jar") //$NON-NLS-1$
+ .include("hibernate-all\\.jar") //$NON-NLS-1$
+ .include("jboss-ejb3-all\\.jar") //$NON-NLS-1$
+ .include("thirdparty-all\\.jar") //$NON-NLS-1$
+ .exclude(".*/CVS") //$NON-NLS-1$
+ .exclude(".*/\\.svn"); //$NON-NLS-1$
+
+ /**
+ * @param model Seam facet data model
+ * @param seamWebProject Seam web project
+ */
+ public Seam1ProjectCreator(IDataModel model, IProject seamWebProject) {
+ super(model, seamWebProject);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.project.facet.SeamProjectCreator#createTestProject()
+ */
+ @Override
+ protected void createTestProject() {
+ File testProjectDir = new File(seamWebProject.getLocation().removeLastSegments(1).toFile(), testProjectName); //$NON-NLS-1$
+ testProjectDir.mkdir();
+
+ IVirtualComponent component = ComponentCore.createComponent(seamWebProject);
+ IVirtualFolder webRootVirtFolder = component.getRootFolder().getFolder(new Path("/")); //$NON-NLS-1$
+
+ File testLibDir = new File(testProjectDir, "lib"); //$NON-NLS-1$
+ File embededEjbDir = new File(testProjectDir, "embedded-ejb"); //$NON-NLS-1$
+ File testSrcDir = new File(testProjectDir, "test-src"); //$NON-NLS-1$
+ FilterSet filterSet = new FilterSet();
+ filterSet.addFilter("projectName", seamWebProject.getName()); //$NON-NLS-1$
+ filterSet.addFilter("runtimeName", WtpUtils.getServerRuntimeName(seamWebProject)); //$NON-NLS-1$
+ filterSet.addFilter("webRootFolder", webRootVirtFolder.getUnderlyingFolder().getFullPath().removeFirstSegments(1).toString()); //$NON-NLS-1$
+
+ AntCopyUtils.FileSet includeLibs = new AntCopyUtils.FileSet(JBOSS_TEST_LIB_FILESET).dir(new File(seamRuntime.getHomeDir(), "lib")); //$NON-NLS-1$
+ File[] libs = includeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(includeLibs));
+ StringBuffer testLibraries = new StringBuffer();
+
+ for (File file : libs) {
+ testLibraries.append("\t<classpathentry kind=\"lib\" path=\"lib/" + file.getName() + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ StringBuffer requiredProjects = new StringBuffer();
+ requiredProjects.append("\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + seamWebProject.getName() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (!SeamFacetAbstractInstallDelegate.isWarConfiguration(model)) {
+ requiredProjects.append("\n\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + ejbProjectName + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ filterSet.addFilter("testLibraries", testLibraries.toString()); //$NON-NLS-1$
+ filterSet.addFilter("requiredProjects", requiredProjects.toString()); //$NON-NLS-1$
+ File testTemplateDir = null;
+ try {
+ testTemplateDir = new File(SeamFacetInstallDataModelProvider.getTemplatesFolder(), "test"); //$NON-NLS-1$
+ } catch (IOException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ return;
+ }
+ AntCopyUtils.FileSet excludeCvsSvn
+ = new AntCopyUtils.FileSet(SeamFacetAbstractInstallDelegate.CVS_SVN).dir(testTemplateDir);
+
+ AntCopyUtils.copyFilesAndFolders(
+ testTemplateDir,
+ testProjectDir,
+ new AntCopyUtils.FileSetFileFilter(excludeCvsSvn),
+ new FilterSetCollection(filterSet), true);
+
+ excludeCvsSvn.dir(new File(seamRuntime.getHomeDir(), "embedded-ejb/conf")); //$NON-NLS-1$
+ AntCopyUtils.copyFiles(
+ new File(seamRuntime.getHomeDir(), "embedded-ejb/conf"), //$NON-NLS-1$
+ embededEjbDir,
+ new AntCopyUtils.FileSetFileFilter(excludeCvsSvn));
+
+ AntCopyUtils.copyFiles(
+ new File(seamRuntime.getHomeDir(), "lib"), //$NON-NLS-1$
+ testLibDir,
+ new AntCopyUtils.FileSetFileFilter(includeLibs));
+
+ SeamFacetAbstractInstallDelegate.createComponentsProperties(testSrcDir, "", Boolean.TRUE); //$NON-NLS-1$
+ }
+}
\ No newline at end of file
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam1ProjectCreator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2FacetInstallDelegate.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2FacetInstallDelegate.java 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2FacetInstallDelegate.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -11,36 +11,29 @@
package org.jboss.tools.seam.internal.core.project.facet;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.util.HashSet;
-import java.util.Properties;
import java.util.Set;
import org.apache.tools.ant.types.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.preferences.IScopeContext;
-import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarAntExporter;
import org.eclipse.jst.common.project.facet.core.ClasspathHelper;
import org.eclipse.jst.javaee.web.WebApp;
import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -50,16 +43,12 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
-import org.osgi.service.prefs.BackingStoreException;
-import org.osgi.service.prefs.Preferences;
// TODO: why not just *one* global filter set to avoid any missing names ? (assert for it in our unittests!
public class Seam2FacetInstallDelegate extends SeamFacetAbstractInstallDelegate{
public static String DEV_WAR_PROFILE = "dev-war"; //$NON-NLS-1$
public static String DEV_EAR_PROFILE = "dev"; //$NON-NLS-1$
- public static String TEST_WAR_PROFILE = "test-war"; //$NON-NLS-1$
- public static String TEST_EAR_PROFILE = "test"; //$NON-NLS-1$
public static AntCopyUtils.FileSet JBOSS_WAR_LIB_FILESET_WAR_CONFIG = new AntCopyUtils.FileSet()
.include("ajax4jsf.*\\.jar") //$NON-NLS-1$
@@ -88,23 +77,6 @@
.include("mvel14.jar") //$NON-NLS-1$
.include("jboss-el.jar"); //$NON-NLS-1$
- // test/*.jar are duplicated here since the filtering seem to be assymetric when matching
- public static AntCopyUtils.FileSet JBOSS_TEST_LIB_FILESET = new AntCopyUtils.FileSet()
- .include("testng\\.jar") //$NON-NLS-1$
- .include("test/hibernate-all\\.jar") //$NON-NLS-1$
- .include("hibernate-all\\.jar") //$NON-NLS-1$
- .include("test/jboss-embedded-all.jar") //$NON-NLS-1$
- .include("jboss-embedded-all.jar") //$NON-NLS-1$
- .include("test/jboss-embedded-api.jar") //$NON-NLS-1$
- .include("jboss-embedded-api.jar") //$NON-NLS-1$
- .include("test/jboss-deployers.jar") //$NON-NLS-1$
- .include("jboss-deployers.jar") //$NON-NLS-1$
- .include("test/thirdparty-all\\.jar") //$NON-NLS-1$
- .include("thirdparty-all\\.jar") //$NON-NLS-1$
- .include("core.jar") //$NON-NLS-1$
- .exclude(".*/CVS") //$NON-NLS-1$
- .exclude(".*/\\.svn"); //$NON-NLS-1$
-
public static AntCopyUtils.FileSet JBOSS_WAR_LIB_FILESET_EAR_CONFIG = new AntCopyUtils.FileSet()
.include("richfaces-impl\\.jar") //$NON-NLS-1$
.include("richfaces-ui\\.jar") //$NON-NLS-1$
@@ -149,13 +121,6 @@
.exclude(".*/CVS") //$NON-NLS-1$
.exclude(".*/\\.svn"); //$NON-NLS-1$
- public static AntCopyUtils.FileSet CVS_SVN = new AntCopyUtils.FileSet()
- .include(".*") //$NON-NLS-1$
- .exclude(".*/CVS") //$NON-NLS-1$
- .exclude("CVS") //$NON-NLS-1$
- .exclude(".*\\.svn") //$NON-NLS-1$
- .exclude(".*/\\.svn"); //$NON-NLS-1$
-
public static AntCopyUtils.FileSet JBOOS_WAR_WEBINF_SET = new AntCopyUtils.FileSet()
.include("WEB-INF") //$NON-NLS-1$
//.include("WEB-INF/web\\.xml") //$NON-NLS-1$
@@ -184,6 +149,8 @@
public void doExecute(final IProject project, IProjectFacetVersion fv,
Object config, IProgressMonitor monitor) throws CoreException {
final IDataModel model = (IDataModel)config;
+ IFacetedProjectWorkingCopy fc = (IFacetedProjectWorkingCopy)model.getProperty(IFacetDataModelProperties.FACETED_PROJECT_WORKING_COPY);
+ Set<IProjectFacetVersion> fvd = fc.getProjectFacets();
// get WebContents folder path from DWP model
IVirtualComponent component = ComponentCore.createComponent(project);
@@ -192,7 +159,6 @@
IContainer webRootFolder = webRootVirtFolder.getUnderlyingFolder();
model.setProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME, project.getName());
- model.setProperty(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, project.getName()+"-test"); //$NON-NLS-1$
Boolean dbExists = (Boolean)model.getProperty(ISeamFacetDataModelProperties.DB_ALREADY_EXISTS);
Boolean dbRecreate = (Boolean)model.getProperty(ISeamFacetDataModelProperties.RECREATE_TABLES_AND_DATA_ON_DEPLOY);
@@ -276,7 +242,7 @@
hibernateDialectFilterSet.addFilterSet(projectFilterSet);
hibernateDialectFilterSet.addFilterSet(SeamFacetFilterSetFactory.createHibernateDialectFilterSet(model));
- createTestProject(model,project,selectedRuntime);
+// createTestProject(model,project,selectedRuntime);
// ********************************************************************************************
// Handle WAR/EAR configurations
@@ -502,157 +468,22 @@
if(!isWarConfiguration(model)) {
IProject ejbProjectToBeImported = wsRoot.getProject(project.getName()+"-ejb");
- ResourcesUtils.importExistingProject(ejbProjectToBeImported, wsPath+"/"+project.getName()+"-ejb", project.getName()+"-ejb");
+ ResourcesUtils.importExistingProject(ejbProjectToBeImported, wsPath+"/"+project.getName()+"-ejb", project.getName()+"-ejb", monitor, false);
toggleHibernateOnProject(ejbProjectToBeImported, consoleName);
IProjectFacet sf = ProjectFacetsManager.getProjectFacet("jst.ejb");
IProjectFacetVersion pfv = ProjectFacetsManager.create(ejbProjectToBeImported).getInstalledVersion(sf);
ClasspathHelper.addClasspathEntries(ejbProjectToBeImported, pfv);
IProject earProjectToBeImported = wsRoot.getProject(project.getName()+"-ear");
- ResourcesUtils.importExistingProject(earProjectToBeImported, wsPath+"/"+project.getName()+"-ear", project.getName()+"-ear");
+ ResourcesUtils.importExistingProject(earProjectToBeImported, wsPath+"/"+project.getName()+"-ear", project.getName()+"-ear", monitor, false);
}
-
- IProject testProjectToBeImported = wsRoot.getProject(project.getName()+"-test");
- ResourcesUtils.importExistingProject(testProjectToBeImported, wsPath+"/"+project.getName()+"-test", project.getName()+"-test");
- toggleHibernateOnProject(testProjectToBeImported, consoleName);
}
- public static boolean isWarConfiguration(IDataModel model) {
- return "war".equals(model.getProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS)); //$NON-NLS-1$
- }
-
- private void createTestProject(IDataModel model, IProject seamWebProject, SeamRuntime seamRuntime) {
- String projectName = model.getProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME).toString();
- File testProjectDir = new File(seamWebProject.getLocation().removeLastSegments(1).toFile(),projectName+"-test"); //$NON-NLS-1$
- testProjectDir.mkdir();
-
- IVirtualComponent component = ComponentCore.createComponent(seamWebProject);
- IVirtualFolder webRootVirtFolder = component.getRootFolder().getFolder(new Path("/")); //$NON-NLS-1$
-
- File testLibDir = new File(testProjectDir,"lib"); //$NON-NLS-1$
- File embededEjbDir = new File(testProjectDir,"bootstrap"); //$NON-NLS-1$
- File testSrcDir = new File(testProjectDir,"test-src"); //$NON-NLS-1$
- String seamGenResFolder = seamRuntime.getResourceTemplatesDir();
- File persistenceFile = new File(seamGenResFolder ,"META-INF/persistence-" + (isWarConfiguration(model)?TEST_WAR_PROFILE:TEST_EAR_PROFILE) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
- File dataSourceFile = new File(seamGenResFolder, "datasource-ds.xml");
- File seamPropertiesFile = new File(seamGenResFolder, "seam.properties");
- //File jbossBeansFile = new File(seamGenResFolder ,"META-INF/jboss-beans.xml"); //$NON-NLS-1$
- FilterSet filterSet = new FilterSet();
- filterSet.addFilter("projectName", projectName); //$NON-NLS-1$
- filterSet.addFilter("runtimeName", WtpUtils.getServerRuntimeName(seamWebProject)); //$NON-NLS-1$
- filterSet.addFilter("webRootFolder",webRootVirtFolder.getUnderlyingFolder().getFullPath().removeFirstSegments(1).toString()); //$NON-NLS-1$
-
- FilterSet jdbcFilterSet = SeamFacetFilterSetFactory.createJdbcFilterSet(model);
- // TODO: why are these filters not shared!?
- filterSet.addConfiguredFilterSet(SeamFacetFilterSetFactory.createHibernateDialectFilterSet(model));
-
- final SeamRuntime selectedRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(model.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString());
- final String seamHomePath = selectedRuntime.getHomeDir();
-
- AntCopyUtils.FileSet includeLibs
- = new AntCopyUtils.FileSet(JBOSS_TEST_LIB_FILESET)
- .dir(new File(seamRuntime.getHomeDir(),"lib")); //$NON-NLS-1$
- AntCopyUtils.FileSet secondSetincludeLibs
- = new AntCopyUtils.FileSet(JBOSS_TEST_LIB_FILESET)
- .dir(new File(seamRuntime.getHomeDir(),"lib/test")); //$NON-NLS-1$
-
- File[] firstlibs = includeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(includeLibs));
- File[] secondLibs = secondSetincludeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(secondSetincludeLibs));
- Set<String> allLibs = new HashSet<String>(); // HACK: needed to be unique because some jboss-*.jars are duplicated
- for(File f : firstlibs) {
- allLibs.add(f.getName());
- }
- for(File f : secondLibs) {
- allLibs.add(f.getName());
- }
-
- StringBuffer testLibraries = new StringBuffer();
-
- for (String file : allLibs) {
- testLibraries.append("\t<classpathentry kind=\"lib\" path=\"lib/" + file + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- StringBuffer requiredProjects = new StringBuffer();
- requiredProjects.append(
- "\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + seamWebProject.getName() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
- if(!isWarConfiguration(model)) {
- requiredProjects.append(
- "\n\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + seamWebProject.getName() + "-ejb\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- filterSet.addFilter("testLibraries",testLibraries.toString()); //$NON-NLS-1$
- filterSet.addFilter("requiredProjects",requiredProjects.toString()); //$NON-NLS-1$
- File testTemplateDir = null;
- try {
- testTemplateDir = new File(SeamFacetInstallDataModelProvider.getTemplatesFolder(),"test-seam2"); //$NON-NLS-1$
- } catch (IOException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
- AntCopyUtils.FileSet excludeCvsSvn
- = new AntCopyUtils.FileSet(CVS_SVN).dir(testTemplateDir);
-
- AntCopyUtils.copyFilesAndFolders(
- testTemplateDir,
- testProjectDir,
- new AntCopyUtils.FileSetFileFilter(excludeCvsSvn),
- new FilterSetCollection(filterSet), true);
-
- excludeCvsSvn.dir(new File(seamRuntime.getHomeDir(),"bootstrap")); //$NON-NLS-1$
- AntCopyUtils.copyFilesAndFolders(
- new File(seamRuntime.getHomeDir(),"bootstrap"), //$NON-NLS-1$
- embededEjbDir,
- new AntCopyUtils.FileSetFileFilter(excludeCvsSvn), new FilterSetCollection(), true);
-
-// AntCopyUtils.copyFileToFile(
-// persistenceFile,
-// new File(testProjectDir,"test-src/META-INF/persistence.xml"), //$NON-NLS-1$
-// new FilterSetCollection(filterSet), true);
-
- FilterSetCollection f = new FilterSetCollection();
- f.addFilterSet(filterSet);
- f.addFilterSet(jdbcFilterSet);
-
- AntCopyUtils.copyFileToFile(
- dataSourceFile,
- new File(testProjectDir,"test-src/META-INF/"+seamWebProject.getName()+"-test-ds.xml"), //$NON-NLS-1$
- f, true);
-
- AntCopyUtils.copyFileToFolder(
- seamPropertiesFile,
- testSrcDir, //$NON-NLS-1$
- new FilterSetCollection(filterSet), true);
-
- AntCopyUtils.copyFiles(
- new File(seamRuntime.getHomeDir(),"lib"), //$NON-NLS-1$
- testLibDir,
- new AntCopyUtils.FileSetFileFilter(includeLibs));
-
- //seam2 has a lib/test
- AntCopyUtils.copyFiles(
- new File(seamRuntime.getHomeDir(),"lib/test"), //$NON-NLS-1$
- testLibDir,
- new AntCopyUtils.FileSetFileFilter(includeLibs));
-
- createComponentsProperties(testSrcDir, "", true); //$NON-NLS-1$
- }
-
- /**
- * @param seamGenResFolder
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.project.facet.SeamFacetAbstractInstallDelegate#configure(org.eclipse.jst.javaee.web.WebApp)
*/
- private void createComponentsProperties(final File seamGenResFolder, String projectName, boolean embedded) {
- Properties components = new Properties();
- String prefix = "".equals(projectName)?"":projectName+"/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- components.setProperty("embeddedEjb", ""+embedded); //$NON-NLS-1$
- components.setProperty("jndiPattern", prefix+"#{ejbName}/local"); //$NON-NLS-1$ //$NON-NLS-2$
- File componentsProps = new File(seamGenResFolder,"components.properties"); //$NON-NLS-1$
- try {
- componentsProps.createNewFile();
- components.store(new FileOutputStream(componentsProps), ""); //$NON-NLS-1$
- } catch (IOException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- }
-
+ @Override
protected void configure(WebApp webApp) {
// Ajax4jsf
createOrUpdateContextParam(webApp, ORG_RICHFACES_SKIN,
@@ -682,56 +513,4 @@
// Security
addSecurityConstraint(webApp);
}
-
- public static boolean toggleHibernateOnProject(IProject project, String defaultConsoleName) {
- IScopeContext scope = new ProjectScope(project);
-
- Preferences node = scope.getNode("org.hibernate.eclipse.console");
-
- if(node!=null) {
- node.putBoolean("hibernate3.enabled", true );
- node.put("default.configuration", defaultConsoleName );
- try {
- node.flush();
- } catch (BackingStoreException e) {
- SeamCorePlugin.getDefault().logError("Could not save changes to preferences", e);
- return false;
- }
- } else {
- return false;
- }
-
- try {
- addProjectNature(project, "org.hibernate.eclipse.console.hibernateNature", new NullProgressMonitor() );
- return true;
- } catch(CoreException ce) {
- SeamCorePlugin.getDefault().logError("Could not activate Hibernate nature on project " + project.getName(), ce);
- return false;
- }
- }
-
- /**
- * Add the given project nature to the given project (if it isn't already added).
- * @return true if nature where added, false if not
- * @throws OperationCanceledException if job were cancelled or CoreException if something went wrong.
- */
- public static boolean addProjectNature(IProject project, String nature, IProgressMonitor monitor) throws CoreException {
- if (monitor != null && monitor.isCanceled() ) {
- throw new OperationCanceledException();
- }
-
- if (!project.hasNature(nature) ) {
- IProjectDescription description = project.getDescription();
- String[] prevNatures= description.getNatureIds();
- String[] newNatures= new String[prevNatures.length + 1];
- System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
- newNatures[prevNatures.length]= nature;
- description.setNatureIds(newNatures);
- project.setDescription(description, monitor);
- return true;
- } else {
- monitor.worked(1);
- return false;
- }
- }
}
\ No newline at end of file
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2ProjectCreator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2ProjectCreator.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2ProjectCreator.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -0,0 +1,164 @@
+ /*******************************************************************************
+ * Copyright (c) 2008 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.project.facet;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.tools.ant.types.FilterSet;
+import org.apache.tools.ant.types.FilterSetCollection;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+
+/**
+ * @author Alexey Kazakov
+ * This class helps New Seam Wizard Page to create EJB, EAR and test projects for seam 2.* WAR project.
+ */
+public class Seam2ProjectCreator extends SeamProjectCreator {
+
+ // test/*.jar are duplicated here since the filtering seem to be assymetric when matching
+ protected static AntCopyUtils.FileSet JBOSS_TEST_LIB_FILESET = new AntCopyUtils.FileSet()
+ .include("testng\\.jar") //$NON-NLS-1$
+ .include("test/hibernate-all\\.jar") //$NON-NLS-1$
+ .include("hibernate-all\\.jar") //$NON-NLS-1$
+ .include("test/jboss-embedded-all.jar") //$NON-NLS-1$
+ .include("jboss-embedded-all.jar") //$NON-NLS-1$
+ .include("test/jboss-embedded-api.jar") //$NON-NLS-1$
+ .include("jboss-embedded-api.jar") //$NON-NLS-1$
+ .include("test/jboss-deployers.jar") //$NON-NLS-1$
+ .include("jboss-deployers.jar") //$NON-NLS-1$
+ .include("test/thirdparty-all\\.jar") //$NON-NLS-1$
+ .include("thirdparty-all\\.jar") //$NON-NLS-1$
+ .include("core.jar") //$NON-NLS-1$
+ .exclude(".*/CVS") //$NON-NLS-1$
+ .exclude(".*/\\.svn"); //$NON-NLS-1$
+
+ /**
+ * @param model Seam facet data model
+ * @param seamWebProject Seam web project
+ */
+ public Seam2ProjectCreator(IDataModel model, IProject seamWebProject) {
+ super(model, seamWebProject);
+ }
+
+ @Override
+ protected void createTestProject() {
+ File testProjectDir = new File(seamWebProject.getLocation().removeLastSegments(1).toFile(), testProjectName); //$NON-NLS-1$
+ testProjectDir.mkdir();
+
+ IVirtualComponent component = ComponentCore.createComponent(seamWebProject);
+ IVirtualFolder webRootVirtFolder = component.getRootFolder().getFolder(new Path("/")); //$NON-NLS-1$
+
+ File testLibDir = new File(testProjectDir,"lib"); //$NON-NLS-1$
+ File embededEjbDir = new File(testProjectDir,"bootstrap"); //$NON-NLS-1$
+ File testSrcDir = new File(testProjectDir,"test-src"); //$NON-NLS-1$
+ String seamGenResFolder = seamRuntime.getResourceTemplatesDir();
+ File dataSourceFile = new File(seamGenResFolder, "datasource-ds.xml");
+ File seamPropertiesFile = new File(seamGenResFolder, "seam.properties");
+ //File jbossBeansFile = new File(seamGenResFolder ,"META-INF/jboss-beans.xml"); //$NON-NLS-1$
+ FilterSet filterSet = new FilterSet();
+ filterSet.addFilter("projectName", seamWebProject.getName()); //$NON-NLS-1$
+ filterSet.addFilter("runtimeName", WtpUtils.getServerRuntimeName(seamWebProject)); //$NON-NLS-1$
+ filterSet.addFilter("webRootFolder",webRootVirtFolder.getUnderlyingFolder().getFullPath().removeFirstSegments(1).toString()); //$NON-NLS-1$
+
+ FilterSet jdbcFilterSet = SeamFacetFilterSetFactory.createJdbcFilterSet(model);
+ // TODO: why are these filters not shared!?
+ filterSet.addConfiguredFilterSet(SeamFacetFilterSetFactory.createHibernateDialectFilterSet(model));
+
+ AntCopyUtils.FileSet includeLibs = new AntCopyUtils.FileSet(JBOSS_TEST_LIB_FILESET).dir(new File(seamRuntime.getHomeDir(),"lib")); //$NON-NLS-1$
+ AntCopyUtils.FileSet secondSetincludeLibs = new AntCopyUtils.FileSet(JBOSS_TEST_LIB_FILESET).dir(new File(seamRuntime.getHomeDir(),"lib/test")); //$NON-NLS-1$
+
+ File[] firstlibs = includeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(includeLibs));
+ File[] secondLibs = secondSetincludeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(secondSetincludeLibs));
+ Set<String> allLibs = new HashSet<String>(); // HACK: needed to be unique because some jboss-*.jars are duplicated
+ for(File f : firstlibs) {
+ allLibs.add(f.getName());
+ }
+ for(File f : secondLibs) {
+ allLibs.add(f.getName());
+ }
+
+ StringBuffer testLibraries = new StringBuffer();
+
+ for (String file : allLibs) {
+ testLibraries.append("\t<classpathentry kind=\"lib\" path=\"lib/" + file + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ StringBuffer requiredProjects = new StringBuffer();
+ requiredProjects.append(
+ "\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + seamWebProject.getName() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
+ if(!SeamFacetAbstractInstallDelegate.isWarConfiguration(model)) {
+ requiredProjects.append("\n\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + ejbProjectName + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ filterSet.addFilter("testLibraries",testLibraries.toString()); //$NON-NLS-1$
+ filterSet.addFilter("requiredProjects",requiredProjects.toString()); //$NON-NLS-1$
+ File testTemplateDir = null;
+ try {
+ testTemplateDir = new File(SeamFacetInstallDataModelProvider.getTemplatesFolder(), "test-seam2"); //$NON-NLS-1$
+ } catch (IOException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ return;
+ }
+ AntCopyUtils.FileSet excludeCvsSvn
+ = new AntCopyUtils.FileSet(SeamFacetAbstractInstallDelegate.CVS_SVN).dir(testTemplateDir);
+
+ AntCopyUtils.copyFilesAndFolders(
+ testTemplateDir,
+ testProjectDir,
+ new AntCopyUtils.FileSetFileFilter(excludeCvsSvn),
+ new FilterSetCollection(filterSet), true);
+
+ excludeCvsSvn.dir(new File(seamRuntime.getHomeDir(), "bootstrap")); //$NON-NLS-1$
+ AntCopyUtils.copyFilesAndFolders(
+ new File(seamRuntime.getHomeDir(), "bootstrap"), //$NON-NLS-1$
+ embededEjbDir,
+ new AntCopyUtils.FileSetFileFilter(excludeCvsSvn), new FilterSetCollection(), true);
+
+// AntCopyUtils.copyFileToFile(
+// persistenceFile,
+// new File(testProjectDir,"test-src/META-INF/persistence.xml"), //$NON-NLS-1$
+// new FilterSetCollection(filterSet), true);
+
+ FilterSetCollection f = new FilterSetCollection();
+ f.addFilterSet(filterSet);
+ f.addFilterSet(jdbcFilterSet);
+
+ AntCopyUtils.copyFileToFile(
+ dataSourceFile,
+ new File(testProjectDir, "test-src/META-INF/"+seamWebProject.getName() + "-test-ds.xml"), //$NON-NLS-1$
+ f, true);
+
+ AntCopyUtils.copyFileToFolder(
+ seamPropertiesFile,
+ testSrcDir, //$NON-NLS-1$
+ new FilterSetCollection(filterSet), true);
+
+ AntCopyUtils.copyFiles(
+ new File(seamRuntime.getHomeDir(), "lib"), //$NON-NLS-1$
+ testLibDir,
+ new AntCopyUtils.FileSetFileFilter(includeLibs));
+
+ //seam2 has a lib/test
+ AntCopyUtils.copyFiles(
+ new File(seamRuntime.getHomeDir(), "lib/test"), //$NON-NLS-1$
+ testLibDir,
+ new AntCopyUtils.FileSetFileFilter(includeLibs));
+
+ SeamFacetAbstractInstallDelegate.createComponentsProperties(testSrcDir, "", true); //$NON-NLS-1$
+ }
+}
\ No newline at end of file
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/Seam2ProjectCreator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetAbstractInstallDelegate.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetAbstractInstallDelegate.java 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetAbstractInstallDelegate.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -10,17 +10,24 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core.project.facet;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -52,6 +59,7 @@
import org.jboss.tools.seam.core.SeamCoreMessages;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
/**
*
@@ -77,6 +85,13 @@
public static String XHTML = "XHTML";
public static String WEB_RESOURCE_COLLECTION_PATTERN = "*.xhtml";
+ static AntCopyUtils.FileSet CVS_SVN = new AntCopyUtils.FileSet()
+ .include(".*") //$NON-NLS-1$
+ .exclude(".*/CVS") //$NON-NLS-1$
+ .exclude("CVS") //$NON-NLS-1$
+ .exclude(".*\\.svn") //$NON-NLS-1$
+ .exclude(".*/\\.svn"); //$NON-NLS-1$
+
/* (non-Javadoc)
* @see org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse.core.resources.IProject, org.eclipse.wst.common.project.facet.core.IProjectFacetVersion, java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
*/
@@ -106,9 +121,88 @@
}
}
+ public static boolean toggleHibernateOnProject(IProject project, String defaultConsoleName) {
+ IScopeContext scope = new ProjectScope(project);
+
+ Preferences node = scope.getNode("org.hibernate.eclipse.console");
+
+ if(node!=null) {
+ node.putBoolean("hibernate3.enabled", true );
+ node.put("default.configuration", defaultConsoleName );
+ try {
+ node.flush();
+ } catch (BackingStoreException e) {
+ SeamCorePlugin.getDefault().logError("Could not save changes to preferences", e);
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ try {
+ addProjectNature(project, "org.hibernate.eclipse.console.hibernateNature", new NullProgressMonitor() );
+ return true;
+ } catch(CoreException ce) {
+ SeamCorePlugin.getDefault().logError("Could not activate Hibernate nature on project " + project.getName(), ce);
+ return false;
+ }
+ }
+
/**
+ * Add the given project nature to the given project (if it isn't already added).
*
* @param project
+ * @param nature
+ * @param monitor
+ * @return true if nature where added, false if not
+ * @throws OperationCanceledException if job were canceled or CoreException if something went wrong.
+ */
+ public static boolean addProjectNature(IProject project, String nature, IProgressMonitor monitor) throws CoreException {
+ if (monitor != null && monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+
+ if (!project.hasNature(nature)) {
+ IProjectDescription description = project.getDescription();
+ String[] prevNatures = description.getNatureIds();
+ String[] newNatures = new String[prevNatures.length + 1];
+ System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+ newNatures[prevNatures.length] = nature;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, monitor);
+ return true;
+ } else {
+ monitor.worked(1);
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @param model
+ * @return
+ */
+ static boolean isWarConfiguration(IDataModel model) {
+ return "war".equals(model.getProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS)); //$NON-NLS-1$
+ }
+
+ static void createComponentsProperties(final File seamGenResFolder, String projectName, Boolean embedded) {
+ Properties components = new Properties();
+ String prefix = "".equals(projectName) ? "" : projectName + "/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ components.put("embeddedEjb", embedded.toString()); //$NON-NLS-1$
+ components.put("jndiPattern", prefix + "#{ejbName}/local"); //$NON-NLS-1$ //$NON-NLS-2$
+ File componentsProps = new File(seamGenResFolder, "components.properties"); //$NON-NLS-1$
+ try {
+ componentsProps.createNewFile();
+ components.store(new FileOutputStream(componentsProps), ""); //$NON-NLS-1$
+ } catch (IOException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ }
+
+ /**
+ *
+ * @param project
* @param fv
* @param config
* @param monitor
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegate.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegate.java 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegate.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -14,31 +14,24 @@
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.util.List;
import java.util.Properties;
import org.apache.tools.ant.types.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jst.common.project.facet.core.ClasspathHelper;
import org.eclipse.jst.javaee.core.DisplayName;
import org.eclipse.jst.javaee.core.JavaeeFactory;
import org.eclipse.jst.javaee.web.Filter;
import org.eclipse.jst.javaee.web.WebApp;
-import org.eclipse.jst.javaee.web.WebFactory;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
@@ -52,8 +45,6 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
-import org.osgi.service.prefs.BackingStoreException;
-import org.osgi.service.prefs.Preferences;
/**
* Install delegate for seam faset version 1.2
@@ -85,16 +76,6 @@
/**
*
*/
- public static final String TEST_WAR_PROFILE = "test-war"; //$NON-NLS-1$
-
- /**
- *
- */
- public static final String TEST_EAR_PROFILE = "test"; //$NON-NLS-1$
-
- /**
- *
- */
public static final AntCopyUtils.FileSet JBOSS_WAR_LIB_FILESET_WAR_CONFIG = new AntCopyUtils.FileSet()
.include("ajax4jsf.*\\.jar") //$NON-NLS-1$
.include("richfaces.*\\.jar") //$NON-NLS-1$
@@ -136,20 +117,6 @@
/**
*
*/
- public static AntCopyUtils.FileSet JBOSS_TEST_LIB_FILESET = new AntCopyUtils.FileSet()
- .include("testng-.*-jdk15\\.jar") //$NON-NLS-1$
- .include("myfaces-api-.*\\.jar") //$NON-NLS-1$
- .include("myfaces-impl-.*\\.jar") //$NON-NLS-1$
- .include("servlet-api\\.jar") //$NON-NLS-1$
- .include("hibernate-all\\.jar") //$NON-NLS-1$
- .include("jboss-ejb3-all\\.jar") //$NON-NLS-1$
- .include("thirdparty-all\\.jar") //$NON-NLS-1$
- .exclude(".*/CVS") //$NON-NLS-1$
- .exclude(".*/\\.svn"); //$NON-NLS-1$
-
- /**
- *
- */
public static AntCopyUtils.FileSet JBOSS_WAR_LIB_FILESET_EAR_CONFIG = new AntCopyUtils.FileSet()
.include("ajax4jsf.*\\.jar") //$NON-NLS-1$
.include("richfaces.*\\.jar") //$NON-NLS-1$
@@ -211,16 +178,6 @@
/**
*
*/
- public static AntCopyUtils.FileSet CVS_SVN = new AntCopyUtils.FileSet()
- .include(".*") //$NON-NLS-1$
- .exclude(".*/CVS") //$NON-NLS-1$
- .exclude("CVS") //$NON-NLS-1$
- .exclude(".*\\.svn") //$NON-NLS-1$
- .exclude(".*/\\.svn"); //$NON-NLS-1$
-
- /**
- *
- */
public static AntCopyUtils.FileSet JBOOS_WAR_WEBINF_SET = new AntCopyUtils.FileSet()
.include("WEB-INF") //$NON-NLS-1$
//.include("WEB-INF/web\\.xml") //$NON-NLS-1$
@@ -267,12 +224,8 @@
*/
public static String WEB_LIBRARIES_RELATED_PATH = "WEB-INF/lib"; //$NON-NLS-1$
- /**
- *
- */
- public void doExecute(final IProject project, IProjectFacetVersion fv,
- Object config, IProgressMonitor monitor) throws CoreException {
- final IDataModel model = (IDataModel)config;
+ private void doExecuteForWar(final IProject project, IProjectFacetVersion fv,
+ IDataModel model, IProgressMonitor monitor) throws CoreException {
// get WebContents folder path from DWP model
IVirtualComponent component = ComponentCore.createComponent(project);
@@ -281,7 +234,6 @@
IContainer webRootFolder = webRootVirtFolder.getUnderlyingFolder();
model.setProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME, project.getName());
- model.setProperty(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, project.getName() + "-test"); //$NON-NLS-1$
Boolean dbExists = (Boolean) model.getProperty(ISeamFacetDataModelProperties.DB_ALREADY_EXISTS);
Boolean dbRecreate = (Boolean) model.getProperty(ISeamFacetDataModelProperties.RECREATE_TABLES_AND_DATA_ON_DEPLOY);
@@ -310,7 +262,6 @@
final File seamHomeFolder = new File(seamHomePath);
final File seamLibFolder = new File(seamHomePath, SEAM_LIB_RELATED_PATH);
final File seamGenResFolder = new File(seamHomePath, "seam-gen/resources"); //$NON-NLS-1$
- final File seamGenResMetainfFolder = new File(seamGenResFolder, "META-INF"); //$NON-NLS-1$
final File droolsLibFolder = new File(seamHomePath, DROOLS_LIB_SEAM_RELATED_PATH);
final File seamGenHomeFolder = new File(seamHomePath, "seam-gen"); //$NON-NLS-1$
@@ -323,8 +274,6 @@
//final File hibernateConsolePref = new File(seamGenHomeFolder, "hibernatetools/.settings/org.hibernate.eclipse.console.prefs"); //$NON-NLS-1$
final File persistenceFile = new File(seamGenResFolder, "META-INF/persistence-" + (isWarConfiguration(model) ? DEV_WAR_PROFILE : DEV_EAR_PROFILE) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
- final File applicationFile = new File(seamGenResFolder, "META-INF/application.xml"); //$NON-NLS-1$
-
final FilterSet jdbcFilterSet = SeamFacetFilterSetFactory.createJdbcFilterSet(model);
final FilterSet projectFilterSet = SeamFacetFilterSetFactory.createProjectFilterSet(model);
final FilterSet filtersFilterSet = SeamFacetFilterSetFactory.createFiltersFilterSet(model);
@@ -350,7 +299,7 @@
AntCopyUtils.FileSet webInfSet = new AntCopyUtils.FileSet(JBOOS_WAR_WEBINF_SET).dir(seamGenResFolder);
configureWebXml(project);
-
+
AntCopyUtils.copyFileToFile(
componentsFile,
new File(webInfFolder, "components.xml"), //$NON-NLS-1$
@@ -364,7 +313,7 @@
hibernateDialectFilterSet.addFilterSet(projectFilterSet);
hibernateDialectFilterSet.addFilterSet(SeamFacetFilterSetFactory.createHibernateDialectFilterSet(model));
- createTestProject(model, project, selectedRuntime);
+// createTestProject(model, project, selectedRuntime);
// ********************************************************************************************
// Handle WAR/EAR configurations
@@ -389,7 +338,7 @@
// ********************************************************************************************
// Copy seam project indicator
// ********************************************************************************************
-
+
final IContainer source = srcRootFolder.getUnderlyingFolder();
IPath actionSrcPath = new Path(source.getFullPath().removeFirstSegments(1) + "/action"); //$NON-NLS-1$
@@ -403,9 +352,9 @@
srcRootFolder.createLink(modelSrcPath, 0, null);
File actionsSrc = new File(project.getLocation().toFile(), source.getFullPath().removeFirstSegments(1) + "/action/");
-
+
//AntCopyUtils.copyFileToFolder(new File(seamGenResFolder, "seam.properties"), actionsSrc, true); //$NON-NLS-1$
-
+
AntCopyUtils.copyFileToFile(
new File(seamGenHomeFolder, "src/Authenticator.java"), //$NON-NLS-1$
new File(actionsSrc,model.getProperty(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME).toString().replace('.', '/') + "/" + "Authenticator.java"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -458,7 +407,7 @@
} else {
filterSet.addFilter("driverJar", ""); //$NON-NLS-1$ //$NON-NLS-2$
}
-
+
File ejbTemplateDir = new File(SeamFacetInstallDataModelProvider.getTemplatesFolder(),"ejb");
AntCopyUtils.FileSet excludeCvsSvn = new AntCopyUtils.FileSet(CVS_SVN).dir(ejbTemplateDir);
@@ -582,183 +531,32 @@
if (!isWarConfiguration(model)) {
IProject ejbProjectToBeImported = wsRoot.getProject(project.getName() + "-ejb");
- ResourcesUtils.importExistingProject(ejbProjectToBeImported, wsPath + "/" + project.getName() + "-ejb", project.getName() + "-ejb");
+ ResourcesUtils.importExistingProject(ejbProjectToBeImported, wsPath + "/" + project.getName() + "-ejb", project.getName() + "-ejb", monitor, false);
toggleHibernateOnProject(ejbProjectToBeImported, consoleName);
IProjectFacet sf = ProjectFacetsManager.getProjectFacet("jst.ejb");
IProjectFacetVersion pfv = ProjectFacetsManager.create(ejbProjectToBeImported).getInstalledVersion(sf);
ClasspathHelper.addClasspathEntries(ejbProjectToBeImported, pfv);
IProject earProjectToBeImported = wsRoot.getProject(project.getName() + "-ear");
- ResourcesUtils.importExistingProject(earProjectToBeImported, wsPath + "/" + project.getName() + "-ear", project.getName() + "-ear");
+ ResourcesUtils.importExistingProject(earProjectToBeImported, wsPath + "/" + project.getName() + "-ear", project.getName() + "-ear", monitor, false);
}
-
- IProject testProjectToBeImported = wsRoot.getProject(project.getName() + "-test");
- ResourcesUtils.importExistingProject(testProjectToBeImported, wsPath + "/" + project.getName() + "-test", project.getName() + "-test");
- toggleHibernateOnProject(testProjectToBeImported, consoleName);
}
- /**
- *
- * @param model
- * @return
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.project.facet.SeamFacetAbstractInstallDelegate#doExecute(org.eclipse.core.resources.IProject, org.eclipse.wst.common.project.facet.core.IProjectFacetVersion, java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
*/
- public static boolean isWarConfiguration(IDataModel model) {
- return "war".equals(model.getProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS)); //$NON-NLS-1$
- }
+ public void doExecute(final IProject project, IProjectFacetVersion fv,
+ Object config, IProgressMonitor monitor) throws CoreException {
+ final IDataModel model = (IDataModel)config;
- private void createTestProject(IDataModel model, IProject seamWebProject, SeamRuntime seamRuntime) {
- String projectName = model.getProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME).toString();
- File testProjectDir = new File(seamWebProject.getLocation().removeLastSegments(1).toFile(), projectName + "-test"); //$NON-NLS-1$
- testProjectDir.mkdir();
-
- IVirtualComponent component = ComponentCore.createComponent(seamWebProject);
- IVirtualFolder webRootVirtFolder = component.getRootFolder().getFolder(new Path("/")); //$NON-NLS-1$
-
- File testLibDir = new File(testProjectDir, "lib"); //$NON-NLS-1$
- File embededEjbDir = new File(testProjectDir, "embedded-ejb"); //$NON-NLS-1$
- File testSrcDir = new File(testProjectDir, "test-src"); //$NON-NLS-1$
- String seamGenResFolder = seamRuntime.getResourceTemplatesDir();
- File persistenceFile = new File(seamGenResFolder , "META-INF/persistence-" + (isWarConfiguration(model) ? TEST_WAR_PROFILE:TEST_EAR_PROFILE) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
- File jbossBeansFile = new File(seamGenResFolder , "META-INF/jboss-beans.xml"); //$NON-NLS-1$
- FilterSet filterSet = new FilterSet();
- filterSet.addFilter("projectName", projectName); //$NON-NLS-1$
- filterSet.addFilter("runtimeName", WtpUtils.getServerRuntimeName(seamWebProject)); //$NON-NLS-1$
- filterSet.addFilter("webRootFolder", webRootVirtFolder.getUnderlyingFolder().getFullPath().removeFirstSegments(1).toString()); //$NON-NLS-1$
-
- final SeamRuntime selectedRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(model.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString());
- final String seamHomePath = selectedRuntime.getHomeDir();
-
- AntCopyUtils.FileSet includeLibs
- = new AntCopyUtils.FileSet(JBOSS_TEST_LIB_FILESET)
- .dir(new File(seamRuntime.getHomeDir(), "lib")); //$NON-NLS-1$
- File[] libs = includeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(includeLibs));
- StringBuffer testLibraries = new StringBuffer();
-
- for (File file : libs) {
- testLibraries.append("\t<classpathentry kind=\"lib\" path=\"lib/" + file.getName() + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- StringBuffer requiredProjects = new StringBuffer();
- requiredProjects.append(
- "\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + seamWebProject.getName() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
- if (!isWarConfiguration(model)) {
- requiredProjects.append(
- "\n\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/" + seamWebProject.getName() + "-ejb\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- filterSet.addFilter("testLibraries", testLibraries.toString()); //$NON-NLS-1$
- filterSet.addFilter("requiredProjects", requiredProjects.toString()); //$NON-NLS-1$
- File testTemplateDir = null;
- try {
- testTemplateDir = new File(SeamFacetInstallDataModelProvider.getTemplatesFolder(), "test"); //$NON-NLS-1$
- } catch (IOException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
- AntCopyUtils.FileSet excludeCvsSvn
- = new AntCopyUtils.FileSet(CVS_SVN).dir(testTemplateDir);
-
- AntCopyUtils.copyFilesAndFolders(
- testTemplateDir,
- testProjectDir,
- new AntCopyUtils.FileSetFileFilter(excludeCvsSvn),
- new FilterSetCollection(filterSet), true);
-
- excludeCvsSvn.dir(new File(seamRuntime.getHomeDir(), "embedded-ejb/conf")); //$NON-NLS-1$
- AntCopyUtils.copyFiles(
- new File(seamRuntime.getHomeDir(), "embedded-ejb/conf"), //$NON-NLS-1$
- embededEjbDir,
- new AntCopyUtils.FileSetFileFilter(excludeCvsSvn));
-
- AntCopyUtils.copyFiles(
- new File(seamRuntime.getHomeDir(), "lib"), //$NON-NLS-1$
- testLibDir,
- new AntCopyUtils.FileSetFileFilter(includeLibs));
-
- createComponentsProperties(testSrcDir, "", Boolean.TRUE); //$NON-NLS-1$
+ doExecuteForWar(project, fv, model, monitor);
}
- /**
- *
- * @param seamGenResFolder
- * @param projectName
- * @param embedded
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.project.facet.SeamFacetAbstractInstallDelegate#configure(org.eclipse.jst.javaee.web.WebApp)
*/
- private void createComponentsProperties(final File seamGenResFolder, String projectName, Boolean embedded) {
- Properties components = new Properties();
- String prefix = "".equals(projectName) ? "" : projectName + "/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- components.put("embeddedEjb", embedded.toString()); //$NON-NLS-1$
- components.put("jndiPattern", prefix + "#{ejbName}/local"); //$NON-NLS-1$ //$NON-NLS-2$
- File componentsProps = new File(seamGenResFolder, "components.properties"); //$NON-NLS-1$
- try {
- componentsProps.createNewFile();
- components.store(new FileOutputStream(componentsProps), ""); //$NON-NLS-1$
- } catch (IOException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- }
-
- /**
- *
- * @param project
- * @param defaultConsoleName
- * @return
- */
- public static boolean toggleHibernateOnProject(IProject project, String defaultConsoleName) {
- IScopeContext scope = new ProjectScope(project);
-
- Preferences node = scope.getNode("org.hibernate.eclipse.console");
-
- if (node != null) {
- node.putBoolean("hibernate3.enabled", true);
- node.put("default.configuration", defaultConsoleName);
- try {
- node.flush();
- } catch (BackingStoreException e) {
- SeamCorePlugin.getDefault().logError("Could not save changes to preferences", e);
- return false;
- }
- } else {
- return false;
- }
-
- try {
- addProjectNature(project, "org.hibernate.eclipse.console.hibernateNature", new NullProgressMonitor());
- return true;
- } catch (CoreException ce) {
- SeamCorePlugin.getDefault().logError("Could not activate Hibernate nature on project " + project.getName(), ce);
- return false;
- }
- }
-
- /**
- * Add the given project nature to the given project (if it isn't already added).
- *
- * @param project
- * @param nature
- * @param monitor
- * @return true if nature where added, false if not
- * @throws OperationCanceledException if job were canceled or CoreException if something went wrong.
- */
- public static boolean addProjectNature(IProject project, String nature, IProgressMonitor monitor) throws CoreException {
- if (monitor != null && monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
-
- if (!project.hasNature(nature)) {
- IProjectDescription description = project.getDescription();
- String[] prevNatures = description.getNatureIds();
- String[] newNatures = new String[prevNatures.length + 1];
- System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
- newNatures[prevNatures.length] = nature;
- description.setNatureIds(newNatures);
- project.setDescription(description, monitor);
- return true;
- } else {
- monitor.worked(1);
- return false;
- }
- }
-
@Override
protected void configure(WebApp webApp) {
// Ajax4jsf (must come first!)
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamProjectCreator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamProjectCreator.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamProjectCreator.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -0,0 +1,99 @@
+ /*******************************************************************************
+ * Copyright (c) 2008 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.project.facet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.jboss.tools.common.util.ResourcesUtils;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
+
+/**
+ * @author Alexey Kazakov
+ * This is basic class that helps New Seam Wizard Page to create EJB, EAR and test projects for seam WAR project.
+ */
+abstract public class SeamProjectCreator {
+
+ protected static final String TEST_WAR_PROFILE = "test-war"; //$NON-NLS-1$
+ protected static final String TEST_EAR_PROFILE = "test"; //$NON-NLS-1$
+
+ protected IDataModel model;
+ protected IProject seamWebProject;
+ protected SeamRuntime seamRuntime;
+ protected String earProjectName;
+ protected String ejbProjectName;
+ protected String testProjectName;
+
+ /**
+ * @param model Seam facet data model
+ * @param seamWebProject Seam web project
+ */
+ public SeamProjectCreator(IDataModel model, IProject seamWebProject) {
+ this.model = model;
+ this.seamWebProject = seamWebProject;
+
+ seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(model.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString());
+ if(seamRuntime==null) {
+ throw new RuntimeException("Can't get seam runtime " + model.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString());
+ }
+
+ // Set default project names
+ earProjectName = seamWebProject.getName() + "-ear";
+ ejbProjectName = seamWebProject.getName() + "-ejb";
+ testProjectName = seamWebProject.getName() + "-test";
+ }
+
+ public IDataModel getModel() {
+ return model;
+ }
+
+ public void setModel(IDataModel model) {
+ this.model = model;
+ }
+
+ /**
+ * Creates test project for seam web project in case of WAR deployment and test, EAR and EJB projects in case of EAR deployment.
+ * @param monitor
+ * @throws CoreException
+ */
+ public void execute(IProgressMonitor monitor) throws CoreException {
+ createTestProject();
+ final String consoleName = SeamFacetAbstractInstallDelegate.isWarConfiguration(model) ? seamWebProject.getName() : ejbProjectName;
+
+ String wsPath = seamWebProject.getLocation().removeLastSegments(1).toFile().getAbsoluteFile().getPath();
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject testProjectToBeImported = wsRoot.getProject(testProjectName);
+
+ ResourcesUtils.importExistingProject(testProjectToBeImported, wsPath + "/" + testProjectName, testProjectName, monitor, true);
+ SeamFacetAbstractInstallDelegate.toggleHibernateOnProject(testProjectToBeImported, consoleName);
+ }
+
+ /**
+ * Creates test project for given seam web project.
+ */
+ abstract protected void createTestProject();
+
+ /**
+ * Creates test project for given seam web project.
+ * @param testProjectName
+ */
+ protected void createTestProject(String testProjectName) {
+ if(testProjectName==null) {
+ throw new IllegalArgumentException("Test project name must not be null");
+ }
+ this.testProjectName = testProjectName;
+ createTestProject();
+ }
+}
\ No newline at end of file
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamProjectCreator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -219,6 +219,14 @@
}
/**
+ *
+ * @return
+ */
+ public IDataModel getConfig() {
+ return model;
+ }
+
+ /**
* Finish has been pressed.
*/
public void transferStateToConfig() {
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamProjectWizard.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamProjectWizard.java 2008-09-29 15:29:53 UTC (rev 10542)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamProjectWizard.java 2008-09-29 16:00:28 UTC (rev 10543)
@@ -15,6 +15,9 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jst.servlet.ui.project.facet.WebProjectFirstPage;
@@ -48,8 +51,12 @@
import org.eclipse.wst.server.ui.ServerUIUtil;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamProjectPreferences;
+import org.jboss.tools.seam.core.project.facet.SeamVersion;
import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.jboss.tools.seam.internal.core.project.facet.Seam1ProjectCreator;
+import org.jboss.tools.seam.internal.core.project.facet.Seam2ProjectCreator;
import org.jboss.tools.seam.internal.core.project.facet.SeamFacetProjectCreationDataModelProvider;
+import org.jboss.tools.seam.internal.core.project.facet.SeamProjectCreator;
import org.jboss.tools.seam.ui.ISeamHelpContextIds;
import org.jboss.tools.seam.ui.SeamUIMessages;
import org.jboss.tools.seam.ui.internal.project.facet.SeamInstallWizardPage;
@@ -188,6 +195,31 @@
return super.performFinish();
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.wst.web.ui.internal.wizards.NewProjectDataModelFacetWizard#performFinish(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void performFinish(final IProgressMonitor monitor) throws CoreException {
+ super.performFinish(monitor);
+ IProject project = this.getFacetedProject().getProject();
+
+ SeamInstallWizardPage page = (SeamInstallWizardPage)getPage(SeamUIMessages.SEAM_INSTALL_WIZARD_PAGE_SEAM_FACET);
+ IDataModel model = page.getConfig();
+
+ String seamVersionString = model.getProperty(IFacetDataModelProperties.FACET_VERSION_STR).toString();
+ SeamVersion seamVersion = SeamVersion.parseFromString(seamVersionString);
+ SeamProjectCreator creator = null;
+ if(seamVersion == SeamVersion.SEAM_1_2) {
+ creator = new Seam1ProjectCreator(model, project);
+ } else if(seamVersion == SeamVersion.SEAM_2_0) {
+ creator = new Seam2ProjectCreator(model, project);
+ } else {
+ throw new RuntimeException("Can't get seam version from seam facet model");
+ }
+
+ creator.execute(monitor);
+ }
+
class SeamWebProjectFirstPage extends WebProjectFirstPage {
@Override
protected String getInfopopID() {
16 years, 3 months
JBoss Tools SVN: r10542 - trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-09-29 11:29:53 -0400 (Mon, 29 Sep 2008)
New Revision: 10542
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
Log:
JBIDE-1497.
Refactoring for usage of ELOperandToken
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2008-09-29 15:29:44 UTC (rev 10541)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2008-09-29 15:29:53 UTC (rev 10542)
@@ -18,6 +18,7 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
@@ -30,7 +31,6 @@
import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ELOperandToken;
import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.internal.core.el.Var;
@@ -195,13 +195,20 @@
Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (n == null || !(n instanceof Attr || n instanceof Text)) return null;
+
+ int start = 0;
+ int end = document.getLength();
+ if(n instanceof IDOMNode) {
+ start = ((IDOMNode)n).getStartOffset();
+ end = ((IDOMNode)n).getEndOffset();
+ }
- List<ELOperandToken> tokens = SeamELCompletionEngine.findTokensAtOffset(document, offset);
- if (tokens == null || tokens.size() == 0)
+ ELInvocationExpression tokens = SeamELCompletionEngine.findExpressionAtOffset(document, offset, start, end);
+ if (tokens == null /*|| tokens.size() == 0*/)
return null; // No EL Operand found
- int propStart = tokens.get(0).getStart();
- int propLength = tokens.get(tokens.size() - 1).getStart() + tokens.get(tokens.size() - 1).getLength() - propStart;
+ int propStart = tokens.getStartPosition();
+ int propLength = tokens.getEndPosition() - propStart;
if (propStart > offset || propStart + propLength < offset) return null;
@@ -255,7 +262,7 @@
SeamELCompletionEngine engine= new SeamELCompletionEngine();
- String prefix = SeamELCompletionEngine.getPrefix(document.get(), r.getOffset() + r.getLength());
+ String prefix = propText;
ELExpression expr = SeamELCompletionEngine.parseOperand(prefix);
if (expr == null)
return null; // No EL Operand found
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2008-09-29 15:29:44 UTC (rev 10541)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2008-09-29 15:29:53 UTC (rev 10542)
@@ -20,6 +20,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
@@ -27,6 +28,7 @@
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.rules.IToken;
import org.eclipse.ui.texteditor.ITextEditor;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -39,7 +41,7 @@
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
IRegion region, boolean canShowMultipleHyperlinks) {
ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
- if (region == null || canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor))
+ if (region == null /*|| canShowMultipleHyperlinks*/ || !(textEditor instanceof JavaEditor))
return null;
int offset= region.getOffset();
@@ -53,7 +55,22 @@
if (wordRegion == null)
return null;
-
+
+ int[] range = null;
+ FastJavaPartitionScanner scanner = new FastJavaPartitionScanner();
+ scanner.setRange(document, 0, document.getLength());
+ while(true) {
+ IToken token = scanner.nextToken();
+ if(token == null || token.isEOF()) break;
+ int start = scanner.getTokenOffset();
+ int end = start + scanner.getTokenLength();
+ if(start <= offset && end >= offset) {
+ range = new int[]{start, end};
+ break;
+ }
+ if(start > offset) break;
+ }
+
if (!checkStartPosition(document, offset))
return null;
@@ -67,14 +84,16 @@
// Ignore. It is probably because of Java element's resource is not found
}
- IJavaElement[] elements = findJavaElements(document, file, wordRegion);
+ if(range == null) range = new int[]{0, document.getLength()};
+
+ IJavaElement[] elements = findJavaElements(document, file, wordRegion, range[0], range[1]);
if (elements != null && elements.length > 0)
return new IHyperlink[] {new SeamELInJavaStringHyperlink(wordRegion, elements)};
return null;
}
- public static IJavaElement[] findJavaElements(IDocument document, IFile file, IRegion region) {
+ public static IJavaElement[] findJavaElements(IDocument document, IFile file, IRegion region, int start, int end) {
IProject project = (file == null ? null : file.getProject());
@@ -84,7 +103,7 @@
SeamELCompletionEngine engine= new SeamELCompletionEngine();
- String prefix= engine.getJavaElementExpression(document.get(), region.getOffset(), region);
+ String prefix= engine.getJavaElementExpression(document, region.getOffset(), region, start, end);
prefix = (prefix == null ? "" : prefix);
List<IJavaElement> javaElements = null;
16 years, 3 months
JBoss Tools SVN: r10541 - in trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui: search and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-09-29 11:29:44 -0400 (Mon, 29 Sep 2008)
New Revision: 10541
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
Log:
JBIDE-1497.
Refactoring for usage of ELOperandToken
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -48,14 +48,13 @@
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.progress.IProgressService;
import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
import org.jboss.tools.common.model.ui.texteditors.xmleditor.XMLTextEditor;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ELOperandToken;
-import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
import org.jboss.tools.seam.ui.search.SeamSearchQuery;
import org.jboss.tools.seam.ui.search.SeamSearchScope;
@@ -187,8 +186,10 @@
if (seamProject == null)
return;
- List<ELOperandToken> tokens = SeamELCompletionEngine.findTokensAtOffset(document, selectionOffset);
+// List<ELOperandToken> tokens = SeamELCompletionEngine.findTokensAtOffset(document, selectionOffset);
+ ELInvocationExpression tokens = null; //TODO
+
if (tokens == null)
return; // No EL Operand found
@@ -210,19 +211,17 @@
* @param tokens
* @return
*/
- public static String[] findVariableNames(ISeamProject seamProject, IDocument document, List<ELOperandToken> tokens) {
+ public static String[] findVariableNames(ISeamProject seamProject, IDocument document, ELInvocationExpression tokens) {
String[] varNames = null;
+ if(tokens == null) return varNames;
- List<List<ELOperandToken>> variations = SeamELCompletionEngine.getPossibleVarsFromPrefix(tokens);
-
// Define the Seam project variables to search for declarations
List<ISeamContextVariable> variables = new ArrayList<ISeamContextVariable>();
- for (List<ELOperandToken> variation : variations) {
+ while(tokens != null) {
try {
- int start = variation.get(0).getStart();
- int end = variation.get(variation.size() - 1).getStart() +
- variation.get(variation.size() - 1).getLength();
+ int start = tokens.getStartPosition();
+ int end = tokens.getEndPosition();
String variationText = document.get(start, end - start);
Set<ISeamContextVariable> vars = seamProject.getVariablesByName(variationText);
@@ -232,6 +231,7 @@
} catch (BadLocationException e1) {
SeamGuiPlugin.getPluginLog().logError(e1);
}
+ tokens = tokens.getLeft();
}
if (variables.size() != 0) {
@@ -291,7 +291,7 @@
fDelegatorAction = action;
}
- private SeamSearchQuery createQuery(List<ELOperandToken> tokens, IFile sourceFile) throws JavaModelException, InterruptedException {
+ private SeamSearchQuery createQuery(ELInvocationExpression tokens, IFile sourceFile) throws JavaModelException, InterruptedException {
SeamSearchScope scope = new SeamSearchScope(new IProject[] {sourceFile.getProject()}, getLimitTo());
@@ -306,7 +306,7 @@
*/
abstract protected int getLimitTo();
- private void performNewSearch(List<ELOperandToken> tokens, IFile sourceFile) throws JavaModelException, InterruptedException {
+ private void performNewSearch(ELInvocationExpression tokens, IFile sourceFile) throws JavaModelException, InterruptedException {
SeamSearchQuery query= createQuery(tokens, sourceFile);
if (query.canRunInBackground()) {
/*
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -11,13 +11,12 @@
package org.jboss.tools.seam.ui.actions;
-import java.util.List;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.text.java.IInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
@@ -33,9 +32,9 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ELOperandToken;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
import org.jboss.tools.seam.ui.SeamUIMessages;
@@ -62,8 +61,16 @@
return false;
IDocument document = getDocument( context.getCompilationUnit() );
+
+ //TODO compute region start and end
+ int start = 0;
+ int end = document.getLength();
+
+ ASTNode node = context.getCoveringNode();
+
+ System.out.println("Covering node=" + node);
- String[] varNames = getVariableNames(seamProject, document, context.getSelectionOffset());
+ String[] varNames = getVariableNames(seamProject, document, context.getSelectionOffset(), start, end);
return (varNames != null && varNames.length != 0);
}
@@ -80,10 +87,10 @@
return SeamCorePlugin.getSeamProject(javaFile.getProject(), true);
}
- private String[] getVariableNames(ISeamProject seamProject, IDocument document, int offset) {
- List<ELOperandToken> tokens = SeamELCompletionEngine.findTokensAtOffset(
- document,
- offset);
+ private String[] getVariableNames(ISeamProject seamProject, IDocument document, int offset,
+ int start, int end) {
+ ELInvocationExpression tokens = SeamELCompletionEngine.findExpressionAtOffset(
+ document, offset, start, end);
if (tokens == null)
return null;
@@ -110,18 +117,16 @@
if (seamProject == null)
return result;
- List<ELOperandToken> tokens = SeamELCompletionEngine.findTokensAtOffset(
+ ELInvocationExpression tokens = SeamELCompletionEngine.findExpressionAtOffset(
document,
- context.getSelectionOffset());
- if (tokens == null || tokens.size() == 0)
+ context.getSelectionOffset(),
+ 0, //TODO compute region start
+ document.getLength() //TODO compute region end
+ );
+ if (tokens == null /*|| tokens.size() == 0*/)
return result;
-
- StringBuffer buf= new StringBuffer();
- for (int i= 0; i < tokens.size(); i++) {
- buf.append(tokens.get(i).getText()); //$NON-NLS-1$
- }
- searchString = buf.toString();
+ searchString = tokens.getText();
result = new IJavaCompletionProposal[2];
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -36,10 +36,10 @@
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.search.core.text.TextSearchEngine;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ELOperandToken;
import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.internal.core.el.Var;
@@ -83,10 +83,10 @@
public IStatus search(SeamSearchScope javaScope,
SeamSearchRequestor requestor,
IFile sourceFile,
- List<ELOperandToken> tokens,
+ ELInvocationExpression tokens,
IProgressMonitor monitor) {
- if (tokens == null || tokens.size() == 0) {
+ if (tokens == null /*|| tokens.size() == 0*/) {
return Status.OK_STATUS;
}
@@ -102,7 +102,7 @@
//Find Seam variable names
// - if the tokens are the variable name only - search for variable declaration in Seam project
- String variableName = SeamSearchVisitor.tokensToString(tokens);
+ String variableName = tokens.getText(); //SeamSearchVisitor.tokensToString(tokens);
Set<ISeamContextVariable> variables = seamProject.getVariablesByName(variableName);
if (variables != null && variables.size() > 0) {
@@ -128,31 +128,25 @@
// Try to find a local Var (a pair of variable-value attributes)
ElVarSearcher varSearcher = new ElVarSearcher(seamProject, sourceFile, new SeamELCompletionEngine());
// Find a Var in the EL
- int start = tokens.get(0).getStart();
- int end = tokens.get(tokens.size() - 1).getStart() +
- tokens.get(tokens.size() - 1).getLength();
+ int start = tokens.getStartPosition();
+ int end = tokens.getEndPosition();
StringBuffer elText = new StringBuffer();
- for (ELOperandToken token : tokens) {
- if (elText.length() > 0) {
- elText.append(".");
- }
- elText.append(token.getText());
- }
+ elText.append(tokens.toString());
if (elText == null || elText.length() == 0)
return Status.OK_STATUS;
- List<Var> allVars= ElVarSearcher.findAllVars(sourceFile, tokens.get(0).getStart());
+ List<Var> allVars= ElVarSearcher.findAllVars(sourceFile, tokens.getStartPosition());
Var var = varSearcher.findVarForEl(elText.toString(), allVars, true);
if (var == null) {
// Find a Var in the current offset assuming that it's a node with var/value attribute pair
- var = ElVarSearcher.findVar(sourceFile, tokens.get(0).getStart());
+ var = ElVarSearcher.findVar(sourceFile, tokens.getStartPosition());
}
if (var == null)
return Status.OK_STATUS;
- if (tokens.size() == 1) {
+ if (tokens.getLeft() == null) {
// The only Var is selected to search for
if (isSearchForDeclarations(javaScope.getLimitTo())) {
@@ -230,7 +224,7 @@
* @return the status containing information about problems in resources searched.
*/
public abstract IStatus search(SeamSearchScope scope, SeamSearchRequestor requestor,
- IFile sourceFile, List<ELOperandToken> tokens, IProgressMonitor monitor);
+ IFile sourceFile, ELInvocationExpression tokens, IProgressMonitor monitor);
/**
* Uses a given IJavaElement-s to find matches in the content of
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -1,5 +1,4 @@
/*******************************************************************************
- * Copyright (c) 2007 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,
@@ -33,11 +32,11 @@
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.seam.core.ISeamDeclaration;
import org.jboss.tools.seam.core.ISeamJavaSourceReference;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ELOperandToken;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.ui.SeamUIMessages;
@@ -174,7 +173,7 @@
}
- private List<ELOperandToken> fTokens;
+ private ELInvocationExpression fTokens;
private IJavaElement[] fJavaElements;
private final SeamSearchScope fScope;
private SeamSearchResult fResult;
@@ -182,13 +181,13 @@
private ISearchRequestor fParentRequestor;
/**
- * Constructs Seam search query for a given {@link ELOperandToken} objects list
+ * Constructs Seam search query for a given {@link ELInvocationExpression} objects list
*
* @param tokens
* @param sourceFile
* @param scope
*/
- public SeamSearchQuery(List<ELOperandToken> tokens, IFile sourceFile, SeamSearchScope scope) {
+ public SeamSearchQuery(ELInvocationExpression tokens, IFile sourceFile, SeamSearchScope scope) {
fTokens = tokens;
fJavaElements = null;
fSourceFile = sourceFile;
@@ -329,11 +328,7 @@
}
searchString = buf.toString();
} else if (fTokens != null) {
- StringBuffer buf= new StringBuffer();
- for (int i= 0; i < fTokens.size(); i++) {
- buf.append(fTokens.get(i).getText());
- }
- searchString = buf.toString();
+ searchString = fTokens.getText();
}
return searchString;
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -113,7 +113,6 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.AbstractSeamDeclaration;
import org.jboss.tools.seam.internal.core.SeamComponent;
-import org.jboss.tools.seam.internal.core.el.ELOperandToken;
import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.internal.core.el.Var;
@@ -1236,26 +1235,7 @@
return false;
}
-
/**
- * Returns the text for a given {@link ELOperandToken} list
- *
- * @param tokens
- * @return
- */
- public static String tokensToString(List<ELOperandToken> tokens) {
- StringBuffer text = new StringBuffer();
- if (tokens != null) {
- for (ELOperandToken token : tokens) {
- text = text.append(token.getText());
- }
- }
-
- return text.toString();
- }
-
-
- /**
* Evaluates all files in this scope.
*
* @param status a {@link MultiStatus} to collect the error status that occurred while collecting resources.
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -17,6 +17,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
+import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
@@ -39,6 +40,13 @@
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
+ if(context instanceof JavaContentAssistInvocationContext) {
+ int start = ((JavaContentAssistInvocationContext)context).getCoreContext().getTokenStart();
+ int end = ((JavaContentAssistInvocationContext)context).getCoreContext().getTokenEnd();
+ if(start >= 0 && end >= start) {
+ return Arrays.asList(fProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset(), start, end));
+ }
+ }
return Arrays.asList(fProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset()));
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java 2008-09-29 15:29:27 UTC (rev 10540)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java 2008-09-29 15:29:44 UTC (rev 10541)
@@ -42,24 +42,31 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor;
import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper;
import org.jboss.tools.common.model.ui.texteditors.xmleditor.XMLTextEditor;
import org.jboss.tools.common.text.ext.IEditorWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.internal.core.el.Var;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* Content assist proposal processor.
@@ -268,7 +275,61 @@
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ if(viewer == null) {
+ return NO_PROPOSALS;
+ }
+ IDocument document = viewer.getDocument();
+ int start = 0;
+ int end = document.getLength();
+
+ int[] region = getRegion(document, offset);
+ if(region != null) {
+ start = region[0];
+ end = region[1];
+ }
+
+ return computeCompletionProposals(viewer, offset, start, end);
+ }
+
+ private int[] getRegion(IDocument document, int offset) {
+ IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
+
try {
+ Document xmlDocument = (model instanceof IDOMModel) ? ((IDOMModel) model)
+ .getDocument()
+ : null;
+ if (xmlDocument == null)
+ return null;
+
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
+
+ if (n == null || !(n instanceof Attr || n instanceof Text))
+ return null;
+
+ int start = 0;
+ int end = document.getLength();
+ if (n instanceof IDOMNode) {
+ start = ((IDOMNode) n).getStartOffset();
+ end = ((IDOMNode) n).getEndOffset();
+ }
+ return new int[]{start, end};
+ } finally {
+ if(model != null) {
+ model.releaseFromRead();
+ model = null;
+ }
+ }
+
+ }
+ /**
+ *
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
+ *
+ * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
+ */
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset, int start, int end) {
+ try {
ITextEditor part = getActiveEditor();
if (part == null) {
return NO_PROPOSALS;
@@ -287,7 +348,9 @@
return NO_PROPOSALS;
}
- String prefix= SeamELCompletionEngine.getPrefix(viewer, offset);
+ //TODO Now this will work only for EL.
+ // If we need CA for expressions/variables without #{}, it should be handled separately.
+ String prefix= SeamELCompletionEngine.getPrefix(viewer, offset, start, end);
prefix = (prefix == null ? "" : prefix); //$NON-NLS-1$
String proposalPrefix = "";
@@ -326,7 +389,10 @@
}
List<Var> vars = ElVarSearcher.findAllVars(viewer, offset);
- List<String> suggestions = fEngine.getCompletions(seamProject, file, documentContent, prefix, offset + proposalPrefix.length() - prefix.length(), false, vars);
+
+ //TODO
+
+ List<String> suggestions = fEngine.getCompletions(seamProject, file, document, prefix, offset + proposalPrefix.length() - prefix.length(), false, vars, start, end);
List<String> uniqueSuggestions = fEngine.makeUnique(suggestions);
List<ICompletionProposal> result= new ArrayList<ICompletionProposal>();
16 years, 3 months
JBoss Tools SVN: r10540 - in trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core: validation and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-09-29 11:29:27 -0400 (Mon, 29 Sep 2008)
New Revision: 10540
Removed:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
Log:
JBIDE-1497.
Refactoring for usage of ELOperandToken
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java 2008-09-29 15:29:16 UTC (rev 10539)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java 2008-09-29 15:29:27 UTC (rev 10540)
@@ -1,123 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.el;
-
-import org.eclipse.jface.text.rules.IToken;
-
-/**
- * Token for the EX expression operand parts
- *
- * @author Jeremy
- */
-public class ELOperandToken implements IToken {
- public static final ELOperandToken EOF = new ELOperandToken(-1, -1, null, -1);
- public static final int EL_VARIABLE_NAME_TOKEN = 1;
- public static final int EL_PROPERTY_NAME_TOKEN = 2;
- public static final int EL_METHOD_TOKEN = 3;
- public static final int EL_SEPARATOR_TOKEN = 4;
-
- int start;
- int length;
- CharSequence chars;
- int type;
-
- /**
- * Constructs the ELToken object
- *
- * @param start
- * @param length
- * @param chars
- * @param type
- */
- public ELOperandToken(int start, int length, CharSequence chars, int type) {
- this.start = start;
- this.length = length;
- this.chars = chars;
- this.type = type;
- }
-
- /**
- * Returns string representation for the token
- */
- public String toString() {
- return "ELToken(" + start + ", " + length + ", " + type + ") [" + (chars == null ? "<Empty>" : chars.toString()) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#getData()
- */
- public Object getData() {
- return (chars == null ? null : chars.subSequence(start, start+length).toString());
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isEOF()
- */
- public boolean isEOF() {
- return (start == -1 && length == -1 && chars == null);
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isOther()
- */
- public boolean isOther() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isUndefined()
- */
- public boolean isUndefined() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isWhitespace()
- */
- public boolean isWhitespace() {
- return false;
- }
-
- /**
- * Returns the token type
- */
- public int getType(){
- return type;
- }
-
- /**
- * Returns the token type
- */
- public boolean isNameToken(){
- return EL_VARIABLE_NAME_TOKEN == type || EL_PROPERTY_NAME_TOKEN == type;
- }
-
- /**
- * Returns the token text
- */
- public String getText() {
- return chars.toString();
- }
-
- /**
- * @return offset of token
- */
- public int getStart() {
- return start;
- }
-
- /**
- * @return length of token
- */
- public int getLength() {
- return length;
- }
-}
\ No newline at end of file
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-09-29 15:29:16 UTC (rev 10539)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-09-29 15:29:27 UTC (rev 10540)
@@ -35,6 +35,7 @@
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.model.ELObjectType;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.model.ELUtil;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
import org.jboss.tools.common.el.core.parser.LexicalToken;
@@ -68,16 +69,14 @@
* @param prefix the prefix to search for
* @param position Offset of the prefix
* @param vars - 'var' attributes which can be used in this EL
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* @return the list of all possible suggestions
* @throws BadLocationException if accessing the current document fails
*/
public List<String> getCompletions(ISeamProject project, IFile file, IDocument document, CharSequence prefix,
- int position, List<Var> vars) throws BadLocationException, StringIndexOutOfBoundsException {
- String documentContent = null;
- if(document!=null) {
- documentContent = document.get();
- }
- return getCompletions(project, file, documentContent, prefix, position, false, vars);
+ int position, List<Var> vars, int start, int end) throws BadLocationException, StringIndexOutOfBoundsException {
+ return getCompletions(project, file, document, prefix, position, false, vars, start, end);
}
/**
@@ -89,6 +88,8 @@
* @param position Offset of the prefix
* @param vars - 'var' attributes which can be used in this EL. Can be null.
* @param returnEqualedVariablesOnly 'false' if we get proposals for mask
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* for example:
* we have 'variableName.variableProperty', 'variableName.variableProperty1', 'variableName.variableProperty2'
* prefix is 'variableName.variableProperty'
@@ -102,12 +103,11 @@
* @throws BadLocationException if accessing the current document fails
* @throws StringIndexOutOfBoundsException
*/
- public List<String> getCompletions(ISeamProject project, IFile file, String documentContent, CharSequence prefix,
- int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws BadLocationException, StringIndexOutOfBoundsException {
+ public List<String> getCompletions(ISeamProject project, IFile file, IDocument document, CharSequence prefix,
+ int position, boolean returnEqualedVariablesOnly, List<Var> vars, int start, int end) throws BadLocationException, StringIndexOutOfBoundsException {
List<String> completions = new ArrayList<String>();
- //TODO change algorithm for finding operand.
- String prefix2 = SeamELCompletionEngine.getPrefix(documentContent, position + prefix.length());
+ String prefix2 = getPrefix(document, position + prefix.length(), start, end);
SeamELOperandResolveStatus status = resolveSeamELOperand(project, file, parseOperand(prefix2), returnEqualedVariablesOnly, vars, new ElVarSearcher(project, file, this));
if (status.isOK()) {
@@ -540,7 +540,8 @@
status.setLastResolvedToken(expr);
}
}
-
+
+/**
private String computeVariableName(List<ELOperandToken> tokens){
if (tokens == null)
tokens = new ArrayList<ELOperandToken>();
@@ -555,14 +556,9 @@
}
return sb.toString();
}
+*/
- /*
- * Compares to tokenized expressions.
- *
- * @param first
- * @param second
- * @return boolean true if two expressions are equal
- */
+/**
private boolean areEqualExpressions(List<ELOperandToken>first, List<ELOperandToken>second) {
if (first == null || second == null)
return (first == second);
@@ -576,6 +572,7 @@
}
return true;
}
+*/
/* Returns scope for the resource
*
@@ -599,15 +596,7 @@
return null;
}
- /*
- * Tries to resolve variables by part of expression
- *
- * @param project
- * @param scope
- * @param part
- * @param tokens
- * @return
- */
+/**
private List<ISeamContextVariable> resolveVariables(ISeamProject project, ScopeType scope, List<ELOperandToken>part, List<ELOperandToken> tokens, boolean onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
String varName = computeVariableName(part);
@@ -631,6 +620,7 @@
}
return new ArrayList<ISeamContextVariable>();
}
+*/
private List<ISeamContextVariable> resolveVariables(ISeamProject project, ScopeType scope, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
@@ -656,12 +646,7 @@
return new ArrayList<ISeamContextVariable>();
}
- /**
- * Creates and returns list of possible variable name combinations from expression starting from the longest name
- *
- * @param prefix
- * @return
- */
+/**
public static List<List<ELOperandToken>> getPossibleVarsFromPrefix(List<ELOperandToken>prefix) {
ArrayList<List<ELOperandToken>> result = new ArrayList<List<ELOperandToken>>();
for (int i = 0; prefix != null && i < prefix.size(); i++) {
@@ -676,6 +661,7 @@
}
return result;
}
+*/
/**
* Removes duplicates of completion strings
@@ -706,14 +692,16 @@
*
* @param viewer
* @param offset
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* @return
* @throws BadLocationException
*/
- public static String getPrefix(ITextViewer viewer, int offset) throws StringIndexOutOfBoundsException {
+ public static String getPrefix(ITextViewer viewer, int offset, int start, int end) throws StringIndexOutOfBoundsException {
IDocument doc= viewer.getDocument();
if (doc == null || offset > doc.getLength())
return null;
- return getPrefix(doc.get(), offset);
+ return getPrefix(doc, offset, start, end);
}
/**
@@ -721,20 +709,18 @@
*
* @param viewer
* @param offset
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* @return
* @throws StringIndexOutOfBoundsException
*/
- public static String getPrefix(String documentContent, int offset) throws StringIndexOutOfBoundsException {
- if (documentContent == null || offset > documentContent.length())
+ public static String getPrefix(IDocument document, int offset, int start, int end) throws StringIndexOutOfBoundsException {
+ if (document == null || document.get() == null || offset > document.get().length())
return null;
-
- SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(documentContent, offset);
- List<ELOperandToken> tokens = tokenizer.getTokens();
-
- if (tokens == null || tokens.size() == 0)
+ ELInvocationExpression expr = findExpressionAtOffset(document, offset, start, end);
+ if (expr == null)
return null;
-
- return documentContent.substring(tokens.get(0).start, offset);
+ return document.get().substring(expr.getStartPosition(), offset);
}
/**
@@ -744,35 +730,35 @@
* @return
* @throws StringIndexOutOfBoundsException
*/
- public String getJavaElementExpression(String documentContent, int offset, IRegion region) throws StringIndexOutOfBoundsException {
- if (documentContent == null || offset > documentContent.length())
+ public String getJavaElementExpression(IDocument document, int offset, IRegion region, int start, int end) throws StringIndexOutOfBoundsException {
+ if (document == null || document.get() == null || offset > document.get().length())
return null;
- SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(documentContent, region.getOffset() + region.getLength());
- List<ELOperandToken> tokens = tokenizer.getTokens();
+ ELInvocationExpression expr = findExpressionAtOffset(
+ document,
+ region.getOffset() + region.getLength(),
+ start, end);
- if (tokens == null || tokens.size() == 0)
- return null;
+ if (expr == null) return null;
- List<List<ELOperandToken>> vars = getPossibleVarsFromPrefix(tokens);
- if (vars == null)
- return null;
+ ELInvocationExpression left = expr;
+ while(left != null && left.getLeft() != null) left = left.getLeft();
- String prefixPart = documentContent.substring(tokens.get(0).start, offset);
+ String prefixPart = document.get().substring(expr.getStartPosition(), offset);
- // Search from the shortest variation to the longest one
- for (int i = vars.size() - 1; i >= 0; i--) {
- List<ELOperandToken>var = vars.get(i);
- String varText = computeVariableName(var);
+ while(left != null) {
+ String varText = left.getText();
if (varText != null && varText.startsWith(prefixPart)) {
return varText;
}
+ if(left == expr) break;
+ left = (ELInvocationExpression)left.getParent();
}
return null;
}
/**
- * Create the array of suggestions from {@link ELOperandToken} list.
+ * Create the array of suggestions from expression.
* @param project Seam project
* @param file File
* @param document
@@ -787,14 +773,7 @@
return getJavaElementsForELOperandTokens(project, file, (ELInvocationExpression)expr);
}
- /**
- * Create the array of suggestions.
- * @param project Seam project
- * @param file File
- * @param document
- * @param prefix the prefix to search for
- * @param position Offset of the prefix
- */
+/**
public List<IJavaElement> getJavaElementsForELOperandTokens(
ISeamProject project, IFile file,
List<ELOperandToken> tokens) throws BadLocationException, StringIndexOutOfBoundsException {
@@ -940,7 +919,7 @@
}
return res;
}
-
+*/
/**
* Create the array of suggestions.
@@ -960,7 +939,6 @@
return res;
}
- List<ELOperandToken> resolvedExpressionPart = new ArrayList<ELOperandToken>();
List<ISeamContextVariable> resolvedVariables = new ArrayList<ISeamContextVariable>();
ScopeType scope = getScope(project, file);
ELInvocationExpression left = expr;
@@ -974,6 +952,7 @@
resolvedVariables = resolvedVars;
break;
}
+ int y = 0;
left = (ELInvocationExpression)left.getLeft();
}
@@ -991,7 +970,6 @@
}
// First segment is found - proceed with next tokens
- int startTokenIndex = (resolvedExpressionPart == null ? 0 : resolvedExpressionPart.size());
List<TypeInfoCollector.MemberInfo> members = new ArrayList<TypeInfoCollector.MemberInfo>();
for (ISeamContextVariable var : resolvedVariables) {
TypeInfoCollector.MemberInfo member = SeamExpressionResolver.getMemberInfoByVariable(var, true);
@@ -1110,12 +1088,52 @@
}
/**
- * Returns list of Seam ELOperandToken which are placed under the cursor position
- *
- * @param document
- * @param offset
- * @return
- */
+ *
+ * @param document
+ * @param offset
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
+ * @return
+ */
+ public static ELInvocationExpression findExpressionAtOffset(IDocument document, int offset, int start, int end) {
+ String content = document.get();
+
+ //TODO this naive calculations should be removed;
+ // this method should be called with reasonable start and end.
+ if(start <= 0) start = guessStart(content, offset);
+ if(end >= content.length()) end = guessEnd(content, offset);
+
+ ELParser parser = ELParserFactory.createJbossParser();
+ ELModel model = parser.parse(content, start, end - start);
+
+ return ELUtil.findExpression(model, offset);
+ }
+
+ static int guessStart(String content, int offset) {
+ if(offset > content.length()) offset = content.length();
+ if(offset < 2) return 0;
+ int s = offset - 2;
+
+ while(s >= 0) {
+ if(content.charAt(s + 1) == '{') {
+ char ch = content.charAt(s);
+ if(ch == '#' || ch == '$') return s;
+ }
+ s--;
+ }
+ return 0;
+ }
+
+ static int guessEnd(String content, int offset) {
+ if(offset >= content.length()) return content.length();
+ while(offset < content.length()) {
+ if(content.charAt(offset) == '}') return offset;
+ offset++;
+ }
+ return content.length();
+ }
+
+/**
public static List<ELOperandToken> findTokensAtOffset(IDocument document, int offset) {
List<ELOperandToken> result = new ArrayList<ELOperandToken>();
@@ -1150,11 +1168,9 @@
return result;
}
+*/
- /*
- * Scans the document from the offset to the beginning to find start of Seam EL operand
- * Returns the start position of first Seam EL operand token
- */
+/**
private static int getELStart(IDocument document, int offset) {
SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(document, offset);
List<ELOperandToken> tokens = tokenizer.getTokens();
@@ -1165,5 +1181,6 @@
ELOperandToken firstToken = tokens.get(0);
return firstToken.getStart();
}
+*/
}
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java 2008-09-29 15:29:16 UTC (rev 10539)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java 2008-09-29 15:29:27 UTC (rev 10540)
@@ -1,360 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.el;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.IDocument;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-
-/**
- * EL string parser.
- * Creates list of tokens for the name, method and separator parts
- *
- * @author Jeremy
- */
-public class SeamELOperandTokenizer {
- protected static final int STATE_INITIAL = 0;
- protected static final int STATE_VAR = 1;
- protected static final int STATE_METHOD = 2;
- protected static final int STATE_SEPARATOR = 3;
-
- protected String documentContent;
- protected List<ELOperandToken> fTokens;
- protected int index;
-
- /**
- * Constructs SeamELTokenizer object.
- * Parse expression from offset to first operator or space.
- * Tokenizer parses document from offset to beginning.
- * For example: documentContetn is '<tag attr="#{var1.pr!=var2.pr}"/>'
- * offset = 29 ("...var2.pr|}")
- * then tokens are {"pr",".","var2"}
- * @param documentContent
- * @param offset
- */
- public SeamELOperandTokenizer(String documentContent, int offset) {
- this.documentContent = documentContent;
- index = (documentContent == null || documentContent.length() < offset? -1 : offset);
- fTokens = new ArrayList<ELOperandToken>();
- parseBackward();
- }
-
- /**
- * Constructs SeamELTokenizer object.
- * @param document
- * @param offset
- */
- public SeamELOperandTokenizer(IDocument document, int offset) {
- this(document.get(), offset);
- }
-
- /**
- * Returns list of tokens for the expression parsed
- *
- * @return
- */
- public List<ELOperandToken> getTokens() {
- return fTokens;
- }
-
- /*
- * Performs backward parsing of document text for expression
- */
- private void parseBackward() {
- ELOperandToken token;
- fState = STATE_INITIAL;
- while ((token = getNextToken()) != ELOperandToken.EOF) {
- if (token.type == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
- token.type == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
- token.type == ELOperandToken.EL_METHOD_TOKEN ||
- token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
-
- fTokens.add(0, token);
- }
- }
- // set first token as variable
- for (int i=0; i<fTokens.size(); i++) {
- token = fTokens.get(i);
- if(token.isNameToken()) {
- token.type = ELOperandToken.EL_VARIABLE_NAME_TOKEN;
- break;
- }
- }
- }
-
- int fState;
- int fEndOfToken;
-
- /*
- * Calculates and returns next token for expression
- *
- * @return
- */
- private ELOperandToken getNextToken() {
- switch (fState) {
- case STATE_INITIAL: // Just started
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierPart((char)ch)) {
- releaseChar();
- return readVarToken();
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- if (ch == ')') {
- releaseChar();
- return readMethodToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_VAR: // Variable name is read - expecting a separator
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_METHOD: // Method name and parameters are read - expecting a separator
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_SEPARATOR: // Separator is read - expecting a var or method
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierPart((char)ch)) {
- releaseChar();
- return readVarToken();
- }
- if (ch == ')') {
- releaseChar();
- return readMethodToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- }
- return ELOperandToken.EOF;
- }
-
- /* Reads and returns the method token from the expression
- *
- * @return
- */
- private ELOperandToken readMethodToken() {
- fState = STATE_METHOD;
- int endOfToken = index;
-
- // read the method parameters
- if (!skipMethodParameters())
- return ELOperandToken.EOF;
-
- // skip spaces between the method's name and it's parameters
- if (!skipSpaceChars())
- return ELOperandToken.EOF;
- // read the method name
- if (!skipMethodName())
- return ELOperandToken.EOF;
-
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index, getCharSequence(index, endOfToken - index), ELOperandToken.EL_METHOD_TOKEN) : ELOperandToken.EOF);
- }
-
- /*
- * Returns the CharSequence object
- *
- * @param start
- * @param length
- * @return
- */
- protected CharSequence getCharSequence(int start, int length) {
- String text = ""; //$NON-NLS-1$
- try {
- text = documentContent.substring(start, start + length);
- } catch (StringIndexOutOfBoundsException e) {
- SeamCorePlugin.getDefault().logError(e);
- text = ""; // For sure //$NON-NLS-1$
- }
- return text.subSequence(0, text.length());
- }
-
-
- /*
- * Skips the space characters in the document
- */
- private boolean skipSpaceChars() {
- int ch;
- while ((ch = readCharBackward()) != -1) {
- if (!Character.isSpaceChar(ch)) {
- releaseChar();
- break;
- }
- }
- return true;
- }
-
- /*
- * Skips the method name characters in the document
- *
- * @return boolean true if at least 1 character had been read
- */
- boolean skipMethodName() {
- int endOfToken = index;
- int ch;
- while((ch = readCharBackward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- releaseChar();
- return (endOfToken - index > 0);
- }
- }
- return false;
- }
-
- /*
- * Skips the method parameters characters in the document
- *
- * @return boolean true if complete parameters set had been read
- */
- private boolean skipMethodParameters() {
- int ch = readCharBackward();
- if (ch != ')')
- return false;
- int pCount = 1;
- while (pCount > 0) {
- ch = readCharBackward();
- if (ch == -1)
- return false;
-
- if (ch == '"' || ch == '\'') {
- skipQuotedChars((char)ch);
- continue;
- }
- if (ch == ')') {
- pCount++;
- continue;
- }
- if (ch == '(') {
- pCount--;
- continue;
- }
- }
- return true;
- }
-
- /*
- * Skips the quoted characters
- *
- */
- private void skipQuotedChars(char pair) {
- int ch = readCharBackward();
-
- while (ch != -1) {
- if (ch == pair) {
- ch = readCharBackward();
- if (ch == '\\') {
- int backSlashCount = 0;
- while (ch == '\\') {
- backSlashCount++;
- ch = readCharBackward();
- }
- releaseChar(); // Return the last non-slash char to the buffer
- if ((backSlashCount/2)*2 == backSlashCount) {
- return;
- }
- } else {
- releaseChar(); // Return the last non-slash char to the buffer
- return;
- }
- }
- ch = readCharBackward();
- }
- }
-
- /* Reads and returns the separator token from the expression
- *
- * @return
- */
- private ELOperandToken readSeparatorToken() {
- fState = STATE_SEPARATOR;
- int ch = readCharBackward();
-
- return (ch == '.' ? new ELOperandToken(index, 1, getCharSequence(index, 1), ELOperandToken.EL_SEPARATOR_TOKEN) :
- ELOperandToken.EOF);
- }
-
- /* Reads and returns the variable token from the expression
- *
- * @return
- */
- private ELOperandToken readVarToken() {
- fState = STATE_VAR;
- int endOfToken = index;
- int ch;
- int type = ELOperandToken.EL_PROPERTY_NAME_TOKEN;
- while((ch = readCharBackward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- releaseChar();
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index, getCharSequence(index, endOfToken - index), type) : ELOperandToken.EOF);
- }
- }
- releaseChar();
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index, getCharSequence(index, endOfToken - index), type) : ELOperandToken.EOF);
- }
-
- /* Reads the next character in the document
- *
- * @return
- */
- private int readCharBackward() {
- if (--index < 0 ||
- documentContent == null ||
- documentContent.length() <= index)
- return -1;
-
- try {
- return documentContent.charAt(index);
- } catch (StringIndexOutOfBoundsException e) {
- return -1;
- }
- }
-
- /*
- * returns the character to the document
- */
- private void releaseChar() {
- if (index < documentContent.length())
- index++;
- }
-}
\ No newline at end of file
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java 2008-09-29 15:29:16 UTC (rev 10539)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java 2008-09-29 15:29:27 UTC (rev 10540)
@@ -1,307 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.el;
-
-import java.util.ArrayList;
-
-import org.eclipse.jface.text.IDocument;
-
-/**
- * EL string parser.
- * Creates list of tokens for the name, method and separator parts
- * Forward parsing
- *
- * @author Jeremy
- */
-
-public class SeamELOperandTokenizerForward extends SeamELOperandTokenizer {
-
- /**
- * Constructs SeamELOperandTokenizerForward object.
- * Parse expression from offset to last operator or space.
- * Tokenizer parses document from offset to ending.
- * For example: documentContetn is '<tag attr="#{var1.pr!=var2.pr}"/>'
- * offset = 29 ("...var2.pr|}")
- * then tokens are {"pr",".","var2"}
- * @param documentContent
- * @param offset
- */
- public SeamELOperandTokenizerForward(String documentContent, int offset) {
- super(documentContent, offset);
- this.documentContent = documentContent;
- index = (documentContent == null || documentContent.length() < offset? -1 : offset);
- fTokens = new ArrayList<ELOperandToken>();
- parseForward();
- }
-
- /**
- * Constructs SeamELOperandTokenizerForward object.
- * Parse expression from offset to last operator or space.
- * Tokenizer parses document from offset to ending.
- * For example: documentContetn is '<tag attr="#{var1.pr!=var2.pr}"/>'
- * offset = 29 ("...var2.pr|}")
- * then tokens are {"pr",".","var2"}
- * @param document
- * @param offset
- */
- public SeamELOperandTokenizerForward(IDocument document, int offset) {
- this(document.get(), offset);
- }
-
- /*
- * Performs forward parsing of document text for expression
- */
- private void parseForward() {
- ELOperandToken token;
- fState = STATE_INITIAL;
- while ((token = getNextToken()) != ELOperandToken.EOF) {
- if (token.type == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
- token.type == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
- token.type == ELOperandToken.EL_METHOD_TOKEN ||
- token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
-
- fTokens.add(token);
- }
- }
- // set first token as variable
- for (int i=0; i<fTokens.size(); i++) {
- token = fTokens.get(i);
- if(token.isNameToken()) {
- token.type = ELOperandToken.EL_VARIABLE_NAME_TOKEN;
- break;
- }
- }
- }
-
- /*
- * Calculates and returns next token for expression.
- * Forward parsing
- *
- * @return
- */
- private ELOperandToken getNextToken() {
- switch (fState) {
- case STATE_INITIAL: // Just started
- {
- int ch = readCharForward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierPart((char)ch)) {
- releaseChar();
- return readVarOrMethodToken();
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_VAR: // Variable name is read - expecting a separator
- {
- int ch = readCharForward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_METHOD: // Method name and parameters are read - expecting a separator
- {
- int ch = readCharForward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_SEPARATOR: // Separator is read - expecting a var or method
- {
- int ch = readCharForward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierStart((char)ch)) {
- releaseChar();
- return readVarOrMethodToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- }
- return ELOperandToken.EOF;
- }
-
- /* Reads the next character in the document
- *
- * @return
- */
- int readCharForward() {
- if (index >= documentContent.length() ||
- documentContent == null ||
- index < 0)
- return -1;
-
- try {
- int ch = documentContent.charAt(index);
- index++;
- return ch;
- } catch (StringIndexOutOfBoundsException e) {
- return -1;
- }
- }
-
- /* Reads and returns the variable token from the expression
- * Forward parsing
- *
- * @return
- */
- private ELOperandToken readVarOrMethodToken() {
- fState = STATE_VAR;
- int startOfToken = index;
- int ch;
- while((ch = readCharForward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- int marker = index - 1; // save the current index (end of var name)
- // skip spaces between the method's name and it's parameters
- if (Character.isSpaceChar(ch)) {
- if (!skipSpaceChars()) {
- // EOF - return the var
- index = marker; // restore the end of var name in the current index
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
- }
- if (ch == -1) {
- // EOF - return the var
- index = marker; // restore the end of var name in the current index
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
-
- if (ch != '(') {
- // not a method - return the var
- index = marker; // restore the end of var name in the current index
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
- releaseChar();
- fState = STATE_METHOD;
-
- // read the method parameters
- skipMethodParameters(); // Do not use the return value (not a matter)
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_METHOD_TOKEN) : ELOperandToken.EOF);
- }
- }
- return (index - startOfToken > 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
-
- /* Reads and returns the separator token from the expression
- * Forward parsing
- *
- * @return
- */
- private ELOperandToken readSeparatorToken() {
- fState = STATE_SEPARATOR;
- int ch = readCharForward();
-
- return (ch == '.' ? new ELOperandToken(index - 1, 1, getCharSequence(index - 1, 1), ELOperandToken.EL_SEPARATOR_TOKEN) :
- ELOperandToken.EOF);
- }
-
-
- /*
- * Skips the space characters in the document
- */
- private boolean skipSpaceChars() {
- int ch;
- while ((ch = readCharForward()) != -1) {
- if (!Character.isSpaceChar(ch)) {
- releaseChar();
- break;
- }
- }
- return true;
- }
-
- /*
- * Skips the method parameters characters in the document
- * Forward parsing
- *
- * @return boolean true if complete parameters set had been read
- */
- private boolean skipMethodParameters() {
- int ch = readCharForward();
- if (ch != '(')
- return false;
- int pCount = 1;
- while (pCount > 0) {
- ch = readCharForward();
- if (ch == -1)
- return false;
-
- if (ch == '"' || ch == '\'') {
- skipQuotedChars((char)ch);
- continue;
- }
- if (ch == '(') {
- pCount++;
- continue;
- }
- if (ch == ')') {
- pCount--;
- continue;
- }
- }
- return true;
- }
-
- /*
- * Skips the quoted characters
- * Forward parsing
- *
- */
- private void skipQuotedChars(char pair) {
- int ch = readCharForward();
-
- while (ch != -1) {
- if (ch == pair)
- return;
-
- if (ch == '\\') {
- int backSlashCount = 0;
- while (ch == '\\') {
- backSlashCount++;
- ch = readCharForward();
- }
- releaseChar(); // Return the last non-slash char to the buffer
- if ((backSlashCount/2)*2 == backSlashCount) {
- return;
- }
- }
- ch = readCharForward();
- }
- }
-
- /*
- * returns the character to the document
- */
- private void releaseChar() {
- if (index > 0)
- index--;
- }
-}
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2008-09-29 15:29:16 UTC (rev 10539)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2008-09-29 15:29:27 UTC (rev 10540)
@@ -56,13 +56,15 @@
list.addAll(set);
return list;
} else if(MEMBERS.equals(id)) {
- try {
- String prefix2 = SeamELCompletionEngine.getPrefix(prefix, prefix.length());
- List<String> suggestions = engine.getCompletions(p, f, prefix, prefix2, 2, true, null);
- return suggestions;
- } catch (BadLocationException e) {
- return EMPTY_LIST;
- }
+ //TODO either refactor or remove this class
+// try {
+// String prefix2 = SeamELCompletionEngine.getPrefix(prefix, prefix.length());
+// List<String> suggestions = engine.getCompletions(p, f, prefix, prefix2, 2, true, null);
+// return suggestions;
+// } catch (BadLocationException e) {
+// return EMPTY_LIST;
+// }
+ return EMPTY_LIST;
}
return null;
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2008-09-29 15:29:16 UTC (rev 10539)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2008-09-29 15:29:27 UTC (rev 10540)
@@ -280,6 +280,7 @@
}
private void validateEl(IFile file, ELExpression el, int offset) {
+ if(el == null) return;
List<ELInvocationExpression> es = el.getInvocations();
for (ELInvocationExpression token: es) {
validateElOperand(file, token, offset);
16 years, 3 months