JBoss Tools SVN: r6998 - in trunk/core: plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-03-18 19:20:48 -0400 (Tue, 18 Mar 2008)
New Revision: 6998
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveActionImpl.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFolderImpl.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/ModelCreationTest.java
Log:
Validation and testing for model
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -182,4 +182,10 @@
* @return
*/
public void clearDelta();
+
+ /**
+ * Validating the model
+ * @return true if it's ok, false if it should fail
+ */
+ public boolean validateModel();
}
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveActionImpl.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveActionImpl.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveActionImpl.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -22,6 +22,7 @@
package org.jboss.ide.eclipse.archives.core.model.internal;
import org.eclipse.core.runtime.IPath;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveAction;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbAction;
@@ -86,4 +87,17 @@
actionDelegate.setType(type);
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean validateModel() {
+ if( getAllChildren().length != 0 ) return false;
+ if( getParent() != null && getModelRootNode() != null &&
+ (getParent().getNodeType() != IArchiveNode.TYPE_ARCHIVE ||
+ !((IArchive)getParent()).isTopLevel()))
+ return false;
+ return true;
+ }
+
}
\ No newline at end of file
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -250,7 +250,7 @@
public IPath getPathRelativeToParent(IPath inputFile) {
String s = inputFile.toOSString().substring(getGlobalSourcePath().toOSString().length()+1);
return new Path(s);
-}
+ }
/*
@@ -259,4 +259,13 @@
public void resetScanner() {
rescanRequired = true;
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean validateModel() {
+ return getAllChildren().length == 0 ? true : false;
+ }
+
}
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFolderImpl.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFolderImpl.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFolderImpl.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -21,11 +21,14 @@
*/
package org.jboss.ide.eclipse.archives.core.model.internal;
+import java.util.ArrayList;
+
import org.eclipse.core.runtime.IPath;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.INamedContainerArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder;
/**
@@ -114,4 +117,23 @@
public IPath getRootArchiveRelativePath() {
return getParent().getRootArchiveRelativePath().append(getName());
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean validateModel() {
+ ArrayList<String> list = new ArrayList<String>();
+ IArchiveNode[] children = getAllChildren();
+ for( int i = 0; i < children.length; i++ ) {
+ if( children[i] instanceof INamedContainerArchiveNode) {
+ if( list.contains(((INamedContainerArchiveNode)children[i]).getName()))
+ return false;
+ else
+ list.add(((INamedContainerArchiveNode)children[i]).getName());
+ }
+ }
+ return super.validateModel();
+ }
+
}
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -21,6 +21,8 @@
*/
package org.jboss.ide.eclipse.archives.core.model.internal;
+import java.util.ArrayList;
+
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.jboss.ide.eclipse.archives.core.ArchivesCore;
@@ -29,7 +31,9 @@
import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor;
import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.jboss.ide.eclipse.archives.core.model.INamedContainerArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
@@ -214,10 +218,6 @@
attributeChanged(PACKAGE_TYPE_ATTRIBUTE, getArchiveTypeId(), type == null ? null : type.getId());
packageDelegate.setPackageType(type.getId());
}
-
- protected XbPackage getPackageDelegate () {
- return packageDelegate;
- }
/*
* @see IArchive#setArchiveType(String)
@@ -246,5 +246,23 @@
return new Path(getName());
return getParent().getRootArchiveRelativePath().append(getName());
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean validateModel() {
+ ArrayList<String> list = new ArrayList<String>();
+ IArchiveNode[] children = getAllChildren();
+ for( int i = 0; i < children.length; i++ ) {
+ if( children[i] instanceof INamedContainerArchiveNode) {
+ if( list.contains(((INamedContainerArchiveNode)children[i]).getName()))
+ return false;
+ else
+ list.add(((INamedContainerArchiveNode)children[i]).getName());
+ }
+ }
+ return super.validateModel();
+ }
}
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveModelNode.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -21,14 +21,18 @@
*/
package org.jboss.ide.eclipse.archives.core.model.internal;
+import java.util.ArrayList;
+
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
import org.jboss.ide.eclipse.archives.core.model.EventManager;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveModel;
import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
+import org.jboss.ide.eclipse.archives.core.model.INamedContainerArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
@@ -162,4 +166,24 @@
clearDelta();
EventManager.fireDelta(delta);
}
+
+ public boolean validateModel() {
+ if( getChildren(IArchiveNode.TYPE_ARCHIVE).length < getAllChildren().length)
+ return false;
+ ArrayList<IPath> list = new ArrayList<IPath>();
+ IArchiveNode[] children = getChildren(IArchiveNode.TYPE_ARCHIVE);
+ IArchive child;
+ for( int i = 0; i < children.length; i++ ) {
+ child = (IArchive)children[i];
+ if( child.getGlobalDestinationPath() != null ) {
+ IPath p = child.getGlobalDestinationPath().append(child.getName());
+ if( list.contains(p))
+ return false;
+ else
+ list.add(p);
+ }
+ }
+
+ return super.validateModel();
+ }
}
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -241,7 +241,7 @@
* (non-Javadoc)
* @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#addChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
*/
- public void addChild(IArchiveNode node) throws ArchivesModelException {
+ public final void addChild(IArchiveNode node) throws ArchivesModelException {
addChild(node, true);
}
@@ -250,9 +250,7 @@
* @param child
* @param addInDelegate
*/
- public void addChild(IArchiveNode child, boolean addInDelegate) throws ArchivesModelException {
- if( !validateChild(child) )
- throw new ArchivesModelException("Unable to add child node");
+ public final void addChild(IArchiveNode child, boolean addInDelegate) throws ArchivesModelException {
Assert.isNotNull(child);
ArchiveNodeImpl childImpl = (ArchiveNodeImpl) child;
children.add(childImpl);
@@ -260,9 +258,17 @@
if( addInDelegate )
nodeDelegate.addChild(childImpl.nodeDelegate);
childChanges(child, IArchiveNodeDelta.CHILD_ADDED);
+ if( !validateModel()) {
+ removeChild(child);
+ throw new ArchivesModelException("Unable to add child node");
+ }
}
- protected boolean validateChild(IArchiveNode child) {
+ public boolean validateModel() {
+ IArchiveNode[] kids = getAllChildren();
+ for( int i = 0; i < kids.length; i++ )
+ if( !kids[i].validateModel() )
+ return false;
return true;
}
Modified: trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/ModelCreationTest.java
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/ModelCreationTest.java 2008-03-18 20:22:52 UTC (rev 6997)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/ModelCreationTest.java 2008-03-18 23:20:48 UTC (rev 6998)
@@ -30,6 +30,7 @@
import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveAction;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.IArchiveModel;
@@ -53,11 +54,16 @@
}
public void testSimpleCreation() {
- createModelNode();
+ createEmptyModelNode();
}
- public void testAddToModel() {
- ArchiveModelNode modelNode = createModelNode();
+
+ /*
+ * Testing the validity of adding certain types
+ * of nodes to others.
+ */
+ public void testRegisterInModel() {
+ ArchiveModelNode modelNode = createEmptyModelNode();
modelNode.getModel().registerProject(modelNode, new NullProgressMonitor());
assertEquals(modelNode,modelNode.getModel().getRoot(project));
assertNotSame(null, modelListener.getDelta());
@@ -65,72 +71,439 @@
modelNode.getModel().registerProject(modelNode, new NullProgressMonitor());
}
- protected ArchiveModelNode createModelNode() {
+
+ // Add everything to the root model
+
+ public void testAddFolderToModel() {
try {
- XbPackages packs = new XbPackages();
- XbPackage pack = new XbPackage();
- packs.addChild(pack);
- ArchiveModelNode model = getModel(packs);
- ModelUtil.fillArchiveModel(packs, model);
- assertEquals(project, model.getProjectPath());
- assertEquals(IArchiveNode.TYPE_MODEL_ROOT, model.getNodeType());
- assertEquals(null, model.getParent());
- assertEquals(packs, model.getNodeDelegate());
- assertTrue(model.hasChildren());
- assertEquals(1, model.getAllChildren().length);
- assertEquals(null, ArchivesModel.instance().getRoot(project));
- assertEquals(null, modelListener.getDelta());
- return model;
+ createEmptyModelNode().addChild(createFolder("testFolder"));
} catch( ArchivesModelException ame ) {
- fail(ame.getMessage());
+ return;
}
- return null;
+ fail();
}
- public void testAddFolderToModel() {
+ public void testAddFilesetToModel() {
try {
- ArchiveModelNode modelNode = createModelNode();
- IArchiveFolder folder = ArchiveNodeFactory.createFolder();
- folder.setName("testFolder");
- modelNode.addChild(folder);
+ createEmptyModelNode().addChild(createFileSet("*", "blah"));
} catch( ArchivesModelException ame ) {
return;
}
fail();
}
- public void testAddFilesetToModel() {
+ public void testAddActionToModel() {
try {
- ArchiveModelNode modelNode = createModelNode();
- IArchiveFileSet fs = ArchiveNodeFactory.createFileset();
- fs.setIncludesPattern("*");
- fs.setSourcePath(new Path("blah"));
- modelNode.addChild(fs);
+ createEmptyModelNode().addChild(createAction());;
} catch( ArchivesModelException ame ) {
return;
}
fail();
}
+ public void testAddArchiveToModel() {
+ try {
+ createEmptyModelNode().addChild(createArchive("someName.war", "test"));
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
- public void testAddActionToModel() {
+ /*
+ * Let's make sure all 4 types can be added to an archive.
+ */
+ public void testAddArchiveToArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName.war2", "test2");
+ archive.addChild(archive2);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+ public void testAddFolderToArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFolder folder = createFolder("test3");
+ archive.addChild(folder);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+ public void testAddFilesetToArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFileSet fs = createFileSet("*", "blah");
+ archive.addChild(fs);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+ public void testAddActionToArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveAction action = createAction();
+ archive.addChild(action);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+
+
+ /*
+ * Let's make sure all 4 types can be added to an INNER archive.
+ */
+ public void testAddArchiveToInnerArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName.war2", "test2");
+ IArchive archive3 = createArchive("someName.war3", "test3");
+ archive.addChild(archive2);
+ archive2.addChild(archive3);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+ public void testAddFolderToInnerArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName.war2", "test2");
+ IArchiveFolder folder = createFolder("test3");
+ archive.addChild(archive2);
+ archive2.addChild(folder);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+ public void testAddFilesetToInnerArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName.war2", "test2");
+ IArchiveFileSet fs = createFileSet("*", "blah");
+ archive.addChild(archive2);
+ archive2.addChild(fs);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ }
+
+ public void testAddActionToInnerArchive() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName.war2", "test2");
+ IArchiveAction action = createAction();
+
+ archive.addChild(archive2);
+ archive2.addChild(action);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
fail();
}
+
- public void testAddArchiveToModel() {
+ // Add all to INNER-folder
+
+ public void testAddArchiveToInnerFolder() {
try {
- ArchiveModelNode modelNode = createModelNode();
- IArchive archive = ArchiveNodeFactory.createArchive();
- archive.setName("someName.war");
- archive.setDestinationPath(new Path("test"));
- modelNode.addChild(archive);
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName.war2", "test2");
+ IArchiveFolder folder = createFolder("test3");
+
+ archive.addChild(folder);
+ folder.addChild(archive2);
+ createEmptyModelNode().addChild(archive);
} catch( ArchivesModelException ame ) {
fail();
}
+ return;
}
+ public void testAddFolderToInnerFolder() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFolder folder = createFolder("folder");
+ IArchiveFolder folder2 = createFolder("folder2");
+
+ archive.addChild(folder);
+ folder.addChild(folder2);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ return;
+ }
+
+ public void testAddFilesetToInnerFolder() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchive archive2 = createArchive("someName2.war", "test2");
+ IArchiveFolder folder = createFolder("test3");
+
+ archive.addChild(folder);
+ folder.addChild(archive2);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ return;
+ }
+
+ public void testAddActionToInnerFolder() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFolder folder = createFolder("folder");
+ IArchiveAction action = createAction();
+
+ archive.addChild(folder);
+ folder.addChild(action);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+ // add all to action
+ public void testAddArchiveToAction() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveAction action = createAction();
+ IArchiveNode child = createArchive("someName2.war", "test2");
+ archive.addChild(action);
+ action.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddFolderToAction() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveAction action = createAction();
+ IArchiveNode child = createFolder("test");
+ archive.addChild(action);
+ action.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddFilesetToAction() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveAction action = createAction();
+ IArchiveNode child = createFileSet("*", "path");
+ archive.addChild(action);
+ action.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+
+ public void testAddActionToAction() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveAction action = createAction();
+ IArchiveNode child = createAction();
+ archive.addChild(action);
+ action.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ // add all to fileset
+ public void testAddArchiveToFileset() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFileSet fs = createFileSet("*", "path");
+ IArchiveNode child = createArchive("someName.war", "test");
+ archive.addChild(fs);
+ fs.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddFolderToFileset() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFileSet fs = createFileSet("*", "path");
+ IArchiveNode child = createFolder("test");
+ archive.addChild(fs);
+ fs.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddFilesetToFileset() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFileSet fs = createFileSet("*", "path");
+ IArchiveNode child = createFileSet("*", "path");
+ archive.addChild(fs);
+ fs.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddActionToFileset() {
+ try {
+ IArchive archive = createArchive("someName.war", "test");
+ IArchiveFileSet fs = createFileSet("*", "path");
+ IArchiveNode child = createAction();
+ archive.addChild(fs);
+ fs.addChild(child);
+ createEmptyModelNode().addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+
+
+ // Test purposely matching archive / folder names
+ public void testAddFolderClashingFolder() {
+ IArchive root = createArchive("root.war", "blah");
+ IArchiveFolder folder1 = createFolder("folder");
+ IArchiveFolder folder2 = createFolder("folder");
+ ArchiveModelNode model = createEmptyModelNode();
+ try {
+ model.addChild(root);
+ root.addChild(folder1);
+ } catch( ArchivesModelException ame ) {
+ fail(ame.getMessage());
+ }
+
+ try {
+ root.addChild(folder2);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddFolderClashingArchive() {
+ IArchive root = createArchive("root.war", "blah");
+ IArchive archive = createArchive("test.war", "dest");
+ IArchiveFolder folder = createFolder("test.war");
+ ArchiveModelNode model = createEmptyModelNode();
+ try {
+ model.addChild(root);
+ root.addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ fail(ame.getMessage());
+ }
+
+ try {
+ root.addChild(folder);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddArchiveClashingFolder() {
+ IArchive root = createArchive("root.war", "blah");
+ IArchive archive = createArchive("test.war", "dest");
+ IArchiveFolder folder = createFolder("test.war");
+ ArchiveModelNode model = createEmptyModelNode();
+ try {
+ model.addChild(root);
+ root.addChild(folder);
+ } catch( ArchivesModelException ame ) {
+ fail(ame.getMessage());
+ }
+
+ try {
+ root.addChild(archive);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ public void testAddArchiveClashingArchive() {
+ IArchive root = createArchive("root.war", "blah");
+ IArchiveFolder folder = createFolder("folder");
+ IArchiveFolder folder2 = createFolder("folder");
+ ArchiveModelNode model = createEmptyModelNode();
+ try {
+ model.addChild(root);
+ root.addChild(folder);
+ } catch( ArchivesModelException ame ) {
+ fail(ame.getMessage());
+ }
+
+ try {
+ root.addChild(folder2);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ // should clash, same destinations
+ public void testArchiveClashingArchiveInModel() {
+ ArchiveModelNode model = createEmptyModelNode();
+ IArchive root = createArchive("root.war", "blah");
+ IArchive root2 = createArchive("root.war", "blah");
+ try {
+ model.addChild(root);
+ model.addChild(root2);
+ } catch( ArchivesModelException ame ) {
+ return;
+ }
+ fail();
+ }
+
+ // Should not clash, different destinations
+ public void testArchiveNotClashingArchiveInModel() {
+ ArchiveModelNode model = createEmptyModelNode();
+ IArchive root = createArchive("root.war", "blah");
+ IArchive root2 = createArchive("root.war", "blah2");
+ try {
+ model.addChild(root);
+ model.addChild(root2);
+ } catch( ArchivesModelException ame ) {
+ fail();
+ }
+ return;
+ }
// public void testDeltas() {
// try {
// ArchiveModelNode model = createModelNode();
@@ -145,6 +518,82 @@
// }
// }
+
+
+
+ /*
+ * Utility methods
+ */
+ protected IArchiveFolder createFolder(String name) {
+ IArchiveFolder folder = ArchiveNodeFactory.createFolder();
+ folder.setName(name);
+ return folder;
+ }
+
+ protected IArchiveFileSet createFileSet(String includes, String path) {
+ IArchiveFileSet fs = ArchiveNodeFactory.createFileset();
+ fs.setIncludesPattern(includes);
+ fs.setSourcePath(new Path(path));
+ return fs;
+ }
+
+ protected IArchiveAction createAction() {
+ IArchiveAction action = ArchiveNodeFactory.createAction();
+ action.setTime(IArchiveAction.POST_BUILD);
+ action.setType("ant");
+ return action;
+ }
+
+ protected IArchive createArchive(String name, String dest) {
+ IArchive archive = ArchiveNodeFactory.createArchive();
+ archive.setName(name);
+ archive.setDestinationPath(new Path(dest));
+ return archive;
+ }
+
+
+ protected ArchiveModelNode createModelNode() {
+ try {
+ XbPackages packs = new XbPackages();
+ XbPackage pack = new XbPackage();
+ packs.addChild(pack);
+ ArchiveModelNode model = getModel(packs);
+ ModelUtil.fillArchiveModel(packs, model);
+ assertEquals(project, model.getProjectPath());
+ assertEquals(IArchiveNode.TYPE_MODEL_ROOT, model.getNodeType());
+ assertEquals(null, model.getParent());
+ assertEquals(packs, model.getNodeDelegate());
+ assertTrue(model.hasChildren());
+ assertEquals(1, model.getAllChildren().length);
+ assertEquals(null, ArchivesModel.instance().getRoot(project));
+ assertEquals(null, modelListener.getDelta());
+ return model;
+ } catch( ArchivesModelException ame ) {
+ fail(ame.getMessage());
+ }
+ return null;
+ }
+
+ protected ArchiveModelNode createEmptyModelNode() {
+ try {
+ XbPackages packs = new XbPackages();
+ ArchiveModelNode model = getModel(packs);
+ ModelUtil.fillArchiveModel(packs, model);
+ assertEquals(project, model.getProjectPath());
+ assertEquals(IArchiveNode.TYPE_MODEL_ROOT, model.getNodeType());
+ assertEquals(null, model.getParent());
+ assertEquals(packs, model.getNodeDelegate());
+ assertFalse(model.hasChildren());
+ assertEquals(0, model.getAllChildren().length);
+ assertEquals(null, ArchivesModel.instance().getRoot(project));
+ assertEquals(null, modelListener.getDelta());
+ return model;
+ } catch( ArchivesModelException ame ) {
+ fail(ame.getMessage());
+ }
+ return null;
+ }
+
protected ArchiveModelNode getModel(XbPackages packs) {
IArchiveModel model = new ArchivesModel();
model.addModelListener(modelListener);
18 years
JBoss Tools SVN: r6997 - trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-18 16:22:52 -0400 (Tue, 18 Mar 2008)
New Revision: 6997
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1881 Progress report for Find seam references is wrong
issue is fixed
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-03-18 19:13:19 UTC (rev 6996)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-03-18 20:22:52 UTC (rev 6997)
@@ -167,10 +167,15 @@
return Status.OK_STATUS;
}
+ private int calculateFiles() {
+ IFile[] files = fCurrentScope.evaluateFilesInScope(fStatus);
+ return (files == null ? 0 : files.length);
+ }
+
public IStatus searchForDeclarations(ISeamProject[] projects, IProgressMonitor monitor) {
fProgressMonitor= monitor == null ? new NullProgressMonitor() : monitor;
fNumberOfScannedFiles= 0;
- fNumberOfFilesToScan= projects.length;
+ fNumberOfFilesToScan= calculateFiles();
fCurrentSeamProject= null;
Job monitorUpdateJob= new MonitorUpdateJob();
@@ -205,10 +210,8 @@
private ElVarSearcher fELVarSearcher;
public boolean processSeamReferencesInProject(ISeamProject project) {
IFile[] files = fCurrentScope == null ? null :
- fCurrentScope.evaluateFilesInScope(fStatus);
+ evaluateProjectFilesInScope(project.getProject(), fStatus);
-
-
fELVarSearcher = new ElVarSearcher(project, fCompletionEngine);
fDocumentsInEditors= evalNonFileBufferDocuments();
boolean res= true;
@@ -705,7 +708,7 @@
public IStatus searchForReferences(ISeamProject[] projects, IProgressMonitor monitor) {
fProgressMonitor= monitor == null ? new NullProgressMonitor() : monitor;
fNumberOfScannedFiles= 0;
- fNumberOfFilesToScan= projects.length;
+ fNumberOfFilesToScan= calculateFiles();
fCurrentSeamProject= null;
Job monitorUpdateJob= new MonitorUpdateJob();
18 years
JBoss Tools SVN: r6996 - in trunk: seam/tests/org.jboss.tools.seam.core.test/projects and 13 other directories.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2008-03-18 15:13:19 -0400 (Tue, 18 Mar 2008)
New Revision: 6996
Added:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.classpath
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.project
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.settings/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.settings/org.jboss.tools.seam.core.prefs
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/bin/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/src/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/src/ejbdemo/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.classpath
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.project
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.settings/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.settings/org.jboss.tools.seam.core.prefs
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/bin/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/src/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/src/testdemo/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.classpath
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.project
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/WebContent/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/bin/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/src/
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/src/wardemo/
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamEARTest.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/preferences/SeamSettingsPreferencesPageTest.java
trunk/tests/tests/org.jboss.tools.test/src/org/jboss/tools/test/util/ProjectImportTestSetup.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1919 Added JUnitTests
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2008-03-18 17:51:50 UTC (rev 6995)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -633,6 +633,9 @@
getValue(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER));
prefs.put(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
getValue(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER));
+ prefs.put(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER,
+ getValue(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER));
+
try {
prefs.flush();
} catch (BackingStoreException e) {
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.classpath
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.classpath (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.classpath 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.project
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.project (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.project 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RefactoringTestProject-ejb</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.jboss.tools.seam.core.seambuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.jboss.tools.seam.core.seamnature</nature>
+ </natures>
+</projectDescription>
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.settings/org.jboss.tools.seam.core.prefs
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.settings/org.jboss.tools.seam.core.prefs (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-ejb/.settings/org.jboss.tools.seam.core.prefs 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,3 @@
+#Tue Mar 18 20:53:15 MSK 2008
+eclipse.preferences.version=1
+seam.parent.project=RefactoringTestProject-war
\ No newline at end of file
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.classpath
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.classpath (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.classpath 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.project
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.project (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.project 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RefactoringTestProject-test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.jboss.tools.seam.core.seambuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.jboss.tools.seam.core.seamnature</nature>
+ </natures>
+</projectDescription>
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.settings/org.jboss.tools.seam.core.prefs
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.settings/org.jboss.tools.seam.core.prefs (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-test/.settings/org.jboss.tools.seam.core.prefs 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,3 @@
+#Tue Mar 18 20:59:12 MSK 2008
+eclipse.preferences.version=1
+seam.parent.project=RefactoringTestProject-war
\ No newline at end of file
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.classpath
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.classpath (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.classpath 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.project
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.project (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.project 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RefactoringTestProject-war</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.jboss.tools.seam.core.seambuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.jboss.tools.seam.core.seamnature</nature>
+ </natures>
+</projectDescription>
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/projects/RefactoringTestProject-war/.settings/org.jboss.tools.seam.core.prefs 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,16 @@
+#Tue Mar 18 20:57:26 MSK 2008
+action.package=ejbdemo
+action.sources=/RefactoringTestProject-ejb/src
+eclipse.preferences.version=1
+model.package=wardemo
+model.sources=/RefactoringTestProject-war/src
+seam.ejb.project=RefactoringTestProject-ejb
+seam.project.connection.profile=DefaultDS
+seam.project.deployment.type=ear
+seam.project.settings.version=1.1
+seam.project.web.root.folder=/RefactoringTestProject-war/WebContent
+seam.runtime.name=jboss-seam-2.0.0.GA
+seam.test.creating=true
+seam.test.project=RefactoringTestProject-test
+test.package=testdemo
+test.sources=/RefactoringTestProject-test/src
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java 2008-03-18 17:51:50 UTC (rev 6995)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamCoreAllTests.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -16,6 +16,8 @@
import org.jboss.tools.seam.core.test.project.facet.SeamFacetInstallDelegateTest;
import org.jboss.tools.seam.core.test.project.facet.SeamRuntimeListConverterTest;
import org.jboss.tools.seam.core.test.project.facet.SeamRuntimeManagerTest;
+import org.jboss.tools.seam.core.test.refactoring.SeamRefactoringAllTests;
+
/**
* @author V.Kabanovich
*
@@ -34,10 +36,11 @@
suite.addTestSuite(SeamRuntimeManagerTest.class);
suite.addTestSuite(SeamFacetInstallDelegateTest.class);
suite.addTest(SeamValidatorsAllTests.suite());
+ suite.addTest(SeamRefactoringAllTests.suite());
// Seam 2 tests can't run on hudson for now ;(
//suite.addTestSuite(Seam2FacetInstallDelegateTest.class);
-
+
return suite;
}
-}
+}
\ No newline at end of file
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamEARTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamEARTest.java 2008-03-18 17:51:50 UTC (rev 6995)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamEARTest.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -87,27 +87,4 @@
assertNotNull("War project must see component 'authenticator' declared in ejb project", c);
}
-
- public void testRenameProject() throws CoreException {
- getSeamProject(projectWAR);
- ISeamProject seamProjectEJB = getSeamProject(projectEJB);
-
- String parentName = seamProjectEJB.getParentProjectName();
-
- RenameSupport support = RenameSupport.create(JavaCore.create(projectWAR), "newName", RenameSupport.UPDATE_REFERENCES);
-
- Shell parent = WorkbenchUtils.getActiveShell();
- IWorkbenchWindow context = WorkbenchUtils.getWorkbench().getActiveWorkbenchWindow();
- try {
- support.perform(parent, context);
- } catch (InterruptedException e) {
- JUnitUtils.fail("Rename failed", e);
- } catch (InvocationTargetException e) {
- JUnitUtils.fail("Rename failed", e);
- }
- String newParentName = seamProjectEJB.getParentProjectName();
- System.out.println(parentName);
- System.out.println(newParentName);
- assertTrue("", "newName".equals(newParentName));
- }
}
\ No newline at end of file
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,109 @@
+ /*******************************************************************************
+ * 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.refactoring;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.ui.refactoring.RenameSupport;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.jboss.tools.test.util.JUnitUtils;
+import org.jboss.tools.test.util.WorkbenchUtils;
+import org.jboss.tools.test.util.xpl.EditorTestHelper;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamPropertyRefactoringTest extends TestCase {
+ IProject warProject;
+ IProject ejbProject;
+ IProject testProject;
+ ISeamProject seamWarProject;
+ ISeamProject seamEjbProject;
+ ISeamProject seamTestProject;
+
+ public SeamPropertyRefactoringTest() {
+ super("Seam Property Refactoring Tests");
+ }
+
+ protected void setUp() throws Exception {
+ if(warProject==null) {
+ IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember("RefactoringTestProject-war");
+ assertNotNull("Can't load RefactoringTestProject-war", project);
+ warProject = project.getProject();
+ warProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+
+ if(ejbProject==null) {
+ IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember("RefactoringTestProject-ejb");
+ assertNotNull("Can't load RefactoringTestProject-ejb", project);
+ ejbProject = project.getProject();
+ ejbProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+
+ if(testProject==null) {
+ IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember("RefactoringTestProject-test");
+ assertNotNull("Can't load RefactoringTestProject-test", project);
+ testProject = project.getProject();
+ testProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+
+ if(seamWarProject==null) {
+ seamWarProject = SeamCorePlugin.getSeamProject(warProject, true);
+ assertNotNull("Seam WAR project is null", seamWarProject);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+
+ if(seamEjbProject==null) {
+ seamEjbProject = SeamCorePlugin.getSeamProject(ejbProject, true);
+ assertNotNull("Seam EJB project is null", seamEjbProject);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+
+ if(seamTestProject==null) {
+ seamTestProject = SeamCorePlugin.getSeamProject(testProject, true);
+ assertNotNull("Seam test project is null", seamTestProject);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+ }
+
+ public void testWarProjectRename() throws CoreException {
+ RenameSupport support = RenameSupport.create(JavaCore.create(warProject), "NewWarProjectName", RenameSupport.UPDATE_REFERENCES);
+
+ Shell parent = WorkbenchUtils.getActiveShell();
+ IWorkbenchWindow context = WorkbenchUtils.getWorkbench().getActiveWorkbenchWindow();
+ try {
+ support.perform(parent, context);
+ } catch (InterruptedException e) {
+ JUnitUtils.fail("Rename failed", e);
+ } catch (InvocationTargetException e) {
+ JUnitUtils.fail("Rename failed", e);
+ }
+ EditorTestHelper.joinBackgroundActivities();
+ String newParentName = seamEjbProject.getParentProjectName();
+ assertEquals("NewWarProjectName", newParentName);
+ }
+}
\ No newline at end of file
Added: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java (rev 0)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamRefactoringAllTests.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -0,0 +1,31 @@
+ /*******************************************************************************
+ * 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.refactoring;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.tools.test.util.ProjectImportTestSetup;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamRefactoringAllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new ProjectImportTestSetup(new TestSuite(SeamPropertyRefactoringTest.class),
+ "org.jboss.tools.seam.core.test",
+ new String[]{"projects/RefactoringTestProject-war", "projects/RefactoringTestProject-ejb", "projects/RefactoringTestProject-test"},
+ new String[]{"RefactoringTestProject-war", "RefactoringTestProject-ejb", "RefactoringTestProject-test"}));
+ return suite;
+ }
+}
\ No newline at end of file
Modified: trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/preferences/SeamSettingsPreferencesPageTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/preferences/SeamSettingsPreferencesPageTest.java 2008-03-18 17:51:50 UTC (rev 6995)
+++ trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/preferences/SeamSettingsPreferencesPageTest.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -125,5 +125,6 @@
assertEquals("Test project property is not set", pref.get(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, ""), PROJECT_NAME);
assertEquals("Test package name property is not set", pref.get(ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME, ""), TEST_PACKAGE_NAME);
assertEquals("Test source folder property is not set", pref.get(ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER, ""), "/" + PROJECT_NAME + "/src");
+ assertEquals("View folder property is not set", pref.get(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, ""), "/" + PROJECT_NAME);
}
}
\ No newline at end of file
Modified: trunk/tests/tests/org.jboss.tools.test/src/org/jboss/tools/test/util/ProjectImportTestSetup.java
===================================================================
--- trunk/tests/tests/org.jboss.tools.test/src/org/jboss/tools/test/util/ProjectImportTestSetup.java 2008-03-18 17:51:50 UTC (rev 6995)
+++ trunk/tests/tests/org.jboss.tools.test/src/org/jboss/tools/test/util/ProjectImportTestSetup.java 2008-03-18 19:13:19 UTC (rev 6996)
@@ -10,52 +10,63 @@
******************************************************************************/
package org.jboss.tools.test.util;
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
import org.eclipse.core.resources.IProject;
import org.jboss.tools.test.util.xpl.EditorTestHelper;
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
/**
* @author eskimo
*
*/
public class ProjectImportTestSetup extends TestSetup {
-
- private String bundleName = "";
- private String projectPath = "";
- private String projectName = "";
-
+
+ private String bundleName;
+ private String[] projectPaths;
+ private String[] projectNames;
+
/**
* @param test
*/
- public ProjectImportTestSetup(Test test,
- String bundleName, String projectPath, String projectName) {
+ public ProjectImportTestSetup(Test test, String bundleName, String projectPath, String projectName) {
super(test);
this.bundleName = bundleName;
- this.projectPath = projectPath;
- this.projectName = projectName;
+ this.projectPaths = new String[]{projectPath};
+ this.projectNames = new String[]{projectName};
}
+ public ProjectImportTestSetup(Test test, String bundleName, String[] projectPaths, String[] projectNames) {
+ super(test);
+ this.bundleName = bundleName;
+ this.projectPaths = projectPaths;
+ this.projectNames = projectNames;
+ }
+
public IProject importProject() throws Exception {
- IProject importedPrj = null;
- EditorTestHelper.joinBackgroundActivities();
- importedPrj = (IProject)ResourcesUtils.importProject(bundleName, projectPath);
- EditorTestHelper.joinBackgroundActivities();
- return importedPrj;
+ return importProjects()[0];
+ }
+
+ public IProject[] importProjects() throws Exception {
+ IProject[] projects = new IProject[projectPaths.length];
+ for (int i = 0; i < projectPaths.length; i++) {
+ EditorTestHelper.joinBackgroundActivities();
+ projects[i] = (IProject)ResourcesUtils.importProject(bundleName, projectPaths[i]);
+ EditorTestHelper.joinBackgroundActivities();
+ }
+ return projects;
}
@Override
protected void setUp() throws Exception {
- importProject();
+ importProjects();
}
@Override
protected void tearDown() throws Exception {
- ResourcesUtils.deleteProject(projectName);
- EditorTestHelper.joinBackgroundActivities();
+ for (int i = 0; i < projectNames.length; i++) {
+ ResourcesUtils.deleteProject(projectNames[i]);
+ EditorTestHelper.joinBackgroundActivities();
+ }
}
-
-
-
-}
+}
\ No newline at end of file
18 years
JBoss Tools SVN: r6994 - trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test.
by jbosstools-commits@lists.jboss.org
Author: dazarov
Date: 2008-03-18 13:11:34 -0400 (Tue, 18 Mar 2008)
New Revision: 6994
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1878
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2008-03-18 16:35:07 UTC (rev 6993)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2008-03-18 17:11:34 UTC (rev 6994)
@@ -62,6 +62,16 @@
this.project.build(IncrementalProjectBuilder.FULL_BUILD, null);
EditorTestHelper.joinBackgroundActivities();
}
+
+ public void tearDown() throws Exception {
+ if(project != null){
+ EditorTestHelper.joinBackgroundActivities();
+ project.close(new NullProgressMonitor());
+ project.delete(true, new NullProgressMonitor());
+ project = null;
+ EditorTestHelper.joinBackgroundActivities();
+ }
+ }
private ISeamProject getSeamProject(IProject project) {
refreshProject(project);
18 years
JBoss Tools SVN: r6993 - trunk/jst/plugins/org.jboss.tools.jst.web/resources/help.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-03-18 12:35:07 -0400 (Tue, 18 Mar 2008)
New Revision: 6993
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web/resources/help/keys-web.properties
Log:
JBIDE-1894
Modified: trunk/jst/plugins/org.jboss.tools.jst.web/resources/help/keys-web.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web/resources/help/keys-web.properties 2008-03-18 15:40:38 UTC (rev 6992)
+++ trunk/jst/plugins/org.jboss.tools.jst.web/resources/help/keys-web.properties 2008-03-18 16:35:07 UTC (rev 6993)
@@ -44,7 +44,7 @@
FileJS_Properties.WindowTitle=Properties
FileJS_Properties.Title=File JS
FileJS_Rename.WindowTitle=Rename
-FileJS_Rename.Title=File CSS
+FileJS_Rename.Title=File JS
FileCSS=/struts/FileCSS.html
18 years
JBoss Tools SVN: r6992 - in trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor: context and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-03-18 11:40:38 -0400 (Tue, 18 Mar 2008)
New Revision: 6992
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/context/VpePageContext.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1896, patch from Snjezana Peco was applied. It's fixed a memmory link error for editiong *.xhtml files.
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-03-18 15:40:28 UTC (rev 6991)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-03-18 15:40:38 UTC (rev 6992)
@@ -1,301 +1,301 @@
-/*******************************************************************************
- * 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.vpe.editor;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.bindings.Binding;
-import org.eclipse.jface.bindings.keys.KeySequence;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.LineStyleEvent;
-import org.eclipse.swt.custom.LineStyleListener;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.events.MenuEvent;
-import org.eclipse.swt.events.MenuListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MessageBox;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
-import org.eclipse.ui.internal.keys.WorkbenchKeyboard;
-import org.eclipse.ui.keys.IBindingService;
-import org.eclipse.ui.progress.UIJob;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent;
-import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
-import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
-import org.eclipse.wst.xml.core.internal.document.AttrImpl;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.eclipse.wst.xml.core.internal.document.NodeImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.event.XModelTreeEvent;
-import org.jboss.tools.common.model.event.XModelTreeListener;
-import org.jboss.tools.common.model.options.PreferenceModelUtilities;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
-import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
-import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.DropData;
-import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
-import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
-import org.jboss.tools.common.model.ui.objecteditor.ExtendedProperties;
-import org.jboss.tools.common.model.ui.objecteditor.ExtendedPropertiesWizard;
-import org.jboss.tools.common.model.ui.util.ModelUtilities;
-import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.model.util.ModelFeatureFactory;
-import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
-import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
-import org.jboss.tools.jst.jsp.editor.IVisualController;
-import org.jboss.tools.jst.jsp.preferences.VpePreference;
-import org.jboss.tools.jst.web.tld.TLDToPaletteHelper;
-import org.jboss.tools.jst.web.tld.TLDUtil;
-import org.jboss.tools.jst.web.tld.URIConstants;
-import org.jboss.tools.vpe.VpeDebug;
-import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.editor.bundle.BundleMap;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.css.AbsoluteFolderReferenceList;
-import org.jboss.tools.vpe.editor.css.CSSReferenceList;
-import org.jboss.tools.vpe.editor.css.RelativeFolderReferenceList;
-import org.jboss.tools.vpe.editor.css.ResourceReferenceListListener;
-import org.jboss.tools.vpe.editor.css.TaglibReferenceList;
-import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
-import org.jboss.tools.vpe.editor.menu.NodeActionManager;
-import org.jboss.tools.vpe.editor.menu.BaseActionManager.MyMenuManager;
-import org.jboss.tools.vpe.editor.mozilla.EditorDomEventListener;
-import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
-import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionHelper;
-import org.jboss.tools.vpe.editor.template.ITemplateSelectionManager;
-import org.jboss.tools.vpe.editor.template.VpeAnyData;
-import org.jboss.tools.vpe.editor.template.VpeEditAnyDialog;
-import org.jboss.tools.vpe.editor.template.VpeHtmlTemplate;
-import org.jboss.tools.vpe.editor.template.VpeIncludeList;
-import org.jboss.tools.vpe.editor.template.VpeTemplate;
-import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
-import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
-import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
-import org.jboss.tools.vpe.editor.util.TextUtil;
-import org.jboss.tools.vpe.editor.util.VisualDomUtil;
-import org.jboss.tools.vpe.editor.util.VpeDndUtil;
-import org.jboss.tools.vpe.messages.VpeUIMessages;
-import org.jboss.tools.vpe.selbar.SelectionBar;
-import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
-import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
-import org.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMEvent;
-import org.mozilla.interfaces.nsIDOMKeyEvent;
-import org.mozilla.interfaces.nsIDOMMouseEvent;
-import org.mozilla.interfaces.nsIDOMMutationEvent;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsISelection;
-import org.mozilla.interfaces.nsISelectionListener;
-import org.mozilla.interfaces.nsISupports;
-import org.mozilla.xpcom.Mozilla;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-public class VpeController implements INodeAdapter, IModelLifecycleListener, INodeSelectionListener, ITextSelectionListener, SelectionListener, EditorDomEventListener, VpeTemplateListener, XModelTreeListener, ResourceReferenceListListener, ISelectionChangedListener, IVisualController {
-
- StructuredTextEditor sourceEditor;
- private MozillaEditor visualEditor;
-// MozillaBrowser browser;
- XulRunnerEditor xulRunnerEditor;
- // TODO Sergey Vasilyev figure out with nsIPressShell
-// private nsIPresShell presShell;
- // TODO Max Areshkau figure out with nsISelectionController
- private VpeSelectionController visualSelectionController;
- VpeDomMapping domMapping;
- private VpeTemplateManager templateManager;
- private VpeSourceDomBuilder sourceBuilder;
- private VpeVisualDomBuilder visualBuilder;
- private VpeSelectionBuilder selectionBuilder;
- private VpeVisualKeyHandler visualKeyHandler;
- private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
- private Attr lastRemovedAttr;
- private String lastRemovedAttrName;
- private boolean mouseUpSelectionReasonFlag;
- private boolean mouseDownSelectionFlag;
- private boolean sourceChangeFlag;
- private VpePageContext pageContext;
- private BundleMap bundle;
- private VpeEditorPart editPart;
- private static final int AROUND_MENU = 1;
- private static final int BEFORE_MENU = 2;
- private static final int AFTER_MENU = 3;
-
- private CSSReferenceList cssReferenceListListener;
- private TaglibReferenceList taglibReferenceListListener;
- private AbsoluteFolderReferenceList absoluteFolderReferenceListListener;
- private RelativeFolderReferenceList relativeFolderReferenceListListener;
- private VpeIncludeList includeList = new VpeIncludeList();
- private VpeVisualInnerDragInfo innerDragInfo = null;
- private FormatControllerManager toolbarFormatControllerManager = null;
- private SelectionBar selectionBar = null;
+/*******************************************************************************
+ * 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.vpe.editor;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.bindings.Binding;
+import org.eclipse.jface.bindings.keys.KeySequence;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.LineStyleEvent;
+import org.eclipse.swt.custom.LineStyleListener;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
+import org.eclipse.ui.internal.keys.WorkbenchKeyboard;
+import org.eclipse.ui.keys.IBindingService;
+import org.eclipse.ui.progress.UIJob;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent;
+import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
+import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
+import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
+import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
+import org.eclipse.wst.xml.core.internal.document.AttrImpl;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.document.NodeImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.event.XModelTreeEvent;
+import org.jboss.tools.common.model.event.XModelTreeListener;
+import org.jboss.tools.common.model.options.PreferenceModelUtilities;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
+import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
+import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.DropData;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
+import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
+import org.jboss.tools.common.model.ui.objecteditor.ExtendedProperties;
+import org.jboss.tools.common.model.ui.objecteditor.ExtendedPropertiesWizard;
+import org.jboss.tools.common.model.ui.util.ModelUtilities;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.util.ModelFeatureFactory;
+import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
+import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
+import org.jboss.tools.jst.jsp.editor.IVisualController;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
+import org.jboss.tools.jst.web.tld.TLDToPaletteHelper;
+import org.jboss.tools.jst.web.tld.TLDUtil;
+import org.jboss.tools.jst.web.tld.URIConstants;
+import org.jboss.tools.vpe.VpeDebug;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.bundle.BundleMap;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.css.AbsoluteFolderReferenceList;
+import org.jboss.tools.vpe.editor.css.CSSReferenceList;
+import org.jboss.tools.vpe.editor.css.RelativeFolderReferenceList;
+import org.jboss.tools.vpe.editor.css.ResourceReferenceListListener;
+import org.jboss.tools.vpe.editor.css.TaglibReferenceList;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.jboss.tools.vpe.editor.menu.NodeActionManager;
+import org.jboss.tools.vpe.editor.menu.BaseActionManager.MyMenuManager;
+import org.jboss.tools.vpe.editor.mozilla.EditorDomEventListener;
+import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
+import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
+import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
+import org.jboss.tools.vpe.editor.selection.VpeSelectionHelper;
+import org.jboss.tools.vpe.editor.template.ITemplateSelectionManager;
+import org.jboss.tools.vpe.editor.template.VpeAnyData;
+import org.jboss.tools.vpe.editor.template.VpeEditAnyDialog;
+import org.jboss.tools.vpe.editor.template.VpeHtmlTemplate;
+import org.jboss.tools.vpe.editor.template.VpeIncludeList;
+import org.jboss.tools.vpe.editor.template.VpeTemplate;
+import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.TemplateManagingUtil;
+import org.jboss.tools.vpe.editor.util.TextUtil;
+import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.editor.util.VpeDndUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.jboss.tools.vpe.selbar.SelectionBar;
+import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
+import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMEvent;
+import org.mozilla.interfaces.nsIDOMKeyEvent;
+import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMMutationEvent;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsISelection;
+import org.mozilla.interfaces.nsISelectionListener;
+import org.mozilla.interfaces.nsISupports;
+import org.mozilla.xpcom.Mozilla;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+public class VpeController implements INodeAdapter, IModelLifecycleListener, INodeSelectionListener, ITextSelectionListener, SelectionListener, EditorDomEventListener, VpeTemplateListener, XModelTreeListener, ResourceReferenceListListener, ISelectionChangedListener, IVisualController {
+
+ StructuredTextEditor sourceEditor;
+ private MozillaEditor visualEditor;
+// MozillaBrowser browser;
+ XulRunnerEditor xulRunnerEditor;
+ // TODO Sergey Vasilyev figure out with nsIPressShell
+// private nsIPresShell presShell;
+ // TODO Max Areshkau figure out with nsISelectionController
+ private VpeSelectionController visualSelectionController;
+ VpeDomMapping domMapping;
+ private VpeTemplateManager templateManager;
+ private VpeSourceDomBuilder sourceBuilder;
+ private VpeVisualDomBuilder visualBuilder;
+ private VpeSelectionBuilder selectionBuilder;
+ private VpeVisualKeyHandler visualKeyHandler;
+ private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
+ private Attr lastRemovedAttr;
+ private String lastRemovedAttrName;
+ private boolean mouseUpSelectionReasonFlag;
+ private boolean mouseDownSelectionFlag;
+ private boolean sourceChangeFlag;
+ private VpePageContext pageContext;
+ private BundleMap bundle;
+ private VpeEditorPart editPart;
+ private static final int AROUND_MENU = 1;
+ private static final int BEFORE_MENU = 2;
+ private static final int AFTER_MENU = 3;
+
+ private CSSReferenceList cssReferenceListListener;
+ private TaglibReferenceList taglibReferenceListListener;
+ private AbsoluteFolderReferenceList absoluteFolderReferenceListListener;
+ private RelativeFolderReferenceList relativeFolderReferenceListListener;
+ private VpeIncludeList includeList = new VpeIncludeList();
+ private VpeVisualInnerDragInfo innerDragInfo = null;
+ private FormatControllerManager toolbarFormatControllerManager = null;
+ private SelectionBar selectionBar = null;
private XModelTreeListenerSWTSync optionsListener;
- //Added by Max Areshkau Fix for JBIDE-1479
- private UIJob job = null;
- Shell tip;
-
- public final static String MODEL_FLAVOR = ModelTransfer.MODEL; //$NON-NLS-1$
-
- public VpeController(VpeEditorPart editPart){
-
- this.editPart = editPart;
- dropWindow = new VpeDropWindow(editPart.getSite().getShell());
- }
-
- void init(StructuredTextEditor sourceEditor, MozillaEditor visualEditor) throws Exception {
- this.sourceEditor = sourceEditor;
- if(sourceEditor instanceof IJSPTextEditor) {
- ((IJSPTextEditor)sourceEditor).setVPEController(this);
- dropWindow.setEditor((IJSPTextEditor)sourceEditor);
- }
- this.visualEditor = visualEditor;
- visualEditor.setController(this);
- templateManager = VpeTemplateManager.getInstance();
- bundle = new BundleMap();
- bundle.init(sourceEditor);
- pageContext = new VpePageContext(templateManager, bundle, editPart);
- domMapping = new VpeDomMapping(pageContext);
- sourceBuilder = new VpeSourceDomBuilder(domMapping, this, templateManager, sourceEditor, pageContext);
- visualBuilder = new VpeVisualDomBuilder(domMapping, this, templateManager, visualEditor, pageContext);
- pageContext.setSourceDomBuilder(sourceBuilder);
- pageContext.setVisualDomBuilder(visualBuilder);
- IDOMModel sourceModel = (IDOMModel)getModel();
- if (sourceModel == null) {
- return;
- }
- sourceModel.addModelLifecycleListener(this);
- IDOMDocument sourceDocument = sourceModel.getDocument();
- visualBuilder.refreshExternalLinks();
- visualBuilder.buildDom(sourceDocument);
-
- templateManager.addTemplateListener(this);
-
- xulRunnerEditor = visualEditor.getXulRunnerEditor();
- // TODO Sergey Vasilyev figure out with nsIPressShell
-// presShell = browser.getPresShell();
- visualSelectionController = new VpeSelectionController(xulRunnerEditor.getSelection());
- selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder, visualBuilder, visualSelectionController);
- visualKeyHandler = new VpeVisualKeyHandler(sourceEditor, domMapping, pageContext){
- public void doSave(IProgressMonitor monitor){
- editPart.doSave(monitor);
- }
- };
-
-// glory
- ISelectionProvider provider = sourceEditor.getSelectionProvider();
+ //Added by Max Areshkau Fix for JBIDE-1479
+ private UIJob job = null;
+ Shell tip;
+
+ public final static String MODEL_FLAVOR = ModelTransfer.MODEL; //$NON-NLS-1$
+
+ public VpeController(VpeEditorPart editPart){
+
+ this.editPart = editPart;
+ dropWindow = new VpeDropWindow(editPart.getSite().getShell());
+ }
+
+ void init(StructuredTextEditor sourceEditor, MozillaEditor visualEditor) throws Exception {
+ this.sourceEditor = sourceEditor;
+ if(sourceEditor instanceof IJSPTextEditor) {
+ ((IJSPTextEditor)sourceEditor).setVPEController(this);
+ dropWindow.setEditor((IJSPTextEditor)sourceEditor);
+ }
+ this.visualEditor = visualEditor;
+ visualEditor.setController(this);
+ templateManager = VpeTemplateManager.getInstance();
+ bundle = new BundleMap();
+ bundle.init(sourceEditor);
+ pageContext = new VpePageContext(templateManager, bundle, editPart);
+ domMapping = new VpeDomMapping(pageContext);
+ sourceBuilder = new VpeSourceDomBuilder(domMapping, this, templateManager, sourceEditor, pageContext);
+ visualBuilder = new VpeVisualDomBuilder(domMapping, this, templateManager, visualEditor, pageContext);
+ pageContext.setSourceDomBuilder(sourceBuilder);
+ pageContext.setVisualDomBuilder(visualBuilder);
+ IDOMModel sourceModel = (IDOMModel)getModel();
+ if (sourceModel == null) {
+ return;
+ }
+ sourceModel.addModelLifecycleListener(this);
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.refreshExternalLinks();
+ visualBuilder.buildDom(sourceDocument);
+
+ templateManager.addTemplateListener(this);
+
+ xulRunnerEditor = visualEditor.getXulRunnerEditor();
+ // TODO Sergey Vasilyev figure out with nsIPressShell
+// presShell = browser.getPresShell();
+ visualSelectionController = new VpeSelectionController(xulRunnerEditor.getSelection());
+ selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder, visualBuilder, visualSelectionController);
+ visualKeyHandler = new VpeVisualKeyHandler(sourceEditor, domMapping, pageContext){
+ public void doSave(IProgressMonitor monitor){
+ editPart.doSave(monitor);
+ }
+ };
+
+// glory
+ ISelectionProvider provider = sourceEditor.getSelectionProvider();
//Max Areshkau JBIDE-1105 If selection event received after selection in
//visual part we lost focus of selection, so we should process selection event
//in time of selection
// if (provider instanceof IPostSelectionProvider)
// ((IPostSelectionProvider) provider).addPostSelectionChangedListener(this);
// else
- provider.addSelectionChangedListener(this);
-
-// ViewerSelectionManager selectionManager = sourceEditor.getViewerSelectionManager();
-// selectionManager.addNodeSelectionListener(this);
-// selectionManager.addTextSelectionListener(this);
- StyledText textWidget = VpeSelectionHelper.getSourceTextWidget(sourceEditor);
- if (textWidget != null) {
- textWidget.addSelectionListener(this);
- }
-
- visualEditor.setEditorDomEventListener(this);
- switcher.initActiveEditor();
-
+ provider.addSelectionChangedListener(this);
+
+// ViewerSelectionManager selectionManager = sourceEditor.getViewerSelectionManager();
+// selectionManager.addNodeSelectionListener(this);
+// selectionManager.addTextSelectionListener(this);
+ StyledText textWidget = VpeSelectionHelper.getSourceTextWidget(sourceEditor);
+ if (textWidget != null) {
+ textWidget.addSelectionListener(this);
+ }
+
+ visualEditor.setEditorDomEventListener(this);
+ switcher.initActiveEditor();
+
if (optionsListener == null) {
- XModelObject optionsObject = ModelUtilities.getPreferenceModel().getByPath(VpePreference.EDITOR_PATH);
+ XModelObject optionsObject = ModelUtilities.getPreferenceModel().getByPath(VpePreference.EDITOR_PATH);
optionsListener = new XModelTreeListenerSWTSync(this);
- optionsObject.getModel().addModelTreeListener(optionsListener);
+ optionsObject.getModel().addModelTreeListener(optionsListener);
}
-
-
- cssReferenceListListener = CSSReferenceList.getInstance();
- cssReferenceListListener.addChangeListener(this);
-
- taglibReferenceListListener = TaglibReferenceList.getInstance();
- taglibReferenceListListener.addChangeListener(this);
-
- absoluteFolderReferenceListListener = AbsoluteFolderReferenceList.getInstance();
- absoluteFolderReferenceListListener.addChangeListener(this);
-
- relativeFolderReferenceListListener = RelativeFolderReferenceList.getInstance();
- relativeFolderReferenceListListener.addChangeListener(this);
-
-// pageContext.fireTaglibsChanged();
- }
-
- public void dispose() {
+
+
+ cssReferenceListListener = CSSReferenceList.getInstance();
+ cssReferenceListListener.addChangeListener(this);
+
+ taglibReferenceListListener = TaglibReferenceList.getInstance();
+ taglibReferenceListListener.addChangeListener(this);
+
+ absoluteFolderReferenceListListener = AbsoluteFolderReferenceList.getInstance();
+ absoluteFolderReferenceListListener.addChangeListener(this);
+
+ relativeFolderReferenceListListener = RelativeFolderReferenceList.getInstance();
+ relativeFolderReferenceListListener.addChangeListener(this);
+
+// pageContext.fireTaglibsChanged();
+ }
+
+ public void dispose() {
if (optionsListener != null) {
XModelObject optionsObject = ModelUtilities.getPreferenceModel().getByPath(VpePreference.EDITOR_PATH);
optionsObject.getModel().removeModelTreeListener(optionsListener);
@@ -306,589 +306,589 @@
if (sourceModel != null) {
sourceModel.removeModelLifecycleListener(this);
}
- switcher.destroyActiveEditor();
+ switcher.destroyActiveEditor();
switcher=null;
-
- if (templateManager != null) {
- templateManager.removeTemplateListener(this);
+
+ if (templateManager != null) {
+ templateManager.removeTemplateListener(this);
templateManager=null;
- }
- if (visualBuilder != null) {
- visualBuilder.dispose();
- visualBuilder = null;
- }
+ }
+ if (visualBuilder != null) {
+ visualBuilder.dispose();
+ visualBuilder = null;
+ }
sourceBuilder=null;
- if (sourceEditor != null) {
-//glory
- ISelectionProvider provider = sourceEditor.getSelectionProvider();
- provider.removeSelectionChangedListener(this);
-// ViewerSelectionManager selectionManager = sourceEditor.getViewerSelectionManager();
-// selectionManager.removeNodeSelectionListener(this);
-// selectionManager.removeTextSelectionListener(this);
- StyledText textWidget = VpeSelectionHelper.getSourceTextWidget(sourceEditor);
- if (textWidget != null) {
- textWidget.removeSelectionListener(this);
- }
+ if (sourceEditor != null) {
+//glory
+ ISelectionProvider provider = sourceEditor.getSelectionProvider();
+ provider.removeSelectionChangedListener(this);
+// ViewerSelectionManager selectionManager = sourceEditor.getViewerSelectionManager();
+// selectionManager.removeNodeSelectionListener(this);
+// selectionManager.removeTextSelectionListener(this);
+ StyledText textWidget = VpeSelectionHelper.getSourceTextWidget(sourceEditor);
+ if (textWidget != null) {
+ textWidget.removeSelectionListener(this);
+ }
((IJSPTextEditor)sourceEditor).setVPEController(null);
- }
+ }
if (dropWindow != null) {
dropWindow.setEditor(null);
}
- if (visualEditor != null) {
- visualEditor.setEditorDomEventListener(null);
- if (visualSelectionController != null) {
-// visualSelectionController.Release();
- visualSelectionController = null;
- }
- // TODO Sergey Vasilyev figure out with Press Shell
-// if (presShell != null) {
-// presShell.Release();
-// presShell = null;
-// }
+ if (visualEditor != null) {
+ visualEditor.setEditorDomEventListener(null);
+ if (visualSelectionController != null) {
+// visualSelectionController.Release();
+ visualSelectionController = null;
+ }
+ // TODO Sergey Vasilyev figure out with Press Shell
+// if (presShell != null) {
+// presShell.Release();
+// presShell = null;
+// }
visualEditor = null;
- }
-
- if (cssReferenceListListener != null) {
- cssReferenceListListener.removeChangeListener(this);
- }
- if (taglibReferenceListListener != null) {
- taglibReferenceListListener.removeChangeListener(this);
- }
- if (absoluteFolderReferenceListListener != null) {
- absoluteFolderReferenceListListener.removeChangeListener(this);
- }
- if (relativeFolderReferenceListListener != null) {
- relativeFolderReferenceListListener.removeChangeListener(this);
- }
+ }
+
+ if (cssReferenceListListener != null) {
+ cssReferenceListListener.removeChangeListener(this);
+ }
+ if (taglibReferenceListListener != null) {
+ taglibReferenceListListener.removeChangeListener(this);
+ }
+ if (absoluteFolderReferenceListListener != null) {
+ absoluteFolderReferenceListListener.removeChangeListener(this);
+ }
+ if (relativeFolderReferenceListListener != null) {
+ relativeFolderReferenceListListener.removeChangeListener(this);
+ }
toolbarFormatControllerManager = null;
- }
-
- // INodeAdapter implementation
- public boolean isAdapterForType(Object type) {
- return type == this;
- }
- //FIX Fox JBIDE-1479 added by Max Areshkau
- public void notifyChanged(final INodeNotifier notifier, final int eventType,final Object feature,final Object oldValue,final Object newValue, final int pos) {
-
- //start job when we modify file in ui thread, without this code
- //changes will be applied with 1 second delay
- Display display = null;
- if (PlatformUI.isWorkbenchRunning())
- display= PlatformUI.getWorkbench().getDisplay();
-
- if (display != null && (Thread.currentThread() == display.getThread())) {
- notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
- return;
- }
- //start job when we modify file in non ui thread
- if(job!=null) {
- job.cancel();
- }
-
- job = new UIJob("NotifyChangedJob"){
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- //we checks is job was canceled and if is it true we cancel job
- if(monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- } else {
- notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
- }
- return Status.OK_STATUS;
- }};
- job.setPriority(Job.LONG);
- job.schedule(1000L);
- }
-
- public void notifyChangedInUiThread(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int pos) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) {
- printSourceEvent(notifier, eventType, feature, oldValue, newValue, pos);
- }
- if(visualBuilder==null) {
- return;
- }
-// visualBuilder.rebuildFlag = false;
-
- switch (eventType) {
- case INodeNotifier.CHANGE:
- sourceChangeFlag = true;
- int type = ((Node)notifier).getNodeType();
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- if (type == Node.TEXT_NODE) {
- visualBuilder.setText((Node)notifier);
- visualEditor.showResizer();
- //Added by Max Areshkau JBIDE-1554
- visualBuilder.updateNode((Node)notifier);
- } else if (type == Node.COMMENT_NODE) {
- if("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$
- visualBuilder.setSelectionRectangle(null);
- visualBuilder.updateNode((Node)notifier);
- }
- } else if (feature != null && ((Node)feature).getNodeType() == Node.ATTRIBUTE_NODE) {
- if (newValue != null) {
- String attrName = ((Attr)feature).getName();
- if ((Attr)feature == lastRemovedAttr && !attrName.equals(lastRemovedAttrName)) {
- lastRemovedAttr = null;
- visualBuilder.removeAttribute((Element)notifier, lastRemovedAttrName);
- }
- visualBuilder.setAttribute((Element)notifier, ((Attr)feature).getName(), (String)newValue);
- } else {
- lastRemovedAttr = (Attr)feature;
- lastRemovedAttrName = ((Attr)feature).getName();
- visualBuilder.removeAttribute((Element)notifier, lastRemovedAttrName);
- }
- }
- visualEditor.showResizer();
- break;
-
- case INodeNotifier.ADD:
- //we should remove all parent nodes from vpe cash
- visualBuilder.removeNode((Node)newValue);
- break;
-
- case INodeNotifier.REMOVE:
- visualBuilder.stopToggle((Node)feature);
- visualBuilder.removeNode((Node)feature);
- break;
-
- case INodeNotifier.STRUCTURE_CHANGED:
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- visualBuilder.updateNode((Node)notifier);
- break;
- case INodeNotifier.CONTENT_CHANGED:
- if (!sourceChangeFlag) {
- if (feature != null && ((Node)feature).getNodeType() == Node.TEXT_NODE) {
- //if (((Node)notifier).getNodeName().equalsIgnoreCase("style")) {
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- visualBuilder.setText((Node)feature);
- visualEditor.showResizer();
- //}
- }
- } else {
- sourceChangeFlag = false;
- }
- break;
- }
- switcher.stopActiveEditor();
- }
-
- // INodeSelectionListener implementation
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- List<?> nodes = event.getSelectedNodes();
- if (nodes != null && nodes.size() > 0) {
- Node sourceNode = (Node)nodes.get(0);
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> nodeSelectionChanged sourceNode: " + sourceNode.getNodeName() + " " + event.getCaretPosition()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (event.getSource() instanceof IContentOutlinePage) {
- sourceSelectionChanged();
- }
- }
- switcher.stopActiveEditor();
- }
-
- // ITextSelectionListener implementation
- //TODO Max Areshau looks like this method don't used
- public void textSelectionChanged(TextSelectionChangedEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> textSelectionChanged " + event.getSource()); //$NON-NLS-1$
- }
-// if (event.getSource() instanceof StyledText) {
- sourceSelectionChanged();
-// }
- switcher.stopActiveEditor();
- }
-
- // SelectionListener implementation
- public void widgetSelected(SelectionEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> widgetSelected"); //$NON-NLS-1$
- }
- if (event.getSource() instanceof StyledText) {
- sourceSelectionChanged();
- }
- switcher.stopActiveEditor();
- }
-
- public void widgetDefaultSelected(SelectionEvent event) {
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> widgetDefaultSelected"); //$NON-NLS-1$
- }
- }
-
- public void sourceSelectionChanged() {
- sourceSelectionChanged(false);
- }
-
- public void sourceSelectionChanged(boolean showCaret) {
- Point range = sourceEditor.getTextViewer().getSelectedRange();
- int anchorPosition = range.x;
- int focusPosition = range.x + range.y;
-
- boolean extendFlag = range.y != 0;
- boolean reversionFlag = extendFlag && anchorPosition == VpeSelectionHelper.getCaretOffset(sourceEditor);
- if (reversionFlag) {
- anchorPosition = focusPosition;
- focusPosition = range.x;
- }
-
- VpeTemplate template = TemplateManagingUtil
- .getTemplateBySourceSelection(pageContext, focusPosition,
- anchorPosition);
-
- if (template instanceof ITemplateSelectionManager) {
- ((ITemplateSelectionManager) template).setVisualSelectionBySource(
- pageContext, visualSelectionController, focusPosition,
- anchorPosition);
- return;
- }
-
- Node focusNode = getSourceNodeAt(focusPosition);
- if (focusNode == null) {
- return;
- }
- int focusOffset = getSourceNodeOffset(focusNode, focusPosition, extendFlag && !reversionFlag);
- Node anchorNode = null;
- int anchorOffset = 0;
- if (extendFlag) {
- anchorNode = getSourceNodeAt(anchorPosition);
- anchorOffset = getSourceNodeOffset(anchorNode, anchorPosition, reversionFlag);
- } else {
- anchorNode = focusNode;
- anchorOffset = focusOffset;
- }
-
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
- System.out.println(" anchorNode: " + anchorNode.getNodeName() + " anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println(" focusNode: " + focusNode.getNodeName() + " focusOffset: " + focusOffset + " focusPosition: " + focusPosition); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- try{
- if(anchorNode.getNodeType() == Node.TEXT_NODE || anchorNode.getNodeType() == Node.ATTRIBUTE_NODE){
- String text;
- if (anchorNode.getNodeType() == Node.TEXT_NODE) {
- IndexedRegion region = (IndexedRegion)anchorNode;
- text = sourceEditor.getTextViewer().getDocument().get(region.getStartOffset(), region.getEndOffset()-region.getStartOffset());
- } else {
- text = ((AttrImpl)anchorNode).getValueRegionText();
- }
- anchorOffset = TextUtil.visualPosition(text, anchorOffset);
- }
- if(focusNode.getNodeType() == Node.TEXT_NODE || focusNode.getNodeType() == Node.ATTRIBUTE_NODE){
- IndexedRegion region = (IndexedRegion)focusNode;
- String text;
- if (focusNode.getNodeType() == Node.TEXT_NODE) {
- text = sourceEditor.getTextViewer().getDocument().get(region.getStartOffset(), region.getEndOffset()-region.getStartOffset());
- } else {
- text = ((AttrImpl)focusNode).getValueRegionText();
- }
- focusOffset = TextUtil.visualPosition(text, focusOffset);
- }
- }catch(Exception ex){
- VpePlugin.reportProblem(ex);
- }
-
- selectionBuilder.setVisualSelection(anchorNode, anchorOffset, focusNode, focusOffset, reversionFlag, showCaret);
- }
-
- public void sourceSelectionToVisualSelection(boolean showCaret) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- sourceSelectionChanged(showCaret);
- switcher.stopActiveEditor();
- }
- // IModelLifecycleListener implementation
- public void processPreModelEvent(ModelLifecycleEvent event) {
- }
-
- public void processPostModelEvent(ModelLifecycleEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- /* Added by Max Areshkau JBIDE-1457
- * ModelLifecycleEvent.MODEL_RELEASED generated when model in
- * model calls methods releaseFromRead() or releaseFromEdit().
- * When editor is open he has only when href on model, so nothing can generated
- * this event.When editor closes generation of this event depends from cantains
- * any service href on model or not. It's can be a reason of problems
- * on reopen file.
- *
- * We shouldn't call here rebuild dom.
- */
- if (event.getType() == ModelLifecycleEvent.MODEL_RELEASED) {
- if (VpeDebug.PRINT_SOURCE_MODEL_LIFECYCLE_EVENT) {
- System.out.println(">>> processPostModelEvent: " + event.toString()); //$NON-NLS-1$
- }
- visualBuilder.setSelectionRectangle(null);
- IStructuredModel model = event.getModel();
- model.removeModelLifecycleListener(this);
- IDOMModel sourceModel = (IDOMModel)getModel();
- sourceModel.addModelLifecycleListener(this);
- bundle.clearAll();
- bundle.refresh();
- visualBuilder.setSelectionRectangle(null);
- IDOMDocument sourceDocument = sourceModel.getDocument();
- // JBIDE-1457
-// visualBuilder.rebuildDom(sourceDocument);
-// pageContext.fireTaglibsChanged();
- }
- switcher.stopActiveEditor();
- }
-
- // EditorDomEventListener implementation
- public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- switcher.stopActiveEditor();
- }
-
- public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = mutationEvent.getRelatedNode();
- if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
- sourceBuilder.addNode(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- }
- switcher.stopActiveEditor();
- }
-
- public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
- visualBuilder.setSelectionRectangle(null);
- sourceBuilder.removeNode(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- }
- switcher.stopActiveEditor();
- }
-
- public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- switcher.stopActiveEditor();
- }
-
- public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- switcher.stopActiveEditor();
- }
-
- public void attrModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- switcher.stopActiveEditor();
- }
-
- public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
-
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- sourceBuilder.setText(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- switcher.stopActiveEditor();
- }
-
- public void notifySelectionChanged(nsIDOMDocument doc, nsISelection selection, short reason) {
- if (switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- mouseUpSelectionReasonFlag = (reason & nsISelectionListener.MOUSEUP_REASON) > 0;
- if (mouseUpSelectionReasonFlag || reason == nsISelectionListener.NO_REASON || reason == nsISelectionListener.KEYPRESS_REASON || reason == nsISelectionListener.SELECTALL_REASON || (reason & nsISelectionListener.MOUSEDOWN_REASON) > 0) {
- if (VpeDebug.PRINT_VISUAL_SELECTION_EVENT) {
- System.out.println("<<< notifySelectionChanged: " + reason); //$NON-NLS-1$
- }
- selectionBuilder.setSelection(selection);
- }
- switcher.stopActiveEditor();
- }
- }
-
-
- public void mouseDown(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- nsIDOMElement visualDragElement = selectionBuilder.getDragElement(mouseEvent);
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- System.out.println("<<< mouseDown targetNode: " + visualNode.getNodeName() + " (" + visualNode + ") selectedElement: " + (visualDragElement != null ? visualDragElement.getNodeName() + " (" + visualDragElement + ")" : null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
- mouseDownSelectionFlag = false;
-
- if (visualDragElement != null) {
-
- //we shouldn't change selection when we click on <input type="text" /> element,
- //because if we change after resizing the input element lost selection
- if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.getNodeName())&&
- HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.getAttribute(HTML.ATTR_TYPE))
- &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null)) {
-
- selectionBuilder.setVisualElementSelection(visualDragElement);
- mouseDownSelectionFlag = true;
- }
- } else {
- selectionBuilder.setCaretAtMouse(mouseEvent);
- }
- switcher.stopActiveEditor();
- }
-
- public void mouseUp(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseUp"); //$NON-NLS-1$
- }
- if (mouseDownSelectionFlag) {
- mouseEvent.preventDefault();
- mouseEvent.stopPropagation();
- mouseDownSelectionFlag = false;
- }
- switcher.stopActiveEditor();
- }
-
- public void mouseClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
-
- if (visualNode != null) {
- if (!mouseUpSelectionReasonFlag) {
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseClick visualNode: " + visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- if (visualBuilder.isContentArea(visualNode)) {
- selectionBuilder.setClickContentAreaSelection();
- }
- } else {
- mouseUpSelectionReasonFlag = false;
- }
-
- if (visualBuilder.doToggle(VisualDomUtil.getTargetNode(mouseEvent))) {
- selectionBuilder.setClickContentAreaSelection();
- }
- }
- switcher.stopActiveEditor();
- }
-
- public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (visualNode != null) {
- if (!sourceBuilder.openBundleEditors(visualNode)) {
- sourceBuilder.openIncludeEditor(visualNode);
- }
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseDblClick visualNode: " + visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
- switcher.stopActiveEditor();
- }
-
- public void mouseMove(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (visualNode != null) {
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseMove visualNode: " + visualNode.getNodeName() + " (" + visualNode + ")");
- }
- visualBuilder.setMoveCursor(mouseEvent);
- }
- switcher.stopActiveEditor();
- }
-
- public void keyPress(nsIDOMKeyEvent keyEvent) {
- if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
- System.out.println("<<< keyPress type: " + keyEvent.getType() + " Ctrl: " + keyEvent.getCtrlKey() + " Shift: " + keyEvent.getShiftKey() + " CharCode: " + keyEvent.getCharCode() + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- switcher.stopActiveEditor();
- return;
- }
-
- visualEditor.hideResizer();
- switcher.stopActiveEditor();
-
-
- try {
- if (visualKeyHandler.keyPressHandler(keyEvent)) {
- switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
- // Edward
- sourceSelectionChanged(true);
- visualSelectionController.setCaretEnabled(true);
- switcher.stopActiveEditor();
- } else {
- //adding calls of core event handlers, for example 'CTR+H' or 'CTRL+M' event handler dialog
- Event keyboardEvent = new Event ();
- //widget where event occur
- keyboardEvent.widget = xulRunnerEditor.getBrowser();
-
- keyboardEvent.stateMask = (keyEvent.getAltKey() ? SWT.ALT : 0) | (keyEvent.getCtrlKey() ? SWT.CTRL : 0) | (keyEvent.getShiftKey() ? SWT.SHIFT : 0) | (keyEvent.getMetaKey() ? SWT.MOD1 : 0);
- keyboardEvent.x=0;
- keyboardEvent.y=0;
- keyboardEvent.type=SWT.KeyDown;
-
- if(keyEvent.getKeyCode()==0) {
-
- keyboardEvent.keyCode=(int)keyEvent.getCharCode();
- } else{
+ }
+
+ // INodeAdapter implementation
+ public boolean isAdapterForType(Object type) {
+ return type == this;
+ }
+ //FIX Fox JBIDE-1479 added by Max Areshkau
+ public void notifyChanged(final INodeNotifier notifier, final int eventType,final Object feature,final Object oldValue,final Object newValue, final int pos) {
+
+ //start job when we modify file in ui thread, without this code
+ //changes will be applied with 1 second delay
+ Display display = null;
+ if (PlatformUI.isWorkbenchRunning())
+ display= PlatformUI.getWorkbench().getDisplay();
+
+ if (display != null && (Thread.currentThread() == display.getThread())) {
+ notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
+ return;
+ }
+ //start job when we modify file in non ui thread
+ if(job!=null) {
+ job.cancel();
+ }
+
+ job = new UIJob("NotifyChangedJob"){
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ //we checks is job was canceled and if is it true we cancel job
+ if(monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
+ }
+ return Status.OK_STATUS;
+ }};
+ job.setPriority(Job.LONG);
+ job.schedule(1000L);
+ }
+
+ public void notifyChangedInUiThread(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int pos) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) {
+ printSourceEvent(notifier, eventType, feature, oldValue, newValue, pos);
+ }
+ if(visualBuilder==null) {
+ return;
+ }
+// visualBuilder.rebuildFlag = false;
+
+ switch (eventType) {
+ case INodeNotifier.CHANGE:
+ sourceChangeFlag = true;
+ int type = ((Node)notifier).getNodeType();
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ if (type == Node.TEXT_NODE) {
+ boolean update = visualBuilder.setText((Node)notifier);
+ visualEditor.showResizer();
+ //Added by Max Areshkau JBIDE-1554
+ if (!update) visualBuilder.updateNode((Node)notifier);
+ } else if (type == Node.COMMENT_NODE) {
+ if("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$
+ visualBuilder.setSelectionRectangle(null);
+ visualBuilder.updateNode((Node)notifier);
+ }
+ } else if (feature != null && ((Node)feature).getNodeType() == Node.ATTRIBUTE_NODE) {
+ if (newValue != null) {
+ String attrName = ((Attr)feature).getName();
+ if ((Attr)feature == lastRemovedAttr && !attrName.equals(lastRemovedAttrName)) {
+ lastRemovedAttr = null;
+ visualBuilder.removeAttribute((Element)notifier, lastRemovedAttrName);
+ }
+ visualBuilder.setAttribute((Element)notifier, ((Attr)feature).getName(), (String)newValue);
+ } else {
+ lastRemovedAttr = (Attr)feature;
+ lastRemovedAttrName = ((Attr)feature).getName();
+ visualBuilder.removeAttribute((Element)notifier, lastRemovedAttrName);
+ }
+ }
+ visualEditor.showResizer();
+ break;
+
+ case INodeNotifier.ADD:
+ //we should remove all parent nodes from vpe cash
+ visualBuilder.removeNode((Node)newValue);
+ break;
+
+ case INodeNotifier.REMOVE:
+ visualBuilder.stopToggle((Node)feature);
+ visualBuilder.removeNode((Node)feature);
+ break;
+
+ case INodeNotifier.STRUCTURE_CHANGED:
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ visualBuilder.updateNode((Node)notifier);
+ break;
+ case INodeNotifier.CONTENT_CHANGED:
+ if (!sourceChangeFlag) {
+ if (feature != null && ((Node)feature).getNodeType() == Node.TEXT_NODE) {
+ //if (((Node)notifier).getNodeName().equalsIgnoreCase("style")) {
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ visualBuilder.setText((Node)feature);
+ visualEditor.showResizer();
+ //}
+ }
+ } else {
+ sourceChangeFlag = false;
+ }
+ break;
+ }
+ switcher.stopActiveEditor();
+ }
+
+ // INodeSelectionListener implementation
+ public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ List<?> nodes = event.getSelectedNodes();
+ if (nodes != null && nodes.size() > 0) {
+ Node sourceNode = (Node)nodes.get(0);
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> nodeSelectionChanged sourceNode: " + sourceNode.getNodeName() + " " + event.getCaretPosition()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (event.getSource() instanceof IContentOutlinePage) {
+ sourceSelectionChanged();
+ }
+ }
+ switcher.stopActiveEditor();
+ }
+
+ // ITextSelectionListener implementation
+ //TODO Max Areshau looks like this method don't used
+ public void textSelectionChanged(TextSelectionChangedEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> textSelectionChanged " + event.getSource()); //$NON-NLS-1$
+ }
+// if (event.getSource() instanceof StyledText) {
+ sourceSelectionChanged();
+// }
+ switcher.stopActiveEditor();
+ }
+
+ // SelectionListener implementation
+ public void widgetSelected(SelectionEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> widgetSelected"); //$NON-NLS-1$
+ }
+ if (event.getSource() instanceof StyledText) {
+ sourceSelectionChanged();
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent event) {
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> widgetDefaultSelected"); //$NON-NLS-1$
+ }
+ }
+
+ public void sourceSelectionChanged() {
+ sourceSelectionChanged(false);
+ }
+
+ public void sourceSelectionChanged(boolean showCaret) {
+ Point range = sourceEditor.getTextViewer().getSelectedRange();
+ int anchorPosition = range.x;
+ int focusPosition = range.x + range.y;
+
+ boolean extendFlag = range.y != 0;
+ boolean reversionFlag = extendFlag && anchorPosition == VpeSelectionHelper.getCaretOffset(sourceEditor);
+ if (reversionFlag) {
+ anchorPosition = focusPosition;
+ focusPosition = range.x;
+ }
+
+ VpeTemplate template = TemplateManagingUtil
+ .getTemplateBySourceSelection(pageContext, focusPosition,
+ anchorPosition);
+
+ if (template instanceof ITemplateSelectionManager) {
+ ((ITemplateSelectionManager) template).setVisualSelectionBySource(
+ pageContext, visualSelectionController, focusPosition,
+ anchorPosition);
+ return;
+ }
+
+ Node focusNode = getSourceNodeAt(focusPosition);
+ if (focusNode == null) {
+ return;
+ }
+ int focusOffset = getSourceNodeOffset(focusNode, focusPosition, extendFlag && !reversionFlag);
+ Node anchorNode = null;
+ int anchorOffset = 0;
+ if (extendFlag) {
+ anchorNode = getSourceNodeAt(anchorPosition);
+ anchorOffset = getSourceNodeOffset(anchorNode, anchorPosition, reversionFlag);
+ } else {
+ anchorNode = focusNode;
+ anchorOffset = focusOffset;
+ }
+
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
+ System.out.println(" anchorNode: " + anchorNode.getNodeName() + " anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println(" focusNode: " + focusNode.getNodeName() + " focusOffset: " + focusOffset + " focusPosition: " + focusPosition); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ try{
+ if(anchorNode.getNodeType() == Node.TEXT_NODE || anchorNode.getNodeType() == Node.ATTRIBUTE_NODE){
+ String text;
+ if (anchorNode.getNodeType() == Node.TEXT_NODE) {
+ IndexedRegion region = (IndexedRegion)anchorNode;
+ text = sourceEditor.getTextViewer().getDocument().get(region.getStartOffset(), region.getEndOffset()-region.getStartOffset());
+ } else {
+ text = ((AttrImpl)anchorNode).getValueRegionText();
+ }
+ anchorOffset = TextUtil.visualPosition(text, anchorOffset);
+ }
+ if(focusNode.getNodeType() == Node.TEXT_NODE || focusNode.getNodeType() == Node.ATTRIBUTE_NODE){
+ IndexedRegion region = (IndexedRegion)focusNode;
+ String text;
+ if (focusNode.getNodeType() == Node.TEXT_NODE) {
+ text = sourceEditor.getTextViewer().getDocument().get(region.getStartOffset(), region.getEndOffset()-region.getStartOffset());
+ } else {
+ text = ((AttrImpl)focusNode).getValueRegionText();
+ }
+ focusOffset = TextUtil.visualPosition(text, focusOffset);
+ }
+ }catch(Exception ex){
+ VpePlugin.reportProblem(ex);
+ }
+
+ selectionBuilder.setVisualSelection(anchorNode, anchorOffset, focusNode, focusOffset, reversionFlag, showCaret);
+ }
+
+ public void sourceSelectionToVisualSelection(boolean showCaret) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ sourceSelectionChanged(showCaret);
+ switcher.stopActiveEditor();
+ }
+ // IModelLifecycleListener implementation
+ public void processPreModelEvent(ModelLifecycleEvent event) {
+ }
+
+ public void processPostModelEvent(ModelLifecycleEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ /* Added by Max Areshkau JBIDE-1457
+ * ModelLifecycleEvent.MODEL_RELEASED generated when model in
+ * model calls methods releaseFromRead() or releaseFromEdit().
+ * When editor is open he has only when href on model, so nothing can generated
+ * this event.When editor closes generation of this event depends from cantains
+ * any service href on model or not. It's can be a reason of problems
+ * on reopen file.
+ *
+ * We shouldn't call here rebuild dom.
+ */
+ if (event.getType() == ModelLifecycleEvent.MODEL_RELEASED) {
+ if (VpeDebug.PRINT_SOURCE_MODEL_LIFECYCLE_EVENT) {
+ System.out.println(">>> processPostModelEvent: " + event.toString()); //$NON-NLS-1$
+ }
+ visualBuilder.setSelectionRectangle(null);
+ IStructuredModel model = event.getModel();
+ model.removeModelLifecycleListener(this);
+ IDOMModel sourceModel = (IDOMModel)getModel();
+ sourceModel.addModelLifecycleListener(this);
+ bundle.clearAll();
+ bundle.refresh();
+ visualBuilder.setSelectionRectangle(null);
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ // JBIDE-1457
+// visualBuilder.rebuildDom(sourceDocument);
+// pageContext.fireTaglibsChanged();
+ }
+ switcher.stopActiveEditor();
+ }
+
+ // EditorDomEventListener implementation
+ public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = mutationEvent.getRelatedNode();
+ if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
+ sourceBuilder.addNode(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
+ visualBuilder.setSelectionRectangle(null);
+ sourceBuilder.removeNode(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void attrModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
+
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ sourceBuilder.setText(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ switcher.stopActiveEditor();
+ }
+
+ public void notifySelectionChanged(nsIDOMDocument doc, nsISelection selection, short reason) {
+ if (switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ mouseUpSelectionReasonFlag = (reason & nsISelectionListener.MOUSEUP_REASON) > 0;
+ if (mouseUpSelectionReasonFlag || reason == nsISelectionListener.NO_REASON || reason == nsISelectionListener.KEYPRESS_REASON || reason == nsISelectionListener.SELECTALL_REASON || (reason & nsISelectionListener.MOUSEDOWN_REASON) > 0) {
+ if (VpeDebug.PRINT_VISUAL_SELECTION_EVENT) {
+ System.out.println("<<< notifySelectionChanged: " + reason); //$NON-NLS-1$
+ }
+ selectionBuilder.setSelection(selection);
+ }
+ switcher.stopActiveEditor();
+ }
+ }
+
+
+ public void mouseDown(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ nsIDOMElement visualDragElement = selectionBuilder.getDragElement(mouseEvent);
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ System.out.println("<<< mouseDown targetNode: " + visualNode.getNodeName() + " (" + visualNode + ") selectedElement: " + (visualDragElement != null ? visualDragElement.getNodeName() + " (" + visualDragElement + ")" : null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+ mouseDownSelectionFlag = false;
+
+ if (visualDragElement != null) {
+
+ //we shouldn't change selection when we click on <input type="text" /> element,
+ //because if we change after resizing the input element lost selection
+ if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.getNodeName())&&
+ HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.getAttribute(HTML.ATTR_TYPE))
+ &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null)) {
+
+ selectionBuilder.setVisualElementSelection(visualDragElement);
+ mouseDownSelectionFlag = true;
+ }
+ } else {
+ selectionBuilder.setCaretAtMouse(mouseEvent);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void mouseUp(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseUp"); //$NON-NLS-1$
+ }
+ if (mouseDownSelectionFlag) {
+ mouseEvent.preventDefault();
+ mouseEvent.stopPropagation();
+ mouseDownSelectionFlag = false;
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void mouseClick(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+
+ if (visualNode != null) {
+ if (!mouseUpSelectionReasonFlag) {
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseClick visualNode: " + visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ if (visualBuilder.isContentArea(visualNode)) {
+ selectionBuilder.setClickContentAreaSelection();
+ }
+ } else {
+ mouseUpSelectionReasonFlag = false;
+ }
+
+ if (visualBuilder.doToggle(VisualDomUtil.getTargetNode(mouseEvent))) {
+ selectionBuilder.setClickContentAreaSelection();
+ }
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ if (visualNode != null) {
+ if (!sourceBuilder.openBundleEditors(visualNode)) {
+ sourceBuilder.openIncludeEditor(visualNode);
+ }
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseDblClick visualNode: " + visualNode.getNodeName() + " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void mouseMove(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ if (visualNode != null) {
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseMove visualNode: " + visualNode.getNodeName() + " (" + visualNode + ")");
+ }
+ visualBuilder.setMoveCursor(mouseEvent);
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void keyPress(nsIDOMKeyEvent keyEvent) {
+ if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
+ System.out.println("<<< keyPress type: " + keyEvent.getType() + " Ctrl: " + keyEvent.getCtrlKey() + " Shift: " + keyEvent.getShiftKey() + " CharCode: " + keyEvent.getCharCode() + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ switcher.stopActiveEditor();
+ return;
+ }
+
+ visualEditor.hideResizer();
+ switcher.stopActiveEditor();
+
+
+ try {
+ if (visualKeyHandler.keyPressHandler(keyEvent)) {
+ switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
+ // Edward
+ sourceSelectionChanged(true);
+ visualSelectionController.setCaretEnabled(true);
+ switcher.stopActiveEditor();
+ } else {
+ //adding calls of core event handlers, for example 'CTR+H' or 'CTRL+M' event handler dialog
+ Event keyboardEvent = new Event ();
+ //widget where event occur
+ keyboardEvent.widget = xulRunnerEditor.getBrowser();
+
+ keyboardEvent.stateMask = (keyEvent.getAltKey() ? SWT.ALT : 0) | (keyEvent.getCtrlKey() ? SWT.CTRL : 0) | (keyEvent.getShiftKey() ? SWT.SHIFT : 0) | (keyEvent.getMetaKey() ? SWT.MOD1 : 0);
+ keyboardEvent.x=0;
+ keyboardEvent.y=0;
+ keyboardEvent.type=SWT.KeyDown;
+
+ if(keyEvent.getKeyCode()==0) {
+
+ keyboardEvent.keyCode=(int)keyEvent.getCharCode();
+ } else{
keyboardEvent.keyCode=(int)keyEvent.getKeyCode();
}
-
+
// JBIDE-1627
List<KeyStroke> possibleKeyStrokes = WorkbenchKeyboard.generatePossibleKeyStrokes(keyboardEvent);
IWorkbench iWorkbench = VpePlugin.getDefault().getWorkbench();
@@ -911,1534 +911,1534 @@
}
}
}
- }
- //sends xulrunner event to eclipse environment
- getXulRunnerEditor().getBrowser().notifyListeners(keyboardEvent.type, keyboardEvent);
-
- }
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- visualRefresh();
- }
-
- }
-
- public void elementResized(nsIDOMElement element, int resizerConstrains, int top, int left, int width, int height) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- visualEditor.hideResizer();
- switcher.stopActiveEditor();
-
- visualBuilder.resize(element, resizerConstrains, top, left, width, height);
- sourceSelectionChanged();
- }
-
- public void dragGesture(nsIDOMEvent domEvent) {
-
- nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent) domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
- boolean canDragFlag = canInnerDrag(mouseEvent);
- //start drag sessionvpe-element
- if(canDragFlag) {
- startDragSession(domEvent);
- }
- }
-
- private void createMenuForNode(Node node, MenuManager manager) {
- createMenuForNode(node, manager, false);
- }
-
- private void createMenuForNode(Node node, MenuManager manager, boolean topLevelFlag) {
- NodeActionManager.setTextNodeSplitter(null);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- VpeElementMapping elementMapping = (VpeElementMapping)domMapping.getNodeMapping(node);
- if (elementMapping != null && elementMapping.getTemplate() != null) {
- manager.add(new VpeAction("<"+node.getNodeName()+"> Attributes", node) { //$NON-NLS-1$ //$NON-NLS-2$
- public void run() {
- showProperties(actionNode);
- }
- });
-
- if (!topLevelFlag) {
- manager.add(new VpeAction("Select This Tag", node) { //$NON-NLS-1$
- public void run() {
- selectionBuilder.setVisualSelection(actionNode,0,actionNode,0,false,true);
-
- }
- });
- }
- Node parent = node.getParentNode();
- if(parent != null && parent.getNodeType() == Node.ELEMENT_NODE){
- MenuManager menuManager = new MenuManager("Parent Tag"); //$NON-NLS-1$
- menuManager.setParent(manager);
- manager.add(menuManager);
- createMenuForNode(parent, menuManager);
- }
-
- manager.add(new Separator());
- }
- }
- NodeActionManager actionManager = new NodeActionManager(getModel(), null);
-
- if (node.getNodeType() == Node.TEXT_NODE) {
- Point range = sourceEditor.getTextViewer().getSelectedRange();
- TextNodeSplitterImpl splitter = new TextNodeSplitterImpl(range, (Text)node);
- NodeActionManager.setTextNodeSplitter(splitter);
- }
-
-
- if (actionManager != null) {
- StructuredSelection structuredSelection = new StructuredSelection(node);
- actionManager.fillContextMenuForVpe(manager, structuredSelection);
-
- }
-
- IContributionItem[] items = manager.getItems();
-
- for(int i=0;i< items.length;i++){
- if(items[i] instanceof MenuManager){
- MenuManager mm = (MenuManager)items[i];
- if(NodeActionManager.INSERT_AROUND_MENU.equals(mm.getMenuText())){
- listenContextMenu(mm, (IndexedRegion)node, AROUND_MENU);
- }else if(NodeActionManager.INSERT_BEFORE_MENU.equals(mm.getMenuText())){
- listenContextMenu(mm, (IndexedRegion)node, BEFORE_MENU);
- }else if(NodeActionManager.INSERT_AFTER_MENU.equals(mm.getMenuText())){
- listenContextMenu(mm, (IndexedRegion)node, AFTER_MENU);
- }
- }
- }
-
- manager.add(new Separator());
-
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- VpeElementMapping elementMapping = (VpeElementMapping)domMapping.getNodeMapping(node);
- if (elementMapping != null && elementMapping.getTemplate() != null && elementMapping.getTemplate().getType() == VpeHtmlTemplate.TYPE_ANY) {
- final VpeTemplate selectedTemplate = elementMapping.getTemplate();
- manager.add(new VpeAction("Template", node) { //$NON-NLS-1$
- public void run() {
- boolean isCorrectNS = pageContext.isCorrectNS(actionNode);
- VpeAnyData data = null;
- if (isCorrectNS) {
- data = selectedTemplate.getAnyData();
- data.setUri(pageContext.getSourceTaglibUri(actionNode));
- data.setName(actionNode.getNodeName());
- }
- data = editAnyData(sourceEditor, isCorrectNS, data);
- if (data != null && data.isChanged()) templateManager.setAnyTemplate(data);
- }
- });
-
- manager.add(new Separator());
- }
-
-
- manager.add(new VpeTextOperationAction("Cut", ActionFactory.CUT.getId(), (IndexedRegion)node)); //$NON-NLS-1$
- manager.add(new VpeTextOperationAction("Copy", ActionFactory.COPY.getId(), (IndexedRegion)node)); //$NON-NLS-1$
- manager.add(new VpeTextOperationAction("Paste", ActionFactory.PASTE.getId(), (IndexedRegion)node)); //$NON-NLS-1$
- }else if(node.getNodeType() == Node.TEXT_NODE){
- manager.add(new Action("Cut") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.CUT.getId()).run();
- }
- });
- manager.add(new Action("Copy") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.COPY.getId()).run();
- }
- });
- manager.add(new Action("Paste") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.PASTE.getId()).run();
- }
- });
- }
- manager.add(new Separator());
-
- if (actionManager != null) {
- StructuredSelection structuredSelection = node.getNodeType() == Node.ELEMENT_NODE ? new StructuredSelection(node) : null;
- actionManager.addContextMenuForVpe(manager, structuredSelection);
- }
-
- if(node.getNodeType() == Node.ELEMENT_NODE){
- boolean stripEnable = false;
- NodeImpl impl = (NodeImpl)node;
- if(impl.isContainer()){
- NodeList list = impl.getChildNodes();
- if(list.getLength() > 0){
- if(list.getLength() == 1){
- Node child = list.item(0);
- if(child.getNodeType() == Node.TEXT_NODE){
- if("".equals(child.getNodeValue().trim()))stripEnable = false; //$NON-NLS-1$
- else stripEnable = true;
- }else stripEnable = true;
- }else stripEnable = true;
- }
- }
- if(stripEnable)
- manager.add(new VpeAction("Strip Tag", node) { //$NON-NLS-1$
- public void run() {
- Node parent = actionNode.getParentNode();
- if(parent != null){
- int index = ((NodeImpl)actionNode).getIndex();
- parent.removeChild(actionNode);
- NodeList children = actionNode.getChildNodes();
- int lengh = children.getLength();
- Node child;
- for(int i=0; i < lengh; i++){
- child = children.item(0);
- actionNode.removeChild(child);
- insertNode(parent, child, index++);
- }
- }
- }
-
- private void insertNode(Node parent, Node node, int index){
- Node oldNode=null;
- int childSize = parent.getChildNodes().getLength();
-
- if(index <= (childSize-1))oldNode = parent.getChildNodes().item(index);
- if(oldNode != null)parent.insertBefore(node, oldNode);
- else parent.appendChild(node);
- }
- });
- }
- if(node.getNodeType() == Node.TEXT_NODE){
- manager.add(new Action("Delete") { //$NON-NLS-1$
- public void run() {
- sourceEditor.getAction(ActionFactory.DELETE.getId()).run();
- }
- });
- }
-
- if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_SOURCE) {
- manager.add(new Action("Dump Source") { //$NON-NLS-1$
- public void run() {
- DOMTreeDumper dumper = new DOMTreeDumper(VpeDebug.VISUAL_DUMP_PRINT_HASH);
- dumper.dumpToStream(System.out, visualEditor.getDomDocument());
- }
- });
- }
-
- if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_MAPPING) {
- manager.add(new Action("Dump Mapping") { //$NON-NLS-1$
- public void run() {
- printMapping();
- }
- });
- }
-
- if (VpeDebug.VISUAL_CONTEXTMENU_TEST) {
- manager.add(new VpeAction("Test", node) { //$NON-NLS-1$
- public void run() {
- test(actionNode);
- }
- });
- }
- }
-
- /**
- * Calls when on when browser receive context menu event.
- *
- * @param contextFlags -not used in this function, just for becouse this parametr
- * exist in nsIContextMenuListener
- * @param event event from browser used here
- * @param node where this event are occur
- */
- public void onShowContextMenu(long contextFlags, nsIDOMEvent event, nsIDOMNode node) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
-
- if (visualNode != null) {
- Node selectedSourceNode = null;
- selectedSourceNode = selectionBuilder.setContextMenuSelection(visualNode);
- if (selectedSourceNode != null) {
-
- MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
- final Menu contextMenu = menuManager.createContextMenu(visualEditor.getControl());
- contextMenu.addMenuListener(
- new MenuListener(){
- Menu menu = contextMenu;
- public void menuHidden(MenuEvent e) {
- Display.getCurrent().asyncExec(
- new Runnable() {
- public void run() {
- menu.dispose();
- }
- }
- );
- }
- public void menuShown(MenuEvent e) {
- }
- }
- );
- createMenuForNode(selectedSourceNode, menuManager, true);
-
- contextMenu.setVisible(true);
-
- }
- }
- }
-
-
- private VpeAnyData editAnyData(StructuredTextEditor sourceEditor, boolean isCorrectNS, VpeAnyData data) {
- Shell shell = sourceEditor.getEditorPart().getSite().getShell();
- if (isCorrectNS) {
- VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
- editDialog.open();
- } else {
- MessageBox message = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
- message.setMessage(VpeUIMessages.NAMESPACE_NOT_DEFINED);
- message.open();
- }
- return data;
- }
-
- // VpeTemplateListener implementation
- public void templateReloaded() {
- visualRefresh();
- }
-
-
- public void visualRefresh() {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- visualRefreshImpl();
-
- switcher.stopActiveEditor();
- }
-
- void visualRefreshImpl() {
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- IDOMModel sourceModel = (IDOMModel)getModel();
- if (sourceModel != null) {
- IDOMDocument sourceDocument = sourceModel.getDocument();
- visualBuilder.rebuildDom(sourceDocument);
- } else {
- visualBuilder.rebuildDom(null);
- }
- }
-
- public void preLongOperation() {
- switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
- }
-
- public void postLongOperation() {
- switcher.stopActiveEditor();
- visualRefresh();
- }
-
- // for debug
- private void printSourceEvent(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int pos) {
- System.out.println(">>> eventType: " + INodeNotifier.EVENT_TYPE_STRINGS[eventType] + " pos: " + pos + " notifier: " + ((Node)notifier).getNodeName() + " hashCode: " + notifier.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- if (feature != null) {
- if (feature instanceof Node) {
- System.out.println(" feature: " + ((Node)feature).getNodeType() + " " + ((Node)feature).getNodeName() + " hashCode: " + feature.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else {
- System.out.println(" feature: " + feature); //$NON-NLS-1$
- }
- }
- if (oldValue != null) {
- if (oldValue instanceof Node) {
- System.out.println(" oldValue: " + ((Node)oldValue).getNodeName() + " hashCode: " + oldValue.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
- }
- }
- if (newValue != null) {
- if (newValue instanceof Node) {
- System.out.println(" newValue: " + ((Node)newValue).getNodeName() + " hashCode: " + newValue.hashCode() + " " + ((Node)newValue).getNodeType()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else {
- System.out.println(" newValue: " + newValue); //$NON-NLS-1$
- }
- }
- }
-
- private void printVisualEvent(nsIDOMEvent event) {
- System.out.print("<<< " + event.getType()); //$NON-NLS-1$
-
- if (event instanceof nsIDOMMutationEvent) {
- nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent)event;
-
- System.out.print(" EventPhase: " + mutationEvent.getEventPhase()); //$NON-NLS-1$
-
- nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
- System.out.print(" RelatedNode: " + (relatedNode == null ? null : relatedNode.getNodeName())); //$NON-NLS-1$
-
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- String name = targetNode != null ? targetNode.getNodeName() : null;
- System.out.print(" TargetNode: " + name + " (" + targetNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- System.out.print(" PrevValue: " + mutationEvent.getPrevValue().trim()); //$NON-NLS-1$
- System.out.print(" NewValue: " + mutationEvent.getNewValue().trim()); //$NON-NLS-1$
- }
- System.out.println();
- }
-
- private void printMapping() {
- domMapping.printMapping();
- }
-
- private class ActiveEditorSwitcher {
- private static final int ACTIVE_EDITOR_CANNOT = 0;
- private static final int ACTIVE_EDITOR_NONE = 1;
- private static final int ACTIVE_EDITOR_SOURCE = 2;
- private static final int ACTIVE_EDITOR_VISUAL = 3;
-
- private int type = ACTIVE_EDITOR_CANNOT;
-
- private void initActiveEditor() {
- type = ACTIVE_EDITOR_NONE;
- }
-
- private void destroyActiveEditor() {
- type = ACTIVE_EDITOR_CANNOT;
- }
-
- private boolean startActiveEditor(int newType) {
- if (type == ACTIVE_EDITOR_NONE) {
- if( newType == ACTIVE_EDITOR_SOURCE &&
- editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
- return false;
- }
- type = newType;
- return true;
- } else {
- return false;
- }
- }
-
- private void stopActiveEditor() {
- onRefresh();
- type = ACTIVE_EDITOR_NONE;
- }
- }
-
- private void showProperties(Node node){
- ExtendedProperties p = createExtendedProperties(node);
- if(p != null) ExtendedPropertiesWizard.run(p);
- }
-
- ExtendedProperties createExtendedProperties(Node node) {
- try {
- Class c = ModelFeatureFactory.getInstance().getFeatureClass("org.jboss.tools.jst.jsp.outline.VpeProperties"); //$NON-NLS-1$
- return (ExtendedProperties)c.getDeclaredConstructor(new Class[]{Node.class}).newInstance(new Object[]{node});
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- return null;
- }
- }
-
-
- private void test(Node node) {
- }
-
- void refreshBundleValues() {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- if (bundle != null) {
- bundle.refresh();
- if (pageContext != null) {
- pageContext.refreshBundleValues();
- }
- }
- switcher.stopActiveEditor();
- }
-
- void refreshTemplates() {
- if (includeList.includesRefresh()) {
- visualRefresh();
- }
- if (templateManager != null) {
- templateManager.reload();
- }
- if (bundle != null) {
- bundle.refresh();
- if (pageContext != null) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- pageContext.refreshBundleValues();
- switcher.stopActiveEditor();
- }
- }
- }
-
- // implements XModelTreeListener
- public void nodeChanged(XModelTreeEvent event) {
- visualRefresh();
- }
-
- public void structureChanged(XModelTreeEvent event) {
- }
-
- private Node getSourceNodeAt(int offset) {
- if (sourceEditor != null && getModel() != null) {
- IndexedRegion node = getModel().getIndexedRegion(offset);
- if (node instanceof IDOMNode) {
-
- VpeElementMapping elementMapping = domMapping
- .getNearElementMapping((IDOMNode) node);
-
- if (elementMapping != null) {
-
- if (node instanceof IDOMElement) {
- IDOMElement element = (IDOMElement) node;
-
- if (offset < element.getEndStartOffset()) {
- NamedNodeMap attrs = element.getAttributes();
- if (attrs != null) {
- for (int i = 0; i < attrs.getLength(); i++) {
- if (attrs.item(i) instanceof AttrImpl) {
- AttrImpl attr = (AttrImpl) attrs
- .item(i);
- if (getSourceAttributeOffset(attr,
- offset) != -1) {
-
- String[] atributeNames = elementMapping
- .getTemplate()
- .getOutputAtributeNames();
- if (atributeNames != null
- && atributeNames.length > 0
- && attr
- .getName()
- .equalsIgnoreCase(
- atributeNames[0])) {
- return attr;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (node == null) {
- node = getModel().getIndexedRegion(offset - 1);
- }
- if (node instanceof Node) {
- return (Node) node;
- }
- }
- return null;
- }
-
- private int getSourceNodeOffset(Node node, int pos, boolean endFlag) {
- if (node == null) return 0;
- int start = ((IndexedRegion)node).getStartOffset();
- int end = ((IndexedRegion)node).getEndOffset();
-
- switch (node.getNodeType()) {
- case Node.ATTRIBUTE_NODE:
- if (node instanceof AttrImpl) {
- return getSourceAttributeOffset((AttrImpl)node, pos);
- }
- case Node.TEXT_NODE:
- if (pos < start) {
- return 0;
- } else if (pos > end) {
- return end - start;
- } else {
- return pos - start;
- }
- case Node.COMMENT_NODE:
- if (pos > end) {
- pos = end;
- }
- int offset = pos - start - 4;
- return offset < 0 ? 0 : offset;
- case Node.ELEMENT_NODE:
- ElementImpl element = (ElementImpl)node;
- if (element.isContainer()) {
- if (pos < element.getStartEndOffset()) {
- return 0;
- } else {
- return 1;
- }
- } else {
- return endFlag ? 1 : 0;
- }
- default:
- return endFlag ? 1 : 0;
- }
- }
-
- private int getSourceAttributeOffset(AttrImpl attr, int pos) {
- if (attr.getValueRegion() != null) {
- int start = attr.getValueRegionStartOffset();
- String value = attr.getValueRegionText();
- int len = value.length();
- if (pos >= start && pos <= start + len) {
- int offset = pos - start;
- if (len > 1 && value.charAt(0) == '"' && value.charAt(len - 1) == '"') {
- if (offset <= 0 || offset >= len) {
- return -1;
- }
- offset--;
- }
- return offset;
- }
- }
- return -1;
- }
-
- private int getSourceNodeOffset1(Node node, int pos, boolean endFlag) {
- if (node == null) return 0;
- int start = ((IndexedRegion)node).getStartOffset();
- int end = ((IndexedRegion)node).getEndOffset();
-
- switch (node.getNodeType()) {
- case Node.ATTRIBUTE_NODE:
- if (node instanceof AttrImpl) {
- AttrImpl attr = (AttrImpl)node;
- start = attr.getValueRegionStartOffset();
- end = start + attr.getValueRegion().getLength();
- int ret = 0;
- if (pos > end) {
- ret = end - start;
- } else {
- ret = pos - start;
- }
- if (ret > 0 && attr.getValueRegionText().charAt(0) == '"') {
- ret--;
- }
- return ret;
- }
- case Node.TEXT_NODE:
- if (pos < start) {
- return 0;
- } else if (pos > end) {
- return end - start;
- } else {
- return pos - start;
- }
- case Node.COMMENT_NODE:
- if (pos > end) {
- pos = end;
- }
- int offset = pos - start - 4;
- return offset < 0 ? 0 : offset;
- case Node.ELEMENT_NODE:
- ElementImpl element = (ElementImpl)node;
- if (element.isContainer()) {
- if (pos < element.getStartEndOffset()) {
- return 0;
- } else if (pos < element.getStartEndOffset()) {
- return 1;
- } else if (pos == element.getStartEndOffset()) {
- return 2;
- }
- } else {
- return endFlag ? 1 : 0;
- }
- default:
- return endFlag ? 1 : 0;
- }
- }
-
- private void listenContextMenu(MenuManager manager, IndexedRegion region, int type){
- MenuManager mm = new MyMenuManager("From Palette",true); //$NON-NLS-1$
- manager.add(mm);
- manager.addMenuListener(new VpeMenuListener(mm, region, type));
- }
-
- class VpeMenuListener implements IMenuListener{
- private MenuManager manager;
- private IndexedRegion region;
- private int type;
- private boolean loaded=false;
-
- public VpeMenuListener(MenuManager manager, IndexedRegion region, int type){
- this.manager = manager;
- this.region = region;
- this.type = type;
- }
- public void menuAboutToShow(IMenuManager m) {
- if(loaded)return;
- loaded=true;
- fillContextMenuFromPalette(manager, region, type);
- manager.getParent().update(true);
- }
- }
- private MenuManager fillContextMenuFromPalette(MenuManager manager, IndexedRegion region, int type){
- XModelObject model = ModelUtilities.getPreferenceModel().getByPath("%Palette%"); //$NON-NLS-1$
-
- XModelObject[] folders = model.getChildren();
- for(int i=0;i<folders.length;i++){
- if ("yes".equals(folders[i].getAttributeValue("hidden"))) continue; //$NON-NLS-1$ //$NON-NLS-2$
- MenuManager mm = new MenuManager(folders[i].getAttributeValue("name")); //$NON-NLS-1$
- manager.add(mm);
- fillPaletteFolder(mm, region, folders[i], type);
- }
- return manager;
- }
-
- private void fillPaletteFolder(MenuManager menu, IndexedRegion region, XModelObject folder, int type){
- XModelObject[] groups = folder.getChildren();
- for(int i=0;i<groups.length;i++){
- if ("yes".equals(groups[i].getAttributeValue("hidden"))) continue; //$NON-NLS-1$ //$NON-NLS-2$
- MenuManager mm = new MenuManager(groups[i].getAttributeValue("name")); //$NON-NLS-1$
- menu.add(mm);
- fillPaletteGroup(mm, region, groups[i], type);
- }
- }
-
- private void fillPaletteGroup(MenuManager menu, IndexedRegion region, XModelObject group, int type){
- XModelObject[] items = group.getChildren();
- String endText;
-
- for(int i=0;i<items.length;i++){
- if ("yes".equals(items[i].getAttributeValue("hidden"))) continue; //$NON-NLS-1$ //$NON-NLS-2$
- endText = items[i].getAttributeValue("end text"); //$NON-NLS-1$
-
- if(type == AROUND_MENU && (endText == null || "".equals(endText))) continue; //$NON-NLS-1$
- createInsertAction(menu, region, items[i], type);
- }
- }
-
- private void createInsertAction(MenuManager menu, IndexedRegion region, XModelObject item, int type){
-
-
- XModelObject parent = item.getParent();
- String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
- String[] texts = new String[]{"<"+tagName+">"}; //$NON-NLS-1$ //$NON-NLS-2$
- if(tagName.indexOf("taglib") < 0) //$NON-NLS-1$
- PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagName, uri, defaultPrefix);
- tagName = texts[0];
-
- menu.add(new InsertAction(tagName, region, item, type));
- }
-
- class InsertAction extends Action{
- private XModelObject item;
- private int type;
- private IndexedRegion region;
-
- public InsertAction(String title, IndexedRegion region, XModelObject item, int type){
- super(title);
- this.item = item;
- this.type = type;
- this.region = region;
- }
- public void run(){
- try {
- String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
-
- XModelObject parent = item.getParent();
- String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String libraryVersion = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- VpeSelectionProvider selProvider = new VpeSelectionProvider(region);
-
- String startText = "" + item.getAttributeValue("start text"); //$NON-NLS-1$ //$NON-NLS-2$
- String endText = "" + item.getAttributeValue("end text"); //$NON-NLS-1$ //$NON-NLS-2$
- if(type == AROUND_MENU){
- }else if(type == BEFORE_MENU){
- selProvider = new VpeSelectionProvider(region.getStartOffset());
- }else if(type == AFTER_MENU){
- selProvider = new VpeSelectionProvider(region.getEndOffset());
- }
-
- Properties p = new Properties();
- p.setProperty("tag name", tagName); //$NON-NLS-1$
- p.setProperty("start text", startText); //$NON-NLS-1$
- p.setProperty("end text", endText); //$NON-NLS-1$
- p.setProperty("automatically reformat tag body", "" + item.getAttributeValue("automatically reformat tag body")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- p.setProperty(URIConstants.LIBRARY_URI, uri);
- p.setProperty(URIConstants.LIBRARY_VERSION, libraryVersion);
- String addTaglib = item.getParent().getAttributeValue(TLDToPaletteHelper.ADD_TAGLIB);
- p.setProperty(URIConstants.DEFAULT_PREFIX, defaultPrefix);
- p.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, addTaglib);
- if(((Node)region).getNodeType() == Node.ELEMENT_NODE)
- p.put("selectionProvider", selProvider); //$NON-NLS-1$
- PaletteInsertHelper.insertIntoEditor(sourceEditor.getTextViewer(), p);
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- }
-
- }
-
- }
-
- class VpeSelectionProvider implements ISelectionProvider{
- VpeSelection selection;
-
- public VpeSelectionProvider(IndexedRegion region){
- selection = new VpeSelection(region);
- }
- public VpeSelectionProvider(int position){
- selection = new VpeSelection(position);
- }
- public VpeSelectionProvider(int offset, int length){
- selection = new VpeSelection(offset, length);
- }
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- }
- public ISelection getSelection() {
- return selection;
- }
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
-
- }
- public void setSelection(ISelection selection) {
- }
- }
-
- class VpeSelection implements ITextSelection{
- String text=""; //$NON-NLS-1$
- int offset, length;
-
- public VpeSelection(int position){
- offset = position;
- length = 0;
- }
-
- public VpeSelection(int offset, int length){
- this.offset = offset;
- this.length = length;
- if (length > 0) {
- try{
- text = sourceEditor.getTextViewer().getDocument().get(offset, length);
- }catch(Exception ex){
- VpePlugin.reportProblem(ex);
- }
- }
- }
-
- public VpeSelection(IndexedRegion region){
- offset = region.getStartOffset();
- length = region.getEndOffset() - offset;
- try{
- text = sourceEditor.getTextViewer().getDocument().get(offset, length);
- }catch(Exception ex){
- VpePlugin.reportProblem(ex);
- }
- }
-
- public int getEndLine() {
- return 0;
- }
- public int getLength() {
- return length;
- }
- public int getOffset() {
- return offset;
- }
- public int getStartLine() {
- return 0;
- }
- public String getText() {
- return text;
- }
- public boolean isEmpty() {
- return false;
- }
-}
-
- class VpeAction extends Action{
- public Node actionNode;
- public VpeAction(String name, Node node){
- super(name);
- this.actionNode = node;
- }
- }
-
- class VpeTextOperationAction extends Action{
- private String id;
- private IndexedRegion region;
- public VpeTextOperationAction(String name, String id, IndexedRegion region){
- super(name);
- this.id = id;
- this.region = region;
- }
- public void run(){
- sourceEditor.getSelectionProvider().setSelection(new VpeSelection(region));
- sourceEditor.getAction(id).run();
- }
- }
-
- public void refreshExternalLinks() {
- pageContext.getVisualBuilder().refreshExternalLinks();
- }
-
- public IPath getPath() {
- if (editPart != null) {
- IEditorInput input = editPart.getEditorInput();
- if (input != null && input instanceof IFileEditorInput) {
- return ((IFileEditorInput)input).getFile().getFullPath();
- }
- }
- return null;
- }
-
- public void changed(Object source) {
- if(cssReferenceListListener == source) {
- pageContext.getVisualBuilder().refreshExternalLinks();
- } else if (absoluteFolderReferenceListListener == source ||
- relativeFolderReferenceListListener == source ||
- taglibReferenceListListener == source) {
- visualRefresh();
- }
- }
-
- public void dragEnter(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<< DragEnter"); //$NON-NLS-1$
- }
- }
-
- public void dragExit(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<< dragExit"); //$NON-NLS-1$
- }
- // TODO Sergey Vasilyev figure out with drag caret
-// xulRunnerEditor.hideDragCaret();
- }
-
- public void dragOver(nsIDOMEvent event) {
-
- visualBuilder.getDnd().dragOver(event, this);
-
- }
-
- public void _dragOver(nsIDOMEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<< dragOver"); //$NON-NLS-1$
- }
-
-// browser.computeDropPosition(event);
-
- boolean canDrop = !xulRunnerEditor.isMozillaDragFlavor();
- if (canDrop) {
- Clipboard clipboard = new Clipboard(Display.getCurrent());
- canDrop = clipboard.getContents(ModelTransfer.getInstance()) != null;
- }
- if (canDrop) {
- canDrop = VpeDndUtil.isDropEnabled((IModelObjectEditorInput)sourceEditor.getEditorInput());
- }
- if (canDrop) {
- VpeVisualCaretInfo caretInfo = selectionBuilder.getVisualCaretInfo(event);
- canDrop = caretInfo.exist();
- if (canDrop) {
- caretInfo.showCaret();
- } else {
- caretInfo.hideCaret();
- }
- }
- if (!canDrop) {
- event.stopPropagation();
- event.preventDefault();
- }
- switcher.stopActiveEditor();
- }
-
- public void drop(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<< outerDrop"); //$NON-NLS-1$
- }
- event.preventDefault();
- }
-
- public boolean canInnerDrag(nsIDOMMouseEvent event) {
- onHideTooltip();
-
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
- }
- if (innerDragInfo != null) {
- innerDragInfo.Release();
- innerDragInfo = null;
- }
- boolean canDrag = false;
- VpeVisualInnerDragInfo dragInfo = selectionBuilder.getInnerDragInfo(event);
- if (dragInfo != null) {
- nsIDOMNode dragNode = dragInfo.getNode();
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- switch (dragNode.getNodeType()) {
- case nsIDOMNode.ELEMENT_NODE:
- canDrag = visualBuilder.canInnerDrag((nsIDOMElement)dragNode);
- case nsIDOMNode.TEXT_NODE:
- canDrag = visualBuilder.isTextEditable(dragNode);
- }
- if (canDrag) {
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder.getSourceInnerDragInfo(dragInfo);
- if (sourceInnerDragInfo.getNode() != null) {
- innerDragInfo = dragInfo;
- InnerDragBuffer.object = sourceInnerDragInfo.getNode();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- InnerDragBuffer.object = null;
- }
- });
- } else {
- canDrag = false;
- }
- }
- if (!canDrag) {
- dragInfo.Release();
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrag: " + canDrag); //$NON-NLS-1$
- }
- return canDrag;
- }
-
- VpeDropWindow dropWindow = null;
-
- public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
- onHideTooltip();
-
- if(dropWindow.active) {
- if(!event.getAltKey()) {
- dropWindow.close();
- } else {
- return null;
- }
- }
- if(event.getAltKey()) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if(sourceNode != null) {
- dropWindow.active = true;
- dropWindow.setEventPosition(event.getScreenX(), event.getScreenY());
- dropWindow.setInitialTargetNode(sourceNode);
- dropWindow.open();
- event.stopPropagation();
- event.preventDefault();
- return null;
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
- }
- boolean canDrop = false;;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
- if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print(" x: " + visualDropInfo.getMouseX() + " y: " + visualDropInfo.getMouseY() + //$NON-NLS-1$ //$NON-NLS-2$
- " container: " + visualDropInfo.getDropContainer().getNodeName() + //$NON-NLS-1$
- "(" + visualDropInfo.getDropContainer() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " parent: " + visualDropInfo.getDropContainer().getParentNode().getNodeName() + //$NON-NLS-1$
- "(" + visualDropInfo.getDropContainer().getParentNode() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " offset: " + visualDropInfo.getDropOffset()); //$NON-NLS-1$
- }
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder.getSourceInnerDragInfo(innerDragInfo);
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceInnerDragInfo.getNode(), visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder.getInnerDropInfo(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
- }
- }
- visualDropInfo.Release();
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
- }
-
- public void innerDrop(nsIDOMMouseEvent event) {
- onHideTooltip();
-
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
- }
- if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print(" container: " + visualDropInfo.getDropContainer().getNodeName() + //$NON-NLS-1$
- "(" + visualDropInfo.getDropContainer() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " offset: " + visualDropInfo.getDropOffset()); //$NON-NLS-1$
- }
-
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder.getSourceInnerDragInfo(innerDragInfo);
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceInnerDragInfo.getNode(), visualDropInfo, true);
- if(sourceDropInfo.canDrop()){
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder.getInnerDropInfo(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(newVisualDropInfo, visualDropInfo);
- sourceDropInfo.setTop(visualDropInfo.getMouseY());
- sourceDropInfo.setLeft(visualDropInfo.getMouseX());
- visualBuilder.innerDrop(sourceInnerDragInfo, sourceDropInfo);
- if (innerDragInfo != null) {
- innerDragInfo.Release();
- innerDragInfo = null;
- }
- }
- }
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println();
- }
- }
-
- public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
- InnerDragBuffer.object = null;
- onHideTooltip();
-
- if(dropWindow.active) {
- if(!mouseEvent.getAltKey()) {
- dropWindow.close();
- } else {
- return new MozillaDropInfo(false, null, 0);
- }
- }
- if(mouseEvent.getAltKey()) {
- nsIDOMEvent event = (nsIDOMEvent) mouseEvent.queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
- nsIDOMNode visualNode = (nsIDOMNode) event.getTarget().queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if(sourceNode != null) {
- if(ModelTransfer.MODEL.equals(flavor)){ //$NON-NLS-1$
-// XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
-// InnerDragBuffer.object = object;
- } else {
- dropWindow.flavor = flavor;
- }
- dropWindow.active = true;
- dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent.getScreenY());
- dropWindow.setInitialTargetNode(sourceNode);
- dropWindow.open();
- mouseEvent.stopPropagation();
- mouseEvent.preventDefault();
- return new MozillaDropInfo(false, null, 0);
- }
- }
- boolean canDrop = false;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
-
- if(MODEL_FLAVOR.equals(flavor)){
- XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
- if(object.getFileType() == XModelObject.FILE && !TLDUtil.isTaglib(object)) {
- IFile f = (IFile)EclipseResourceUtil.getResource(object);
- canDrop = f != null;
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- } else {
- String tagname = getTagName(object);
- if(tagname.indexOf("taglib") >= 0) tagname= "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
- if (visualDropInfo.getDropContainer() != null) {
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceDragNode, visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder.getInnerDropInfo(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
- }
- }
- visualDropInfo.Release();
- }
- }else if(XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor) ||
- XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- try {
- canDrop = true;
- } catch (Exception ex) {
- VpePlugin.reportProblem(ex);
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop + (canDrop ? " container: " + caretParent.getNodeName() + " offset: " + caretOffset : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
-
- }
-
- public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object, Node parentNode, int offset) {
- String tagname = getTagName(object);
- Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
- return visualBuilder.getSourceInnerDropInfo(sourceDragNode, parentNode, offset, false);
- }
-
- public void externalDropAny(final String flavor, final String data, final Point range, Node container) {
- if(flavor == null || flavor.length() == 0) return;
- IDropCommand dropCommand = DropCommandFactory.getInstance().getDropCommand(flavor, JSPTagProposalFactory.getInstance());
-
- boolean promptAttributes = "yes".equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
- dropCommand.getDefaultModel().setPromptForTagAttributesRequired(promptAttributes);
-
- dropCommand.execute(
- new DropData(
- flavor,
- data,
- sourceEditor.getEditorInput(),
- (ISourceViewer)sourceEditor.getAdapter(ISourceViewer.class),
- new VpeSelectionProvider(range.x,range.y),
- container
- )
- );
- }
-
- private String getTagName(XModelObject object) {
- String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
-
- XModelObject parent = object.getParent();
- String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
-
- String[] texts = new String[]{"<"+tagname+">"}; //$NON-NLS-1$ //$NON-NLS-2$
- PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri, defaultPrefix);
- tagname = texts[0].substring(1,texts[0].length()-1);
-
- return tagname;
- }
-
- public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
- onHideTooltip();
-
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(), (int)visualDropInfo.getDropOffset());
- VpeSourceInnerDropInfo sourceDropInfo = null;
-
- if(MODEL_FLAVOR.equals(flavor)){
- XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
- if(object.getFileType() == XModelObject.FILE && !TLDUtil.isTaglib(object)) {
- flavor = "application/x-moz-file"; //$NON-NLS-1$
- IFile f = (IFile)EclipseResourceUtil.getResource(object);
- try {
- data = f.getLocation().toFile().toURL().toString();
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- }
- } else {
- String tagname = getTagName(object);
- if(tagname.indexOf("taglib") >= 0) tagname= "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
- if (visualDropInfo.getDropContainer() != null) {
- sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceDragNode, visualDropInfo, true);
- range = selectionBuilder.getSourceSelectionRange(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
- }
- }
- }
-
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
- }
- externalDropAny(flavor, data, range, sourceDropInfo == null?null:sourceDropInfo.getContainer());
- }
- }
-
- public void onShowTooltip(int x, int y, final String text) {
-
- if (tip != null && !tip.isDisposed()) tip.dispose();
-
- Display display = visualEditor.getControl().getDisplay();
- Shell parent = visualEditor.getControl().getShell();
-
- tip = new Shell(parent, SWT.NO_FOCUS| SWT.ON_TOP);
- Color bckgColor = new Color(tip.getDisplay(), 255, 250, 236);
- tip.setBackground(bckgColor);
-
- Composite composite = tip;
- GridLayout layout= new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight= 0;
- layout.marginWidth= 0;
- layout.verticalSpacing= 0;
- layout.horizontalSpacing= 0;
- composite.setLayout(layout);
- GridData gd= new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gd);
-
-
- final StyledText tipControlHeaderText = new StyledText(composite, SWT.MULTI | SWT.READ_ONLY);
-
- tipControlHeaderText.setForeground(bckgColor);
- tipControlHeaderText.setBackground(bckgColor);
-
- String formatText = text.trim();
-
- /** attributeString string containing the pairs attribute and it's value as one string*/
- String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
- /** buffer string containing the attribute and the value in the different succeding string*/
- String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
-
- tipControlHeaderText.setText(buffer[0].toString());
-
- tipControlHeaderText.addLineStyleListener(
- new LineStyleListener() {
- public void lineGetStyle(LineStyleEvent event){
- Color color = new Color(tipControlHeaderText.getDisplay(), 201, 51, 40);
- if (event.lineOffset == 0) {
- StyleRange st = new StyleRange();
- st.fontStyle = SWT.BOLD;
- st.foreground = color;
- event.styles = new StyleRange[]{st};
- st.start = event.lineOffset;
- st.length = event.lineText.length();
- }
- }
- }
- );
-
- GridData gridData = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
- gridData.horizontalAlignment = GridData.FILL;
- gridData.horizontalSpan = 2;
- tipControlHeaderText.setLayoutData(gridData);
-
- StringBuffer tempAttr = new StringBuffer();
- StringBuffer tempValue = new StringBuffer();
-
- if (attributeString.length >= 2) {
- for (int i = 1; i < attributeString.length; i++) {
- buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
- if (i == 1) {
- tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
- tempValue.append((buffer.length>=2?buffer[1]:"") + " "); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$ //$NON-NLS-2$
- tempValue.append(" \n" + (buffer.length>=2?buffer[1]:"") + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
-
- final StyledText tipControlAttributeText = new StyledText(composite,
- SWT.MULTI | SWT.READ_ONLY);
-
- tipControlAttributeText.setForeground(bckgColor);
- tipControlAttributeText.setBackground(bckgColor);
-
- tipControlAttributeText.setText(tempAttr.toString());
- tipControlAttributeText
- .addLineStyleListener(new LineStyleListener() {
- public void lineGetStyle(LineStyleEvent event) {
- Color color = new Color(tipControlHeaderText
- .getDisplay(), 42, 148, 0);
- StyleRange st = new StyleRange();
- st.start = event.lineOffset;
- st.length = event.lineText.length();
- st.foreground = color;
- st.fontStyle = SWT.NORMAL;
- event.styles = new StyleRange[] { st };
- }
- });
- GridData gridData1 = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
- gridData1.horizontalAlignment = GridData.FILL;
- tipControlAttributeText.setLayoutData(gridData1);
-
- final StyledText tipControlValueText = new StyledText(composite,
- SWT.MULTI | SWT.READ_ONLY);
-
- tipControlValueText.setBackground(bckgColor);
-
- tipControlValueText.setText(tempValue.toString());
-
-
-
- GridData gridData2 = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
- gridData2.horizontalAlignment = GridData.FILL;
- tipControlValueText.setLayoutData(gridData2);
- }
- /*
- * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
- * elements inside an inline frame (IFrame tag). The workaround is
- * to position the tooltip based on the mouse cursor location.
- */
- Point point = display.getCursorLocation();
- /* Assuming cursor is 21x21 because this is the size of
- * the arrow cursor on Windows
- */
- point.y += 21;
- tip.setLocation(point);
- tip.pack();
- tip.setVisible(true);
- }
-
- public void onHideTooltip() {
- if (tip != null && !tip.isDisposed()) tip.dispose();
- tip = null;
- }
-
- public VpePageContext getPageContext() {
-
- return pageContext;
- }
-
- public StructuredTextEditor getSourceEditor() {
- return sourceEditor;
- }
-
- public FormatControllerManager getToolbarFormatControllerManager() {
- return toolbarFormatControllerManager;
- }
-
- public void setToolbarFormatControllerManager(FormatControllerManager formatControllerManager) {
- toolbarFormatControllerManager = formatControllerManager;
- }
- public void setSelectionBarController(SelectionBar selectionBar) {
- this.selectionBar = selectionBar;
- }
-
- public IStructuredModel getModel() {
- return sourceEditor.getModel();
- }
-
- public VpeDomMapping getDomMapping() {
- return domMapping;
- }
-
- public VpeIncludeList getIncludeList(){
- try {
- if(includeList == null)
- throw new Exception("includeList - NULL!!!"); //$NON-NLS-1$
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- }
- return includeList;
- }
-
- public void selectionChanged(SelectionChangedEvent event) {
- if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
- if(toolbarFormatControllerManager != null) toolbarFormatControllerManager.selectionChanged();
- }
-
- if(selectionBar != null) selectionBar.selectionChanged();
-
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> selectionChanged " + event.getSource()); //$NON-NLS-1$
- }
- sourceSelectionChanged();
- switcher.stopActiveEditor();
- }
-
- // nsIClipboardDragDropHooks implementation
- public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
- onHideTooltip();
-
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(), (int)visualDropInfo.getDropOffset());
- VpeSourceInnerDropInfo sourceDropInfo = null;
-
- XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
-
- String tagname = getTagName(object);
- if(tagname.indexOf("taglib") >= 0) tagname= "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
- if (visualDropInfo.getDropContainer() != null) {
- sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceDragNode, visualDropInfo, true);
- range = selectionBuilder.getSourceSelectionRange(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
- }
-
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
- }
- final String finalFlavor = flavor;
- final String finalData = data;
- final Point finalRange = range;
- final Node finalDropContainer = sourceDropInfo == null ? null : sourceDropInfo.getContainer();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- externalDropAny(finalFlavor, finalData, finalRange, finalDropContainer);
- }
- });
- }
- }
-
- public void drop(Node node, Node parentNode, int offset) {
- visualBuilder.innerDrop(node, parentNode, offset);
- }
-
- /* (non-Javadoc)
- * @see org.mozilla.interfaces.nsISupports#queryInterface(java.lang.String)
- */
- public nsISupports queryInterface(String arg0) {
- return Mozilla.getInstance().queryInterface(this, arg0);
- }
- /**
- * Calls when editor content should be refreshed
- */
- public void onRefresh() {
- //when we using separate thread to display selection rectangle
- //it's working better than without
- /*
- * HACK
- * We need wait some time while standart event will be handled
- * and in process event handles some components are repainted(like buttons)
- * and flasher are not repainted, so we should paint flasher
- */
-
-
- Display.getDefault().asyncExec(new Thread(){
- public void run(){
-
- getXulRunnerEditor().showSelectionRectangle();
- }
- });
-
- }
-
- /**
- * @return the xulRunnerEditor
- */
- public XulRunnerEditor getXulRunnerEditor() {
- return xulRunnerEditor;
- }
-
- /**
- * @param xulRunnerEditor the xulRunnerEditor to set
- */
- public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
- this.xulRunnerEditor = xulRunnerEditor;
- }
-
- /**
- * Start drag session
- */
- public void startDragSession(nsIDOMEvent domEvent) {
-
- visualBuilder.getDnd().startDragSession(domEvent);
- }
-
- public void dragDrop(nsIDOMEvent domEvent) {
-
- visualBuilder.getDnd().dragDrop(domEvent,this);
- }
-
- /**
- * @return the selectionBuilder
- */
- public VpeSelectionBuilder getSelectionBuilder() {
- return selectionBuilder;
- }
-
- /**
- * @param selectionBuilder the selectionBuilder to set
- */
- public void setSelectionBuilder(VpeSelectionBuilder selectionBuilder) {
- this.selectionBuilder = selectionBuilder;
- }
-
-}
+ }
+ //sends xulrunner event to eclipse environment
+ getXulRunnerEditor().getBrowser().notifyListeners(keyboardEvent.type, keyboardEvent);
+
+ }
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ visualRefresh();
+ }
+
+ }
+
+ public void elementResized(nsIDOMElement element, int resizerConstrains, int top, int left, int width, int height) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ visualEditor.hideResizer();
+ switcher.stopActiveEditor();
+
+ visualBuilder.resize(element, resizerConstrains, top, left, width, height);
+ sourceSelectionChanged();
+ }
+
+ public void dragGesture(nsIDOMEvent domEvent) {
+
+ nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent) domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+ boolean canDragFlag = canInnerDrag(mouseEvent);
+ //start drag sessionvpe-element
+ if(canDragFlag) {
+ startDragSession(domEvent);
+ }
+ }
+
+ private void createMenuForNode(Node node, MenuManager manager) {
+ createMenuForNode(node, manager, false);
+ }
+
+ private void createMenuForNode(Node node, MenuManager manager, boolean topLevelFlag) {
+ NodeActionManager.setTextNodeSplitter(null);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ VpeElementMapping elementMapping = (VpeElementMapping)domMapping.getNodeMapping(node);
+ if (elementMapping != null && elementMapping.getTemplate() != null) {
+ manager.add(new VpeAction("<"+node.getNodeName()+"> Attributes", node) { //$NON-NLS-1$ //$NON-NLS-2$
+ public void run() {
+ showProperties(actionNode);
+ }
+ });
+
+ if (!topLevelFlag) {
+ manager.add(new VpeAction("Select This Tag", node) { //$NON-NLS-1$
+ public void run() {
+ selectionBuilder.setVisualSelection(actionNode,0,actionNode,0,false,true);
+
+ }
+ });
+ }
+ Node parent = node.getParentNode();
+ if(parent != null && parent.getNodeType() == Node.ELEMENT_NODE){
+ MenuManager menuManager = new MenuManager("Parent Tag"); //$NON-NLS-1$
+ menuManager.setParent(manager);
+ manager.add(menuManager);
+ createMenuForNode(parent, menuManager);
+ }
+
+ manager.add(new Separator());
+ }
+ }
+ NodeActionManager actionManager = new NodeActionManager(getModel(), null);
+
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ Point range = sourceEditor.getTextViewer().getSelectedRange();
+ TextNodeSplitterImpl splitter = new TextNodeSplitterImpl(range, (Text)node);
+ NodeActionManager.setTextNodeSplitter(splitter);
+ }
+
+
+ if (actionManager != null) {
+ StructuredSelection structuredSelection = new StructuredSelection(node);
+ actionManager.fillContextMenuForVpe(manager, structuredSelection);
+
+ }
+
+ IContributionItem[] items = manager.getItems();
+
+ for(int i=0;i< items.length;i++){
+ if(items[i] instanceof MenuManager){
+ MenuManager mm = (MenuManager)items[i];
+ if(NodeActionManager.INSERT_AROUND_MENU.equals(mm.getMenuText())){
+ listenContextMenu(mm, (IndexedRegion)node, AROUND_MENU);
+ }else if(NodeActionManager.INSERT_BEFORE_MENU.equals(mm.getMenuText())){
+ listenContextMenu(mm, (IndexedRegion)node, BEFORE_MENU);
+ }else if(NodeActionManager.INSERT_AFTER_MENU.equals(mm.getMenuText())){
+ listenContextMenu(mm, (IndexedRegion)node, AFTER_MENU);
+ }
+ }
+ }
+
+ manager.add(new Separator());
+
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ VpeElementMapping elementMapping = (VpeElementMapping)domMapping.getNodeMapping(node);
+ if (elementMapping != null && elementMapping.getTemplate() != null && elementMapping.getTemplate().getType() == VpeHtmlTemplate.TYPE_ANY) {
+ final VpeTemplate selectedTemplate = elementMapping.getTemplate();
+ manager.add(new VpeAction("Template", node) { //$NON-NLS-1$
+ public void run() {
+ boolean isCorrectNS = pageContext.isCorrectNS(actionNode);
+ VpeAnyData data = null;
+ if (isCorrectNS) {
+ data = selectedTemplate.getAnyData();
+ data.setUri(pageContext.getSourceTaglibUri(actionNode));
+ data.setName(actionNode.getNodeName());
+ }
+ data = editAnyData(sourceEditor, isCorrectNS, data);
+ if (data != null && data.isChanged()) templateManager.setAnyTemplate(data);
+ }
+ });
+
+ manager.add(new Separator());
+ }
+
+
+ manager.add(new VpeTextOperationAction("Cut", ActionFactory.CUT.getId(), (IndexedRegion)node)); //$NON-NLS-1$
+ manager.add(new VpeTextOperationAction("Copy", ActionFactory.COPY.getId(), (IndexedRegion)node)); //$NON-NLS-1$
+ manager.add(new VpeTextOperationAction("Paste", ActionFactory.PASTE.getId(), (IndexedRegion)node)); //$NON-NLS-1$
+ }else if(node.getNodeType() == Node.TEXT_NODE){
+ manager.add(new Action("Cut") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.CUT.getId()).run();
+ }
+ });
+ manager.add(new Action("Copy") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.COPY.getId()).run();
+ }
+ });
+ manager.add(new Action("Paste") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.PASTE.getId()).run();
+ }
+ });
+ }
+ manager.add(new Separator());
+
+ if (actionManager != null) {
+ StructuredSelection structuredSelection = node.getNodeType() == Node.ELEMENT_NODE ? new StructuredSelection(node) : null;
+ actionManager.addContextMenuForVpe(manager, structuredSelection);
+ }
+
+ if(node.getNodeType() == Node.ELEMENT_NODE){
+ boolean stripEnable = false;
+ NodeImpl impl = (NodeImpl)node;
+ if(impl.isContainer()){
+ NodeList list = impl.getChildNodes();
+ if(list.getLength() > 0){
+ if(list.getLength() == 1){
+ Node child = list.item(0);
+ if(child.getNodeType() == Node.TEXT_NODE){
+ if("".equals(child.getNodeValue().trim()))stripEnable = false; //$NON-NLS-1$
+ else stripEnable = true;
+ }else stripEnable = true;
+ }else stripEnable = true;
+ }
+ }
+ if(stripEnable)
+ manager.add(new VpeAction("Strip Tag", node) { //$NON-NLS-1$
+ public void run() {
+ Node parent = actionNode.getParentNode();
+ if(parent != null){
+ int index = ((NodeImpl)actionNode).getIndex();
+ parent.removeChild(actionNode);
+ NodeList children = actionNode.getChildNodes();
+ int lengh = children.getLength();
+ Node child;
+ for(int i=0; i < lengh; i++){
+ child = children.item(0);
+ actionNode.removeChild(child);
+ insertNode(parent, child, index++);
+ }
+ }
+ }
+
+ private void insertNode(Node parent, Node node, int index){
+ Node oldNode=null;
+ int childSize = parent.getChildNodes().getLength();
+
+ if(index <= (childSize-1))oldNode = parent.getChildNodes().item(index);
+ if(oldNode != null)parent.insertBefore(node, oldNode);
+ else parent.appendChild(node);
+ }
+ });
+ }
+ if(node.getNodeType() == Node.TEXT_NODE){
+ manager.add(new Action("Delete") { //$NON-NLS-1$
+ public void run() {
+ sourceEditor.getAction(ActionFactory.DELETE.getId()).run();
+ }
+ });
+ }
+
+ if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_SOURCE) {
+ manager.add(new Action("Dump Source") { //$NON-NLS-1$
+ public void run() {
+ DOMTreeDumper dumper = new DOMTreeDumper(VpeDebug.VISUAL_DUMP_PRINT_HASH);
+ dumper.dumpToStream(System.out, visualEditor.getDomDocument());
+ }
+ });
+ }
+
+ if (VpeDebug.VISUAL_CONTEXTMENU_DUMP_MAPPING) {
+ manager.add(new Action("Dump Mapping") { //$NON-NLS-1$
+ public void run() {
+ printMapping();
+ }
+ });
+ }
+
+ if (VpeDebug.VISUAL_CONTEXTMENU_TEST) {
+ manager.add(new VpeAction("Test", node) { //$NON-NLS-1$
+ public void run() {
+ test(actionNode);
+ }
+ });
+ }
+ }
+
+ /**
+ * Calls when on when browser receive context menu event.
+ *
+ * @param contextFlags -not used in this function, just for becouse this parametr
+ * exist in nsIContextMenuListener
+ * @param event event from browser used here
+ * @param node where this event are occur
+ */
+ public void onShowContextMenu(long contextFlags, nsIDOMEvent event, nsIDOMNode node) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+
+ if (visualNode != null) {
+ Node selectedSourceNode = null;
+ selectedSourceNode = selectionBuilder.setContextMenuSelection(visualNode);
+ if (selectedSourceNode != null) {
+
+ MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
+ final Menu contextMenu = menuManager.createContextMenu(visualEditor.getControl());
+ contextMenu.addMenuListener(
+ new MenuListener(){
+ Menu menu = contextMenu;
+ public void menuHidden(MenuEvent e) {
+ Display.getCurrent().asyncExec(
+ new Runnable() {
+ public void run() {
+ menu.dispose();
+ }
+ }
+ );
+ }
+ public void menuShown(MenuEvent e) {
+ }
+ }
+ );
+ createMenuForNode(selectedSourceNode, menuManager, true);
+
+ contextMenu.setVisible(true);
+
+ }
+ }
+ }
+
+
+ private VpeAnyData editAnyData(StructuredTextEditor sourceEditor, boolean isCorrectNS, VpeAnyData data) {
+ Shell shell = sourceEditor.getEditorPart().getSite().getShell();
+ if (isCorrectNS) {
+ VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
+ editDialog.open();
+ } else {
+ MessageBox message = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
+ message.setMessage(VpeUIMessages.NAMESPACE_NOT_DEFINED);
+ message.open();
+ }
+ return data;
+ }
+
+ // VpeTemplateListener implementation
+ public void templateReloaded() {
+ visualRefresh();
+ }
+
+
+ public void visualRefresh() {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ visualRefreshImpl();
+
+ switcher.stopActiveEditor();
+ }
+
+ void visualRefreshImpl() {
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ IDOMModel sourceModel = (IDOMModel)getModel();
+ if (sourceModel != null) {
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.rebuildDom(sourceDocument);
+ } else {
+ visualBuilder.rebuildDom(null);
+ }
+ }
+
+ public void preLongOperation() {
+ switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
+ }
+
+ public void postLongOperation() {
+ switcher.stopActiveEditor();
+ visualRefresh();
+ }
+
+ // for debug
+ private void printSourceEvent(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int pos) {
+ System.out.println(">>> eventType: " + INodeNotifier.EVENT_TYPE_STRINGS[eventType] + " pos: " + pos + " notifier: " + ((Node)notifier).getNodeName() + " hashCode: " + notifier.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ if (feature != null) {
+ if (feature instanceof Node) {
+ System.out.println(" feature: " + ((Node)feature).getNodeType() + " " + ((Node)feature).getNodeName() + " hashCode: " + feature.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else {
+ System.out.println(" feature: " + feature); //$NON-NLS-1$
+ }
+ }
+ if (oldValue != null) {
+ if (oldValue instanceof Node) {
+ System.out.println(" oldValue: " + ((Node)oldValue).getNodeName() + " hashCode: " + oldValue.hashCode()); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
+ }
+ }
+ if (newValue != null) {
+ if (newValue instanceof Node) {
+ System.out.println(" newValue: " + ((Node)newValue).getNodeName() + " hashCode: " + newValue.hashCode() + " " + ((Node)newValue).getNodeType()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else {
+ System.out.println(" newValue: " + newValue); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private void printVisualEvent(nsIDOMEvent event) {
+ System.out.print("<<< " + event.getType()); //$NON-NLS-1$
+
+ if (event instanceof nsIDOMMutationEvent) {
+ nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent)event;
+
+ System.out.print(" EventPhase: " + mutationEvent.getEventPhase()); //$NON-NLS-1$
+
+ nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
+ System.out.print(" RelatedNode: " + (relatedNode == null ? null : relatedNode.getNodeName())); //$NON-NLS-1$
+
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ String name = targetNode != null ? targetNode.getNodeName() : null;
+ System.out.print(" TargetNode: " + name + " (" + targetNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ System.out.print(" PrevValue: " + mutationEvent.getPrevValue().trim()); //$NON-NLS-1$
+ System.out.print(" NewValue: " + mutationEvent.getNewValue().trim()); //$NON-NLS-1$
+ }
+ System.out.println();
+ }
+
+ private void printMapping() {
+ domMapping.printMapping();
+ }
+
+ private class ActiveEditorSwitcher {
+ private static final int ACTIVE_EDITOR_CANNOT = 0;
+ private static final int ACTIVE_EDITOR_NONE = 1;
+ private static final int ACTIVE_EDITOR_SOURCE = 2;
+ private static final int ACTIVE_EDITOR_VISUAL = 3;
+
+ private int type = ACTIVE_EDITOR_CANNOT;
+
+ private void initActiveEditor() {
+ type = ACTIVE_EDITOR_NONE;
+ }
+
+ private void destroyActiveEditor() {
+ type = ACTIVE_EDITOR_CANNOT;
+ }
+
+ private boolean startActiveEditor(int newType) {
+ if (type == ACTIVE_EDITOR_NONE) {
+ if( newType == ACTIVE_EDITOR_SOURCE &&
+ editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
+ return false;
+ }
+ type = newType;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void stopActiveEditor() {
+ onRefresh();
+ type = ACTIVE_EDITOR_NONE;
+ }
+ }
+
+ private void showProperties(Node node){
+ ExtendedProperties p = createExtendedProperties(node);
+ if(p != null) ExtendedPropertiesWizard.run(p);
+ }
+
+ ExtendedProperties createExtendedProperties(Node node) {
+ try {
+ Class c = ModelFeatureFactory.getInstance().getFeatureClass("org.jboss.tools.jst.jsp.outline.VpeProperties"); //$NON-NLS-1$
+ return (ExtendedProperties)c.getDeclaredConstructor(new Class[]{Node.class}).newInstance(new Object[]{node});
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ return null;
+ }
+ }
+
+
+ private void test(Node node) {
+ }
+
+ void refreshBundleValues() {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ if (bundle != null) {
+ bundle.refresh();
+ if (pageContext != null) {
+ pageContext.refreshBundleValues();
+ }
+ }
+ switcher.stopActiveEditor();
+ }
+
+ void refreshTemplates() {
+ if (includeList.includesRefresh()) {
+ visualRefresh();
+ }
+ if (templateManager != null) {
+ templateManager.reload();
+ }
+ if (bundle != null) {
+ bundle.refresh();
+ if (pageContext != null) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ pageContext.refreshBundleValues();
+ switcher.stopActiveEditor();
+ }
+ }
+ }
+
+ // implements XModelTreeListener
+ public void nodeChanged(XModelTreeEvent event) {
+ visualRefresh();
+ }
+
+ public void structureChanged(XModelTreeEvent event) {
+ }
+
+ private Node getSourceNodeAt(int offset) {
+ if (sourceEditor != null && getModel() != null) {
+ IndexedRegion node = getModel().getIndexedRegion(offset);
+ if (node instanceof IDOMNode) {
+
+ VpeElementMapping elementMapping = domMapping
+ .getNearElementMapping((IDOMNode) node);
+
+ if (elementMapping != null) {
+
+ if (node instanceof IDOMElement) {
+ IDOMElement element = (IDOMElement) node;
+
+ if (offset < element.getEndStartOffset()) {
+ NamedNodeMap attrs = element.getAttributes();
+ if (attrs != null) {
+ for (int i = 0; i < attrs.getLength(); i++) {
+ if (attrs.item(i) instanceof AttrImpl) {
+ AttrImpl attr = (AttrImpl) attrs
+ .item(i);
+ if (getSourceAttributeOffset(attr,
+ offset) != -1) {
+
+ String[] atributeNames = elementMapping
+ .getTemplate()
+ .getOutputAtributeNames();
+ if (atributeNames != null
+ && atributeNames.length > 0
+ && attr
+ .getName()
+ .equalsIgnoreCase(
+ atributeNames[0])) {
+ return attr;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (node == null) {
+ node = getModel().getIndexedRegion(offset - 1);
+ }
+ if (node instanceof Node) {
+ return (Node) node;
+ }
+ }
+ return null;
+ }
+
+ private int getSourceNodeOffset(Node node, int pos, boolean endFlag) {
+ if (node == null) return 0;
+ int start = ((IndexedRegion)node).getStartOffset();
+ int end = ((IndexedRegion)node).getEndOffset();
+
+ switch (node.getNodeType()) {
+ case Node.ATTRIBUTE_NODE:
+ if (node instanceof AttrImpl) {
+ return getSourceAttributeOffset((AttrImpl)node, pos);
+ }
+ case Node.TEXT_NODE:
+ if (pos < start) {
+ return 0;
+ } else if (pos > end) {
+ return end - start;
+ } else {
+ return pos - start;
+ }
+ case Node.COMMENT_NODE:
+ if (pos > end) {
+ pos = end;
+ }
+ int offset = pos - start - 4;
+ return offset < 0 ? 0 : offset;
+ case Node.ELEMENT_NODE:
+ ElementImpl element = (ElementImpl)node;
+ if (element.isContainer()) {
+ if (pos < element.getStartEndOffset()) {
+ return 0;
+ } else {
+ return 1;
+ }
+ } else {
+ return endFlag ? 1 : 0;
+ }
+ default:
+ return endFlag ? 1 : 0;
+ }
+ }
+
+ private int getSourceAttributeOffset(AttrImpl attr, int pos) {
+ if (attr.getValueRegion() != null) {
+ int start = attr.getValueRegionStartOffset();
+ String value = attr.getValueRegionText();
+ int len = value.length();
+ if (pos >= start && pos <= start + len) {
+ int offset = pos - start;
+ if (len > 1 && value.charAt(0) == '"' && value.charAt(len - 1) == '"') {
+ if (offset <= 0 || offset >= len) {
+ return -1;
+ }
+ offset--;
+ }
+ return offset;
+ }
+ }
+ return -1;
+ }
+
+ private int getSourceNodeOffset1(Node node, int pos, boolean endFlag) {
+ if (node == null) return 0;
+ int start = ((IndexedRegion)node).getStartOffset();
+ int end = ((IndexedRegion)node).getEndOffset();
+
+ switch (node.getNodeType()) {
+ case Node.ATTRIBUTE_NODE:
+ if (node instanceof AttrImpl) {
+ AttrImpl attr = (AttrImpl)node;
+ start = attr.getValueRegionStartOffset();
+ end = start + attr.getValueRegion().getLength();
+ int ret = 0;
+ if (pos > end) {
+ ret = end - start;
+ } else {
+ ret = pos - start;
+ }
+ if (ret > 0 && attr.getValueRegionText().charAt(0) == '"') {
+ ret--;
+ }
+ return ret;
+ }
+ case Node.TEXT_NODE:
+ if (pos < start) {
+ return 0;
+ } else if (pos > end) {
+ return end - start;
+ } else {
+ return pos - start;
+ }
+ case Node.COMMENT_NODE:
+ if (pos > end) {
+ pos = end;
+ }
+ int offset = pos - start - 4;
+ return offset < 0 ? 0 : offset;
+ case Node.ELEMENT_NODE:
+ ElementImpl element = (ElementImpl)node;
+ if (element.isContainer()) {
+ if (pos < element.getStartEndOffset()) {
+ return 0;
+ } else if (pos < element.getStartEndOffset()) {
+ return 1;
+ } else if (pos == element.getStartEndOffset()) {
+ return 2;
+ }
+ } else {
+ return endFlag ? 1 : 0;
+ }
+ default:
+ return endFlag ? 1 : 0;
+ }
+ }
+
+ private void listenContextMenu(MenuManager manager, IndexedRegion region, int type){
+ MenuManager mm = new MyMenuManager("From Palette",true); //$NON-NLS-1$
+ manager.add(mm);
+ manager.addMenuListener(new VpeMenuListener(mm, region, type));
+ }
+
+ class VpeMenuListener implements IMenuListener{
+ private MenuManager manager;
+ private IndexedRegion region;
+ private int type;
+ private boolean loaded=false;
+
+ public VpeMenuListener(MenuManager manager, IndexedRegion region, int type){
+ this.manager = manager;
+ this.region = region;
+ this.type = type;
+ }
+ public void menuAboutToShow(IMenuManager m) {
+ if(loaded)return;
+ loaded=true;
+ fillContextMenuFromPalette(manager, region, type);
+ manager.getParent().update(true);
+ }
+ }
+ private MenuManager fillContextMenuFromPalette(MenuManager manager, IndexedRegion region, int type){
+ XModelObject model = ModelUtilities.getPreferenceModel().getByPath("%Palette%"); //$NON-NLS-1$
+
+ XModelObject[] folders = model.getChildren();
+ for(int i=0;i<folders.length;i++){
+ if ("yes".equals(folders[i].getAttributeValue("hidden"))) continue; //$NON-NLS-1$ //$NON-NLS-2$
+ MenuManager mm = new MenuManager(folders[i].getAttributeValue("name")); //$NON-NLS-1$
+ manager.add(mm);
+ fillPaletteFolder(mm, region, folders[i], type);
+ }
+ return manager;
+ }
+
+ private void fillPaletteFolder(MenuManager menu, IndexedRegion region, XModelObject folder, int type){
+ XModelObject[] groups = folder.getChildren();
+ for(int i=0;i<groups.length;i++){
+ if ("yes".equals(groups[i].getAttributeValue("hidden"))) continue; //$NON-NLS-1$ //$NON-NLS-2$
+ MenuManager mm = new MenuManager(groups[i].getAttributeValue("name")); //$NON-NLS-1$
+ menu.add(mm);
+ fillPaletteGroup(mm, region, groups[i], type);
+ }
+ }
+
+ private void fillPaletteGroup(MenuManager menu, IndexedRegion region, XModelObject group, int type){
+ XModelObject[] items = group.getChildren();
+ String endText;
+
+ for(int i=0;i<items.length;i++){
+ if ("yes".equals(items[i].getAttributeValue("hidden"))) continue; //$NON-NLS-1$ //$NON-NLS-2$
+ endText = items[i].getAttributeValue("end text"); //$NON-NLS-1$
+
+ if(type == AROUND_MENU && (endText == null || "".equals(endText))) continue; //$NON-NLS-1$
+ createInsertAction(menu, region, items[i], type);
+ }
+ }
+
+ private void createInsertAction(MenuManager menu, IndexedRegion region, XModelObject item, int type){
+
+
+ XModelObject parent = item.getParent();
+ String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
+ String[] texts = new String[]{"<"+tagName+">"}; //$NON-NLS-1$ //$NON-NLS-2$
+ if(tagName.indexOf("taglib") < 0) //$NON-NLS-1$
+ PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagName, uri, defaultPrefix);
+ tagName = texts[0];
+
+ menu.add(new InsertAction(tagName, region, item, type));
+ }
+
+ class InsertAction extends Action{
+ private XModelObject item;
+ private int type;
+ private IndexedRegion region;
+
+ public InsertAction(String title, IndexedRegion region, XModelObject item, int type){
+ super(title);
+ this.item = item;
+ this.type = type;
+ this.region = region;
+ }
+ public void run(){
+ try {
+ String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
+
+ XModelObject parent = item.getParent();
+ String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String libraryVersion = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ VpeSelectionProvider selProvider = new VpeSelectionProvider(region);
+
+ String startText = "" + item.getAttributeValue("start text"); //$NON-NLS-1$ //$NON-NLS-2$
+ String endText = "" + item.getAttributeValue("end text"); //$NON-NLS-1$ //$NON-NLS-2$
+ if(type == AROUND_MENU){
+ }else if(type == BEFORE_MENU){
+ selProvider = new VpeSelectionProvider(region.getStartOffset());
+ }else if(type == AFTER_MENU){
+ selProvider = new VpeSelectionProvider(region.getEndOffset());
+ }
+
+ Properties p = new Properties();
+ p.setProperty("tag name", tagName); //$NON-NLS-1$
+ p.setProperty("start text", startText); //$NON-NLS-1$
+ p.setProperty("end text", endText); //$NON-NLS-1$
+ p.setProperty("automatically reformat tag body", "" + item.getAttributeValue("automatically reformat tag body")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ p.setProperty(URIConstants.LIBRARY_URI, uri);
+ p.setProperty(URIConstants.LIBRARY_VERSION, libraryVersion);
+ String addTaglib = item.getParent().getAttributeValue(TLDToPaletteHelper.ADD_TAGLIB);
+ p.setProperty(URIConstants.DEFAULT_PREFIX, defaultPrefix);
+ p.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, addTaglib);
+ if(((Node)region).getNodeType() == Node.ELEMENT_NODE)
+ p.put("selectionProvider", selProvider); //$NON-NLS-1$
+ PaletteInsertHelper.insertIntoEditor(sourceEditor.getTextViewer(), p);
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ }
+
+ }
+
+ }
+
+ class VpeSelectionProvider implements ISelectionProvider{
+ VpeSelection selection;
+
+ public VpeSelectionProvider(IndexedRegion region){
+ selection = new VpeSelection(region);
+ }
+ public VpeSelectionProvider(int position){
+ selection = new VpeSelection(position);
+ }
+ public VpeSelectionProvider(int offset, int length){
+ selection = new VpeSelection(offset, length);
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ }
+ public ISelection getSelection() {
+ return selection;
+ }
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+
+ }
+ public void setSelection(ISelection selection) {
+ }
+ }
+
+ class VpeSelection implements ITextSelection{
+ String text=""; //$NON-NLS-1$
+ int offset, length;
+
+ public VpeSelection(int position){
+ offset = position;
+ length = 0;
+ }
+
+ public VpeSelection(int offset, int length){
+ this.offset = offset;
+ this.length = length;
+ if (length > 0) {
+ try{
+ text = sourceEditor.getTextViewer().getDocument().get(offset, length);
+ }catch(Exception ex){
+ VpePlugin.reportProblem(ex);
+ }
+ }
+ }
+
+ public VpeSelection(IndexedRegion region){
+ offset = region.getStartOffset();
+ length = region.getEndOffset() - offset;
+ try{
+ text = sourceEditor.getTextViewer().getDocument().get(offset, length);
+ }catch(Exception ex){
+ VpePlugin.reportProblem(ex);
+ }
+ }
+
+ public int getEndLine() {
+ return 0;
+ }
+ public int getLength() {
+ return length;
+ }
+ public int getOffset() {
+ return offset;
+ }
+ public int getStartLine() {
+ return 0;
+ }
+ public String getText() {
+ return text;
+ }
+ public boolean isEmpty() {
+ return false;
+ }
+}
+
+ class VpeAction extends Action{
+ public Node actionNode;
+ public VpeAction(String name, Node node){
+ super(name);
+ this.actionNode = node;
+ }
+ }
+
+ class VpeTextOperationAction extends Action{
+ private String id;
+ private IndexedRegion region;
+ public VpeTextOperationAction(String name, String id, IndexedRegion region){
+ super(name);
+ this.id = id;
+ this.region = region;
+ }
+ public void run(){
+ sourceEditor.getSelectionProvider().setSelection(new VpeSelection(region));
+ sourceEditor.getAction(id).run();
+ }
+ }
+
+ public void refreshExternalLinks() {
+ pageContext.getVisualBuilder().refreshExternalLinks();
+ }
+
+ public IPath getPath() {
+ if (editPart != null) {
+ IEditorInput input = editPart.getEditorInput();
+ if (input != null && input instanceof IFileEditorInput) {
+ return ((IFileEditorInput)input).getFile().getFullPath();
+ }
+ }
+ return null;
+ }
+
+ public void changed(Object source) {
+ if(cssReferenceListListener == source) {
+ pageContext.getVisualBuilder().refreshExternalLinks();
+ } else if (absoluteFolderReferenceListListener == source ||
+ relativeFolderReferenceListListener == source ||
+ taglibReferenceListListener == source) {
+ visualRefresh();
+ }
+ }
+
+ public void dragEnter(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<< DragEnter"); //$NON-NLS-1$
+ }
+ }
+
+ public void dragExit(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<< dragExit"); //$NON-NLS-1$
+ }
+ // TODO Sergey Vasilyev figure out with drag caret
+// xulRunnerEditor.hideDragCaret();
+ }
+
+ public void dragOver(nsIDOMEvent event) {
+
+ visualBuilder.getDnd().dragOver(event, this);
+
+ }
+
+ public void _dragOver(nsIDOMEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<< dragOver"); //$NON-NLS-1$
+ }
+
+// browser.computeDropPosition(event);
+
+ boolean canDrop = !xulRunnerEditor.isMozillaDragFlavor();
+ if (canDrop) {
+ Clipboard clipboard = new Clipboard(Display.getCurrent());
+ canDrop = clipboard.getContents(ModelTransfer.getInstance()) != null;
+ }
+ if (canDrop) {
+ canDrop = VpeDndUtil.isDropEnabled((IModelObjectEditorInput)sourceEditor.getEditorInput());
+ }
+ if (canDrop) {
+ VpeVisualCaretInfo caretInfo = selectionBuilder.getVisualCaretInfo(event);
+ canDrop = caretInfo.exist();
+ if (canDrop) {
+ caretInfo.showCaret();
+ } else {
+ caretInfo.hideCaret();
+ }
+ }
+ if (!canDrop) {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ switcher.stopActiveEditor();
+ }
+
+ public void drop(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<< outerDrop"); //$NON-NLS-1$
+ }
+ event.preventDefault();
+ }
+
+ public boolean canInnerDrag(nsIDOMMouseEvent event) {
+ onHideTooltip();
+
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
+ }
+ if (innerDragInfo != null) {
+ innerDragInfo.Release();
+ innerDragInfo = null;
+ }
+ boolean canDrag = false;
+ VpeVisualInnerDragInfo dragInfo = selectionBuilder.getInnerDragInfo(event);
+ if (dragInfo != null) {
+ nsIDOMNode dragNode = dragInfo.getNode();
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ switch (dragNode.getNodeType()) {
+ case nsIDOMNode.ELEMENT_NODE:
+ canDrag = visualBuilder.canInnerDrag((nsIDOMElement)dragNode);
+ case nsIDOMNode.TEXT_NODE:
+ canDrag = visualBuilder.isTextEditable(dragNode);
+ }
+ if (canDrag) {
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder.getSourceInnerDragInfo(dragInfo);
+ if (sourceInnerDragInfo.getNode() != null) {
+ innerDragInfo = dragInfo;
+ InnerDragBuffer.object = sourceInnerDragInfo.getNode();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ InnerDragBuffer.object = null;
+ }
+ });
+ } else {
+ canDrag = false;
+ }
+ }
+ if (!canDrag) {
+ dragInfo.Release();
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrag: " + canDrag); //$NON-NLS-1$
+ }
+ return canDrag;
+ }
+
+ VpeDropWindow dropWindow = null;
+
+ public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
+ onHideTooltip();
+
+ if(dropWindow.active) {
+ if(!event.getAltKey()) {
+ dropWindow.close();
+ } else {
+ return null;
+ }
+ }
+ if(event.getAltKey()) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+ Node sourceNode = domMapping.getNearSourceNode(visualNode);
+ if(sourceNode != null) {
+ dropWindow.active = true;
+ dropWindow.setEventPosition(event.getScreenX(), event.getScreenY());
+ dropWindow.setInitialTargetNode(sourceNode);
+ dropWindow.open();
+ event.stopPropagation();
+ event.preventDefault();
+ return null;
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
+ }
+ boolean canDrop = false;;
+ nsIDOMNode caretParent = null;
+ long caretOffset = 0;
+ if (innerDragInfo != null) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(event);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print(" x: " + visualDropInfo.getMouseX() + " y: " + visualDropInfo.getMouseY() + //$NON-NLS-1$ //$NON-NLS-2$
+ " container: " + visualDropInfo.getDropContainer().getNodeName() + //$NON-NLS-1$
+ "(" + visualDropInfo.getDropContainer() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " parent: " + visualDropInfo.getDropContainer().getParentNode().getNodeName() + //$NON-NLS-1$
+ "(" + visualDropInfo.getDropContainer().getParentNode() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: " + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ }
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder.getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceInnerDragInfo.getNode(), visualDropInfo, true);
+ canDrop = sourceDropInfo.canDrop();
+ if (canDrop) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder.getInnerDropInfo(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(newVisualDropInfo, visualDropInfo);
+ caretParent = newVisualDropInfo.getDropContainer();
+ caretOffset = newVisualDropInfo.getDropOffset();
+ }
+ }
+ }
+ visualDropInfo.Release();
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
+ }
+ return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+ }
+
+ public void innerDrop(nsIDOMMouseEvent event) {
+ onHideTooltip();
+
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
+ }
+ if (innerDragInfo != null) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(event);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print(" container: " + visualDropInfo.getDropContainer().getNodeName() + //$NON-NLS-1$
+ "(" + visualDropInfo.getDropContainer() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: " + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ }
+
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder.getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceInnerDragInfo.getNode(), visualDropInfo, true);
+ if(sourceDropInfo.canDrop()){
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder.getInnerDropInfo(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(newVisualDropInfo, visualDropInfo);
+ sourceDropInfo.setTop(visualDropInfo.getMouseY());
+ sourceDropInfo.setLeft(visualDropInfo.getMouseX());
+ visualBuilder.innerDrop(sourceInnerDragInfo, sourceDropInfo);
+ if (innerDragInfo != null) {
+ innerDragInfo.Release();
+ innerDragInfo = null;
+ }
+ }
+ }
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println();
+ }
+ }
+
+ public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
+ InnerDragBuffer.object = null;
+ onHideTooltip();
+
+ if(dropWindow.active) {
+ if(!mouseEvent.getAltKey()) {
+ dropWindow.close();
+ } else {
+ return new MozillaDropInfo(false, null, 0);
+ }
+ }
+ if(mouseEvent.getAltKey()) {
+ nsIDOMEvent event = (nsIDOMEvent) mouseEvent.queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
+ nsIDOMNode visualNode = (nsIDOMNode) event.getTarget().queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+ Node sourceNode = domMapping.getNearSourceNode(visualNode);
+ if(sourceNode != null) {
+ if(ModelTransfer.MODEL.equals(flavor)){ //$NON-NLS-1$
+// XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
+// InnerDragBuffer.object = object;
+ } else {
+ dropWindow.flavor = flavor;
+ }
+ dropWindow.active = true;
+ dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent.getScreenY());
+ dropWindow.setInitialTargetNode(sourceNode);
+ dropWindow.open();
+ mouseEvent.stopPropagation();
+ mouseEvent.preventDefault();
+ return new MozillaDropInfo(false, null, 0);
+ }
+ }
+ boolean canDrop = false;
+ nsIDOMNode caretParent = null;
+ long caretOffset = 0;
+
+ if(MODEL_FLAVOR.equals(flavor)){
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
+ if(object.getFileType() == XModelObject.FILE && !TLDUtil.isTaglib(object)) {
+ IFile f = (IFile)EclipseResourceUtil.getResource(object);
+ canDrop = f != null;
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
+ caretParent = visualDropInfo.getDropContainer();
+ caretOffset = visualDropInfo.getDropOffset();
+ } else {
+ String tagname = getTagName(object);
+ if(tagname.indexOf("taglib") >= 0) tagname= "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
+ if (visualDropInfo.getDropContainer() != null) {
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceDragNode, visualDropInfo, true);
+ canDrop = sourceDropInfo.canDrop();
+ if (canDrop) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder.getInnerDropInfo(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(newVisualDropInfo, visualDropInfo);
+ caretParent = newVisualDropInfo.getDropContainer();
+ caretOffset = newVisualDropInfo.getDropOffset();
+ }
+ }
+ }
+ visualDropInfo.Release();
+ }
+ }else if(XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor) ||
+ XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
+ caretParent = visualDropInfo.getDropContainer();
+ caretOffset = visualDropInfo.getDropOffset();
+ try {
+ canDrop = true;
+ } catch (Exception ex) {
+ VpePlugin.reportProblem(ex);
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrop: " + canDrop + (canDrop ? " container: " + caretParent.getNodeName() + " offset: " + caretOffset : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+ return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+
+ }
+
+ public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object, Node parentNode, int offset) {
+ String tagname = getTagName(object);
+ Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
+ return visualBuilder.getSourceInnerDropInfo(sourceDragNode, parentNode, offset, false);
+ }
+
+ public void externalDropAny(final String flavor, final String data, final Point range, Node container) {
+ if(flavor == null || flavor.length() == 0) return;
+ IDropCommand dropCommand = DropCommandFactory.getInstance().getDropCommand(flavor, JSPTagProposalFactory.getInstance());
+
+ boolean promptAttributes = "yes".equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
+ dropCommand.getDefaultModel().setPromptForTagAttributesRequired(promptAttributes);
+
+ dropCommand.execute(
+ new DropData(
+ flavor,
+ data,
+ sourceEditor.getEditorInput(),
+ (ISourceViewer)sourceEditor.getAdapter(ISourceViewer.class),
+ new VpeSelectionProvider(range.x,range.y),
+ container
+ )
+ );
+ }
+
+ private String getTagName(XModelObject object) {
+ String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
+
+ XModelObject parent = object.getParent();
+ String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+
+ String[] texts = new String[]{"<"+tagname+">"}; //$NON-NLS-1$ //$NON-NLS-2$
+ PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri, defaultPrefix);
+ tagname = texts[0].substring(1,texts[0].length()-1);
+
+ return tagname;
+ }
+
+ public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
+ onHideTooltip();
+
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
+ Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(), (int)visualDropInfo.getDropOffset());
+ VpeSourceInnerDropInfo sourceDropInfo = null;
+
+ if(MODEL_FLAVOR.equals(flavor)){
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
+ if(object.getFileType() == XModelObject.FILE && !TLDUtil.isTaglib(object)) {
+ flavor = "application/x-moz-file"; //$NON-NLS-1$
+ IFile f = (IFile)EclipseResourceUtil.getResource(object);
+ try {
+ data = f.getLocation().toFile().toURL().toString();
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ } else {
+ String tagname = getTagName(object);
+ if(tagname.indexOf("taglib") >= 0) tagname= "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
+ if (visualDropInfo.getDropContainer() != null) {
+ sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceDragNode, visualDropInfo, true);
+ range = selectionBuilder.getSourceSelectionRange(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
+ }
+ }
+ }
+
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ }
+ externalDropAny(flavor, data, range, sourceDropInfo == null?null:sourceDropInfo.getContainer());
+ }
+ }
+
+ public void onShowTooltip(int x, int y, final String text) {
+
+ if (tip != null && !tip.isDisposed()) tip.dispose();
+
+ Display display = visualEditor.getControl().getDisplay();
+ Shell parent = visualEditor.getControl().getShell();
+
+ tip = new Shell(parent, SWT.NO_FOCUS| SWT.ON_TOP);
+ Color bckgColor = new Color(tip.getDisplay(), 255, 250, 236);
+ tip.setBackground(bckgColor);
+
+ Composite composite = tip;
+ GridLayout layout= new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ layout.verticalSpacing= 0;
+ layout.horizontalSpacing= 0;
+ composite.setLayout(layout);
+ GridData gd= new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(gd);
+
+
+ final StyledText tipControlHeaderText = new StyledText(composite, SWT.MULTI | SWT.READ_ONLY);
+
+ tipControlHeaderText.setForeground(bckgColor);
+ tipControlHeaderText.setBackground(bckgColor);
+
+ String formatText = text.trim();
+
+ /** attributeString string containing the pairs attribute and it's value as one string*/
+ String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
+ /** buffer string containing the attribute and the value in the different succeding string*/
+ String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
+
+ tipControlHeaderText.setText(buffer[0].toString());
+
+ tipControlHeaderText.addLineStyleListener(
+ new LineStyleListener() {
+ public void lineGetStyle(LineStyleEvent event){
+ Color color = new Color(tipControlHeaderText.getDisplay(), 201, 51, 40);
+ if (event.lineOffset == 0) {
+ StyleRange st = new StyleRange();
+ st.fontStyle = SWT.BOLD;
+ st.foreground = color;
+ event.styles = new StyleRange[]{st};
+ st.start = event.lineOffset;
+ st.length = event.lineText.length();
+ }
+ }
+ }
+ );
+
+ GridData gridData = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.horizontalSpan = 2;
+ tipControlHeaderText.setLayoutData(gridData);
+
+ StringBuffer tempAttr = new StringBuffer();
+ StringBuffer tempValue = new StringBuffer();
+
+ if (attributeString.length >= 2) {
+ for (int i = 1; i < attributeString.length; i++) {
+ buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
+ if (i == 1) {
+ tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
+ tempValue.append((buffer.length>=2?buffer[1]:"") + " "); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$ //$NON-NLS-2$
+ tempValue.append(" \n" + (buffer.length>=2?buffer[1]:"") + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ final StyledText tipControlAttributeText = new StyledText(composite,
+ SWT.MULTI | SWT.READ_ONLY);
+
+ tipControlAttributeText.setForeground(bckgColor);
+ tipControlAttributeText.setBackground(bckgColor);
+
+ tipControlAttributeText.setText(tempAttr.toString());
+ tipControlAttributeText
+ .addLineStyleListener(new LineStyleListener() {
+ public void lineGetStyle(LineStyleEvent event) {
+ Color color = new Color(tipControlHeaderText
+ .getDisplay(), 42, 148, 0);
+ StyleRange st = new StyleRange();
+ st.start = event.lineOffset;
+ st.length = event.lineText.length();
+ st.foreground = color;
+ st.fontStyle = SWT.NORMAL;
+ event.styles = new StyleRange[] { st };
+ }
+ });
+ GridData gridData1 = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
+ gridData1.horizontalAlignment = GridData.FILL;
+ tipControlAttributeText.setLayoutData(gridData1);
+
+ final StyledText tipControlValueText = new StyledText(composite,
+ SWT.MULTI | SWT.READ_ONLY);
+
+ tipControlValueText.setBackground(bckgColor);
+
+ tipControlValueText.setText(tempValue.toString());
+
+
+
+ GridData gridData2 = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
+ gridData2.horizontalAlignment = GridData.FILL;
+ tipControlValueText.setLayoutData(gridData2);
+ }
+ /*
+ * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
+ * elements inside an inline frame (IFrame tag). The workaround is
+ * to position the tooltip based on the mouse cursor location.
+ */
+ Point point = display.getCursorLocation();
+ /* Assuming cursor is 21x21 because this is the size of
+ * the arrow cursor on Windows
+ */
+ point.y += 21;
+ tip.setLocation(point);
+ tip.pack();
+ tip.setVisible(true);
+ }
+
+ public void onHideTooltip() {
+ if (tip != null && !tip.isDisposed()) tip.dispose();
+ tip = null;
+ }
+
+ public VpePageContext getPageContext() {
+
+ return pageContext;
+ }
+
+ public StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+ public FormatControllerManager getToolbarFormatControllerManager() {
+ return toolbarFormatControllerManager;
+ }
+
+ public void setToolbarFormatControllerManager(FormatControllerManager formatControllerManager) {
+ toolbarFormatControllerManager = formatControllerManager;
+ }
+ public void setSelectionBarController(SelectionBar selectionBar) {
+ this.selectionBar = selectionBar;
+ }
+
+ public IStructuredModel getModel() {
+ return sourceEditor.getModel();
+ }
+
+ public VpeDomMapping getDomMapping() {
+ return domMapping;
+ }
+
+ public VpeIncludeList getIncludeList(){
+ try {
+ if(includeList == null)
+ throw new Exception("includeList - NULL!!!"); //$NON-NLS-1$
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ return includeList;
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
+ if(toolbarFormatControllerManager != null) toolbarFormatControllerManager.selectionChanged();
+ }
+
+ if(selectionBar != null) selectionBar.selectionChanged();
+
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> selectionChanged " + event.getSource()); //$NON-NLS-1$
+ }
+ sourceSelectionChanged();
+ switcher.stopActiveEditor();
+ }
+
+ // nsIClipboardDragDropHooks implementation
+ public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
+ onHideTooltip();
+
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
+ Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(), (int)visualDropInfo.getDropOffset());
+ VpeSourceInnerDropInfo sourceDropInfo = null;
+
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
+
+ String tagname = getTagName(object);
+ if(tagname.indexOf("taglib") >= 0) tagname= "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document)getModel().getAdapter(Document.class)).createElement(tagname);
+ if (visualDropInfo.getDropContainer() != null) {
+ sourceDropInfo = visualBuilder.getSourceInnerDropInfo(sourceDragNode, visualDropInfo, true);
+ range = selectionBuilder.getSourceSelectionRange(sourceDropInfo.getContainer(), sourceDropInfo.getOffset());
+ }
+
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ }
+ final String finalFlavor = flavor;
+ final String finalData = data;
+ final Point finalRange = range;
+ final Node finalDropContainer = sourceDropInfo == null ? null : sourceDropInfo.getContainer();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ externalDropAny(finalFlavor, finalData, finalRange, finalDropContainer);
+ }
+ });
+ }
+ }
+
+ public void drop(Node node, Node parentNode, int offset) {
+ visualBuilder.innerDrop(node, parentNode, offset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.mozilla.interfaces.nsISupports#queryInterface(java.lang.String)
+ */
+ public nsISupports queryInterface(String arg0) {
+ return Mozilla.getInstance().queryInterface(this, arg0);
+ }
+ /**
+ * Calls when editor content should be refreshed
+ */
+ public void onRefresh() {
+ //when we using separate thread to display selection rectangle
+ //it's working better than without
+ /*
+ * HACK
+ * We need wait some time while standart event will be handled
+ * and in process event handles some components are repainted(like buttons)
+ * and flasher are not repainted, so we should paint flasher
+ */
+
+
+ Display.getDefault().asyncExec(new Thread(){
+ public void run(){
+
+ getXulRunnerEditor().showSelectionRectangle();
+ }
+ });
+
+ }
+
+ /**
+ * @return the xulRunnerEditor
+ */
+ public XulRunnerEditor getXulRunnerEditor() {
+ return xulRunnerEditor;
+ }
+
+ /**
+ * @param xulRunnerEditor the xulRunnerEditor to set
+ */
+ public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
+ this.xulRunnerEditor = xulRunnerEditor;
+ }
+
+ /**
+ * Start drag session
+ */
+ public void startDragSession(nsIDOMEvent domEvent) {
+
+ visualBuilder.getDnd().startDragSession(domEvent);
+ }
+
+ public void dragDrop(nsIDOMEvent domEvent) {
+
+ visualBuilder.getDnd().dragDrop(domEvent,this);
+ }
+
+ /**
+ * @return the selectionBuilder
+ */
+ public VpeSelectionBuilder getSelectionBuilder() {
+ return selectionBuilder;
+ }
+
+ /**
+ * @param selectionBuilder the selectionBuilder to set
+ */
+ public void setSelectionBuilder(VpeSelectionBuilder selectionBuilder) {
+ this.selectionBuilder = selectionBuilder;
+ }
+
+}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2008-03-18 15:40:28 UTC (rev 6991)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2008-03-18 15:40:38 UTC (rev 6992)
@@ -1,404 +1,410 @@
-/*******************************************************************************
- * 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.vpe.editor.context;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
-import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
-import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.jboss.tools.common.kb.KbConnectorFactory;
-import org.jboss.tools.common.kb.KbConnectorType;
-import org.jboss.tools.common.kb.wtp.WtpKbConnector;
-import org.jboss.tools.jst.jsp.editor.IVisualContext;
-import org.jboss.tools.jst.jsp.preferences.VpePreference;
-import org.jboss.tools.jst.web.tld.TaglibData;
-import org.jboss.tools.jst.web.tld.VpeTaglibListener;
-import org.jboss.tools.jst.web.tld.VpeTaglibManager;
-import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.editor.VpeEditorPart;
-import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
-import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
-import org.jboss.tools.vpe.editor.bundle.BundleMap;
-import org.jboss.tools.vpe.editor.css.AbsoluteFolderReferenceList;
-import org.jboss.tools.vpe.editor.css.CSSReferenceList;
-import org.jboss.tools.vpe.editor.css.RelativeFolderReferenceList;
-import org.jboss.tools.vpe.editor.css.ResourceReference;
-import org.jboss.tools.vpe.editor.css.TaglibReferenceList;
-import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.template.VpeCreationData;
-import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.util.FileUtil;
-import org.jboss.tools.vpe.editor.util.XmlUtil;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * Contains the information on edited page.
- */
-
-public class VpePageContext implements IVisualContext {
- private Set connectorDocuments = new HashSet();
- private BundleMap bundle;
- private Set bundleDependencySet = new HashSet();
- private VpeSourceDomBuilder sourceBuilder;
- private VpeVisualDomBuilder visualBuilder;
- private VpeEditorPart editPart;
- WtpKbConnector connector;
- private nsIDOMNode currentVisualNode;
-
- //Added by Max Areshkau to increase perfomance of VPE JBIDE-675
- private Map<Node,VpeCreationData> vpeCash;
-
- public VpePageContext(VpeTemplateManager templateManager, BundleMap bundle, VpeEditorPart editPart) {
- this.bundle = bundle;
- this.editPart = editPart;
- }
-
- public VpeSourceDomBuilder getSourceBuilder(){
- return sourceBuilder;
- }
-
- public boolean isAbsolutePosition(){
- if("yes".equals(VpePreference.USE_ABSOLUTE_POSITION.getValue()))return true;
- else return false;
- }
-
- public void setSourceDomBuilder(VpeSourceDomBuilder sourceBuilder) {
- this.sourceBuilder = sourceBuilder;
- refreshConnector();
- }
-
- public void refreshConnector() {
- try {
- IDocument document = sourceBuilder.getStructuredTextViewer().getDocument();
- connector = (WtpKbConnector)KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document);
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- }
- }
-
- public VpeVisualDomBuilder getVisualBuilder(){
- return visualBuilder;
- }
-
- public void setVisualDomBuilder(VpeVisualDomBuilder visualBuilder) {
- this.visualBuilder = visualBuilder;
- }
-
- public VpeDomMapping getDomMapping () {
- return visualBuilder.getDomMapping();
- }
-
- public void clearAll() {
- bundleDependencySet.clear();
- bundle.clearAll();
- //clean a cash nodes
- clearVpeCash();
- }
-
- public void dispose() {
+/*******************************************************************************
+ * 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.vpe.editor.context;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.jboss.tools.common.kb.KbConnectorFactory;
+import org.jboss.tools.common.kb.KbConnectorType;
+import org.jboss.tools.common.kb.wtp.WtpKbConnector;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.jst.web.tld.VpeTaglibListener;
+import org.jboss.tools.jst.web.tld.VpeTaglibManager;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.VpeEditorPart;
+import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
+import org.jboss.tools.vpe.editor.bundle.BundleMap;
+import org.jboss.tools.vpe.editor.css.AbsoluteFolderReferenceList;
+import org.jboss.tools.vpe.editor.css.CSSReferenceList;
+import org.jboss.tools.vpe.editor.css.RelativeFolderReferenceList;
+import org.jboss.tools.vpe.editor.css.ResourceReference;
+import org.jboss.tools.vpe.editor.css.TaglibReferenceList;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.editor.util.FileUtil;
+import org.jboss.tools.vpe.editor.util.XmlUtil;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Contains the information on edited page.
+ */
+
+public class VpePageContext implements IVisualContext {
+ private Set connectorDocuments = new HashSet();
+ private BundleMap bundle;
+ private Set bundleDependencySet = new HashSet();
+ private VpeSourceDomBuilder sourceBuilder;
+ private VpeVisualDomBuilder visualBuilder;
+ private VpeEditorPart editPart;
+ WtpKbConnector connector;
+ private nsIDOMNode currentVisualNode;
+
+ //Added by Max Areshkau to increase perfomance of VPE JBIDE-675
+ private Map<Node,VpeCreationData> vpeCash;
+
+ public VpePageContext(VpeTemplateManager templateManager, BundleMap bundle, VpeEditorPart editPart) {
+ this.bundle = bundle;
+ this.editPart = editPart;
+ }
+
+ public VpeSourceDomBuilder getSourceBuilder(){
+ return sourceBuilder;
+ }
+
+ public boolean isAbsolutePosition(){
+ if("yes".equals(VpePreference.USE_ABSOLUTE_POSITION.getValue()))return true;
+ else return false;
+ }
+
+ public void setSourceDomBuilder(VpeSourceDomBuilder sourceBuilder) {
+ this.sourceBuilder = sourceBuilder;
+ refreshConnector();
+ }
+
+ public void refreshConnector() {
+ try {
+ IDocument document = sourceBuilder.getStructuredTextViewer().getDocument();
+ connector = (WtpKbConnector)KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document);
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public VpeVisualDomBuilder getVisualBuilder(){
+ return visualBuilder;
+ }
+
+ public void setVisualDomBuilder(VpeVisualDomBuilder visualBuilder) {
+ this.visualBuilder = visualBuilder;
+ }
+
+ public VpeDomMapping getDomMapping () {
+ return visualBuilder.getDomMapping();
+ }
+
+ public void clearAll() {
+ bundleDependencySet.clear();
+ bundle.clearAll();
+ //clean a cash nodes
+ clearVpeCash();
+ }
+
+ public void dispose() {
for (Iterator iterator = connectorDocuments.iterator(); iterator.hasNext();) {
IDocument document = (IDocument) iterator.next();
KbConnectorFactory.getIntstance().removeConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document);
}
connectorDocuments.clear();
connectorDocuments = null;
- bundle.dispose();
- clearAll();
- editPart=null;
- connector=null;
- sourceBuilder=null;
- visualBuilder=null;
- }
-
- public BundleMap getBundle() {
- return bundle;
- }
-
- public void addBundleDependency(Element sourceNode) {
- bundleDependencySet.add(sourceNode);
- }
-
- public void removeBundleDependency(Element sourceNode) {
- bundleDependencySet.remove(sourceNode);
- }
-
- public void refreshBundleValues() {
- Iterator iterator = bundleDependencySet.iterator();
- while (iterator.hasNext()) {
- Element sourceElement = (Element) iterator.next();
- visualBuilder.refreshBundleValues(sourceElement);
- }
- }
-
- /**
- * Checks for URI for source node was registred on page
- * @param sourceNode
- * @return true - if uri was registred
- * false- if uri doesn't was registered
- */
- public boolean isCorrectNS(Node sourceNode) {
- String sourcePrefix = sourceNode.getPrefix();
-
- if (sourcePrefix == null || ((ElementImpl)sourceNode).isJSPTag()) {
- return true;
- }
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,this.getSourceBuilder().getStructuredTextViewer().getDocument());
-
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
-
- if(sourceNodeTaglib!=null) {
-
- return true;
- }
- return false;
- }
- /**
- * Returns
- * @param sourceNode
- * @return
- */
-
- public String getSourceTaglibUri(Node sourceNode) {
-
- String sourcePrefix = sourceNode.getPrefix();
- if (sourcePrefix == null || ((ElementImpl) sourceNode).isJSPTag()) {
- return null;
- }
-
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,
- this.getSourceBuilder()
- .getStructuredTextViewer().getDocument());
-
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix,
- taglibs);
-
- if (sourceNodeTaglib == null) {
-
- return null;
- }
- String sourceNodeUri = sourceNodeTaglib.getUri();
-
- return sourceNodeUri;
- }
-
- public VpeEditorPart getEditPart() {
- return editPart;
- }
-
- public void openIncludeFile(String file) {
- IEditorInput input = editPart.getEditorInput();
- IWorkbenchPage workbenchPage = VpePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
- try{
- IFile f = FileUtil.getFile(input, file);
- if (f != null) {
- IDE.openEditor(workbenchPage, f, true);
- }
- }catch(Exception ex){
- VpePlugin.reportProblem(ex);
- }
- }
-
- public ResourceReference[] getIncludeTaglibs() {
- IEditorInput input = getEditPart().getEditorInput();
- IFile file = null;
- if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput)input).getFile();
- }
- ResourceReference[] resourceReferences = new ResourceReference[0];
- if (file != null) {
- resourceReferences = TaglibReferenceList.getInstance().getAllResources(file);
- }
- return resourceReferences;
- }
-
- public ResourceReference[] getIncludeCss() {
- IEditorInput input = getEditPart().getEditorInput();
- IFile file = null;
- if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput)input).getFile();
- }
- ResourceReference[] resourceReferences = new ResourceReference[0];
- if (file != null) {
- resourceReferences = CSSReferenceList.getInstance().getAllResources(file);
- }
- return resourceReferences;
- }
-
- public void installIncludeElements() {
- ResourceReference[] list = getIncludeTaglibs();
- for (int i = 0; i < list.length; i++) {
- ResourceReference reference = list[i];
-// setTaglib(i, reference.getLocation(), reference.getProperties(), false);
- }
-
- list = getIncludeCss();
- for (int i = 0; i < list.length; i++) {
- visualBuilder.addLinkNodeToHead(list[i].getLocation(), "yes");
- }
- }
-
- public ResourceReference getRuntimeRelativeFolder(IFile file) {
- ResourceReference[] list = RelativeFolderReferenceList.getInstance().getAllResources(file);
- if (list.length > 0) {
- return list[list.length - 1];
- }
- return null;
- }
-
- public ResourceReference getRuntimeAbsoluteFolder(IFile file) {
- ResourceReference[] list = AbsoluteFolderReferenceList.getInstance().getAllResources(file);
- if (list.length > 0) {
- return list[list.length - 1];
- }
- return null;
- }
-
-
- private void fireTaglibChanged(VpeTaglibListener taglibListener, List newTaglibs, List delTaglibs) {
- Iterator iter = delTaglibs.iterator();
- while (iter.hasNext()) {
- TaglibData taglib = (TaglibData)iter.next();
- taglibListener.removeTaglib(taglib.getUri(), taglib.getPrefix());
- }
- iter = newTaglibs.iterator();
- while (iter.hasNext()) {
- TaglibData taglib = (TaglibData)iter.next();
- taglibListener.addTaglib(taglib.getUri(), taglib.getPrefix());
- }
- }
-
- public WtpKbConnector getConnector() {
- return connector;
- }
-
- public void addTaglibListener(VpeTaglibListener listener) {
- // TODO Auto-generated method stub
-
- }
-
- public List<TaglibData> getTagLibs(Node sourceNode) {
-
- return XmlUtil.getTaglibsForNode(sourceNode, this.getSourceBuilder().getStructuredTextViewer().getDocument());
- }
-
- public void removeTaglibListener(VpeTaglibListener listener) {
- // TODO Auto-generated method stub
-
- }
-
- public void setReferenceNode(Node node) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * @return the currentVisualNode
- */
- public nsIDOMNode getCurrentVisualNode() {
- return currentVisualNode;
- }
-
- /**
- * @param currentVisualNode the currentVisualNode to set
- */
- public void setCurrentVisualNode(nsIDOMNode currentVisualNode) {
- this.currentVisualNode = currentVisualNode;
- }
-
- /**
- * Removes information about source node from vpe cash
- * @param sourceNode
- */
- public void removeNodeFromVpeCash(Node sourceNode) {
-
- getVpeCash().remove(sourceNode);
- Node parentNode = sourceNode.getParentNode();
- //we should on change remove also parent nodes because information for
- //this nodes doen't actual when we change child
- while(parentNode!=null) {
- getVpeCash().remove(parentNode);
- parentNode=parentNode.getParentNode();
- }
- }
- /**
- * Clears all information in cash
- */
- public void clearVpeCash() {
-
- getVpeCash().clear();
- }
- /**
- * Checs is creation data exist in cash
- * @param sourceNode
- * @return true - if date exist
- * false -otherwise
- */
- public boolean isCreationDataExistInCash(Node sourceNode){
-
-// Iterator<Node> keys = getVpeCash().keySet().iterator();
-//
-// //Map.get() doesn't work correctly for this situation
-//// while(keys.hasNext()){
-//// Node key= keys.next();
-//// if(sourceNode.isEqu alNode(key)) {
-//// return true;
-//// }
-//// }
-//// return false;
- return getVpeCash().containsKey(sourceNode);
- }
- /**
- * Inserts creation data into cash
- * @param sourceNode
- * @param creationData
- */
- public void addCreationDataToCash(Node sourceNode,VpeCreationData creationData) {
- //TODO Max Areshkau JBIDE-675 Adds data to cash, think about cloning creationData
- getVpeCash().put(sourceNode, creationData);
- }
- /**
- * Looks creates data in cash
- * @param sourceNode
- * @return returns creation data
- */
- public VpeCreationData getVpeCreationDataFromCash(Node sourceNode) {
-
- return getVpeCash().get(sourceNode);
- }
- /**
- * Return vpe Cash
- * @return the vpeCash
- */
- private Map<Node, VpeCreationData> getVpeCash() {
-
- if(vpeCash ==null) {
-
- vpeCash = new HashMap<Node, VpeCreationData>();
- }
- return vpeCash;
- }
-
+ bundle.dispose();
+ clearAll();
+ editPart=null;
+ connector=null;
+ sourceBuilder=null;
+ visualBuilder=null;
+ }
+
+ public BundleMap getBundle() {
+ return bundle;
+ }
+
+ public void addBundleDependency(Element sourceNode) {
+ //bundleDependencySet.add(sourceNode);
+ }
+
+ public void removeBundleDependency(Element sourceNode) {
+ bundleDependencySet.remove(sourceNode);
+ }
+
+ public void refreshBundleValues() {
+ if (getVisualBuilder() == null) return;
+ List nodes = getVisualBuilder().getSourceNodes();
+ //Iterator iterator = bundleDependencySet.iterator();
+ Iterator iterator = nodes.iterator();
+ while (iterator.hasNext()) {
+ Object object = iterator.next();
+ if (object instanceof Element) {
+ Element sourceElement = (Element) object;
+ visualBuilder.refreshBundleValues(sourceElement);
+ }
+ }
+ }
+
+ /**
+ * Checks for URI for source node was registred on page
+ * @param sourceNode
+ * @return true - if uri was registred
+ * false- if uri doesn't was registered
+ */
+ public boolean isCorrectNS(Node sourceNode) {
+ String sourcePrefix = sourceNode.getPrefix();
+
+ if (sourcePrefix == null || ((ElementImpl)sourceNode).isJSPTag()) {
+ return true;
+ }
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,this.getSourceBuilder().getStructuredTextViewer().getDocument());
+
+ TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
+
+ if(sourceNodeTaglib!=null) {
+
+ return true;
+ }
+ return false;
+ }
+ /**
+ * Returns
+ * @param sourceNode
+ * @return
+ */
+
+ public String getSourceTaglibUri(Node sourceNode) {
+
+ String sourcePrefix = sourceNode.getPrefix();
+ if (sourcePrefix == null || ((ElementImpl) sourceNode).isJSPTag()) {
+ return null;
+ }
+
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,
+ this.getSourceBuilder()
+ .getStructuredTextViewer().getDocument());
+
+ TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix,
+ taglibs);
+
+ if (sourceNodeTaglib == null) {
+
+ return null;
+ }
+ String sourceNodeUri = sourceNodeTaglib.getUri();
+
+ return sourceNodeUri;
+ }
+
+ public VpeEditorPart getEditPart() {
+ return editPart;
+ }
+
+ public void openIncludeFile(String file) {
+ IEditorInput input = editPart.getEditorInput();
+ IWorkbenchPage workbenchPage = VpePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ try{
+ IFile f = FileUtil.getFile(input, file);
+ if (f != null) {
+ IDE.openEditor(workbenchPage, f, true);
+ }
+ }catch(Exception ex){
+ VpePlugin.reportProblem(ex);
+ }
+ }
+
+ public ResourceReference[] getIncludeTaglibs() {
+ IEditorInput input = getEditPart().getEditorInput();
+ IFile file = null;
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput)input).getFile();
+ }
+ ResourceReference[] resourceReferences = new ResourceReference[0];
+ if (file != null) {
+ resourceReferences = TaglibReferenceList.getInstance().getAllResources(file);
+ }
+ return resourceReferences;
+ }
+
+ public ResourceReference[] getIncludeCss() {
+ IEditorInput input = getEditPart().getEditorInput();
+ IFile file = null;
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput)input).getFile();
+ }
+ ResourceReference[] resourceReferences = new ResourceReference[0];
+ if (file != null) {
+ resourceReferences = CSSReferenceList.getInstance().getAllResources(file);
+ }
+ return resourceReferences;
+ }
+
+ public void installIncludeElements() {
+ ResourceReference[] list = getIncludeTaglibs();
+ for (int i = 0; i < list.length; i++) {
+ ResourceReference reference = list[i];
+// setTaglib(i, reference.getLocation(), reference.getProperties(), false);
+ }
+
+ list = getIncludeCss();
+ for (int i = 0; i < list.length; i++) {
+ visualBuilder.addLinkNodeToHead(list[i].getLocation(), "yes");
+ }
+ }
+
+ public ResourceReference getRuntimeRelativeFolder(IFile file) {
+ ResourceReference[] list = RelativeFolderReferenceList.getInstance().getAllResources(file);
+ if (list.length > 0) {
+ return list[list.length - 1];
+ }
+ return null;
+ }
+
+ public ResourceReference getRuntimeAbsoluteFolder(IFile file) {
+ ResourceReference[] list = AbsoluteFolderReferenceList.getInstance().getAllResources(file);
+ if (list.length > 0) {
+ return list[list.length - 1];
+ }
+ return null;
+ }
+
+
+ private void fireTaglibChanged(VpeTaglibListener taglibListener, List newTaglibs, List delTaglibs) {
+ Iterator iter = delTaglibs.iterator();
+ while (iter.hasNext()) {
+ TaglibData taglib = (TaglibData)iter.next();
+ taglibListener.removeTaglib(taglib.getUri(), taglib.getPrefix());
+ }
+ iter = newTaglibs.iterator();
+ while (iter.hasNext()) {
+ TaglibData taglib = (TaglibData)iter.next();
+ taglibListener.addTaglib(taglib.getUri(), taglib.getPrefix());
+ }
+ }
+
+ public WtpKbConnector getConnector() {
+ return connector;
+ }
+
+ public void addTaglibListener(VpeTaglibListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public List<TaglibData> getTagLibs(Node sourceNode) {
+
+ return XmlUtil.getTaglibsForNode(sourceNode, this.getSourceBuilder().getStructuredTextViewer().getDocument());
+ }
+
+ public void removeTaglibListener(VpeTaglibListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setReferenceNode(Node node) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @return the currentVisualNode
+ */
+ public nsIDOMNode getCurrentVisualNode() {
+ return currentVisualNode;
+ }
+
+ /**
+ * @param currentVisualNode the currentVisualNode to set
+ */
+ public void setCurrentVisualNode(nsIDOMNode currentVisualNode) {
+ this.currentVisualNode = currentVisualNode;
+ }
+
+ /**
+ * Removes information about source node from vpe cash
+ * @param sourceNode
+ */
+ public void removeNodeFromVpeCash(Node sourceNode) {
+
+ getVpeCash().remove(sourceNode);
+ Node parentNode = sourceNode.getParentNode();
+ //we should on change remove also parent nodes because information for
+ //this nodes doen't actual when we change child
+ while(parentNode!=null) {
+ getVpeCash().remove(parentNode);
+ parentNode=parentNode.getParentNode();
+ }
+ }
+ /**
+ * Clears all information in cash
+ */
+ public void clearVpeCash() {
+
+ getVpeCash().clear();
+ }
+ /**
+ * Checs is creation data exist in cash
+ * @param sourceNode
+ * @return true - if date exist
+ * false -otherwise
+ */
+ public boolean isCreationDataExistInCash(Node sourceNode){
+
+// Iterator<Node> keys = getVpeCash().keySet().iterator();
+//
+// //Map.get() doesn't work correctly for this situation
+//// while(keys.hasNext()){
+//// Node key= keys.next();
+//// if(sourceNode.isEqu alNode(key)) {
+//// return true;
+//// }
+//// }
+//// return false;
+ return getVpeCash().containsKey(sourceNode);
+ }
+ /**
+ * Inserts creation data into cash
+ * @param sourceNode
+ * @param creationData
+ */
+ public void addCreationDataToCash(Node sourceNode,VpeCreationData creationData) {
+ //TODO Max Areshkau JBIDE-675 Adds data to cash, think about cloning creationData
+ getVpeCash().put(sourceNode, creationData);
+ }
+ /**
+ * Looks creates data in cash
+ * @param sourceNode
+ * @return returns creation data
+ */
+ public VpeCreationData getVpeCreationDataFromCash(Node sourceNode) {
+
+ return getVpeCash().get(sourceNode);
+ }
+ /**
+ * Return vpe Cash
+ * @return the vpeCash
+ */
+ private Map<Node, VpeCreationData> getVpeCash() {
+
+ if(vpeCash ==null) {
+
+ vpeCash = new HashMap<Node, VpeCreationData>();
+ }
+ return vpeCash;
+ }
+
}
\ No newline at end of file
18 years
JBoss Tools SVN: r6991 - trunk/jsf/plugins/org.jboss.tools.jsf.vpe.facelets/src/org/jboss/tools/jsf/vpe/facelets/template.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-03-18 11:40:28 -0400 (Tue, 18 Mar 2008)
New Revision: 6991
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.facelets/src/org/jboss/tools/jsf/vpe/facelets/template/VpeDefineContainerTemplate.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1896, patch from Snjezana Peco was applied. It's fixed a memmory link error for editiong *.xhtml files.
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.facelets/src/org/jboss/tools/jsf/vpe/facelets/template/VpeDefineContainerTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.facelets/src/org/jboss/tools/jsf/vpe/facelets/template/VpeDefineContainerTemplate.java 2008-03-18 15:40:24 UTC (rev 6990)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.facelets/src/org/jboss/tools/jsf/vpe/facelets/template/VpeDefineContainerTemplate.java 2008-03-18 15:40:28 UTC (rev 6991)
@@ -1,297 +1,308 @@
-/*******************************************************************************
- * 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.jsf.vpe.facelets.template;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.resources.IFile;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.jboss.tools.vpe.editor.VpeIncludeInfo;
-import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
-import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
-import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
-import org.jboss.tools.vpe.editor.template.VpeCreationData;
-import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
-import org.jboss.tools.vpe.editor.template.VpeTemplate;
-import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.util.HTML;
-import org.mozilla.interfaces.nsIDOMAttr;
-import org.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMNamedNodeMap;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIDOMNodeList;
-
-public abstract class VpeDefineContainerTemplate extends VpeAbstractTemplate {
- protected static final String ATTR_TEMPLATE = "template";
- protected static final String NAME = "name";
- protected static final String VALUE = "value";
- int count = 0;
- private static Set<Node> defineContainer = new HashSet<Node>();
-
- @Override
- protected void init(Element templateElement) {
- children = true;
- modify = false;
- initTemplateSections(templateElement, false, true, false, false, false);
- }
-
-
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
- String fileName = null;
- Attr attr = ((Element)sourceNode).getAttributeNode(ATTR_TEMPLATE);
- if (attr != null && attr.getNodeValue().trim().length() > 0) {
- fileName = attr.getNodeValue().trim();
- IFile file = VpeCreatorUtil.getFile(fileName, pageContext);
- if (file != null) {
- if (!pageContext.getVisualBuilder().isFileInIncludeStack(file)) {
- registerDefine(pageContext, sourceNode);
- Document document = VpeCreatorUtil.getDocumentForRead(file, pageContext);
- VpeCreationData creationData = createInclude(document, visualDocument);
- creationData.setData(new TemplateFileInfo(file));
- pageContext.getVisualBuilder().pushIncludeStack(new VpeIncludeInfo((Element)sourceNode, file, document));
- defineContainer.add(sourceNode);
- return creationData;
- }
- }
- }
- VpeCreationData creationData = createStub(fileName, (Element)sourceNode, visualDocument);
- creationData.setData(null);
- return creationData;
- }
-
- private String replacePattern(String origStr, String target,
- String replacement) {
- StringBuilder sb = new StringBuilder();
- String word = "((\\w+)([\\.\\[\\]]*))";
- Matcher m;
- String variable;
- String signs;
- m = Pattern.compile(word).matcher(origStr);
-
- // everything must be found here
- int endIndex = 0;
- int startIndex = 0;
- while (m.find()) {
- variable = m.group(2);
- signs = m.group(3);
- startIndex = m.start(2);
-
- if ((startIndex != 0) && (endIndex != 0)
- && (endIndex != startIndex)) {
- sb.append(origStr.substring(endIndex, startIndex));
- }
-
- if (target.equals(variable)) {
- sb.append(replacement);
- } else {
- sb.append(variable);
- }
- sb.append(signs);
- endIndex = m.end(3);
- }
-
- // append the tail
- if (endIndex != origStr.length()) {
- sb.append(origStr.substring(endIndex, origStr.length()));
- }
-
- if (!"".equals(sb.toString())) {
- return sb.toString();
- }
- return origStr;
- }
-
- private void updateNodeValue(nsIDOMNode node, Map<String, String> paramsMap) {
- Set<String> keys = paramsMap.keySet();
- if (null != node) {
- String nodeValue = node.getNodeValue();
- String curlyBracketResultPattern = "(" + Pattern.quote("#")
- + "\\{(.+?)\\})+?";
- int matcherGroupWithVariable = 2;
-
- if ((null != nodeValue) && (!"".equals(nodeValue))) {
- for (String key : keys) {
- Matcher curlyBracketMatcher = Pattern.compile(
- curlyBracketResultPattern).matcher(nodeValue);
-
- String replacement = paramsMap.get(key);
- if (replacement.startsWith("#{")
- && replacement.endsWith("}")) {
- // remove first 2 signs '#{'
- replacement = replacement.substring(2);
- // remove last '}' sign
- replacement = replacement.substring(0, replacement
- .length() - 1);
- }
-
- int lastPos = 0;
- StringBuilder sb = new StringBuilder();
- lastPos = 0;
- sb = new StringBuilder();
- curlyBracketMatcher.reset(nodeValue);
- boolean firstFind = false;
- boolean find = curlyBracketMatcher.find();
- while (find) {
- if (!firstFind) {
- firstFind = true;
- }
- int start = curlyBracketMatcher
- .start(matcherGroupWithVariable);
- int end = curlyBracketMatcher
- .end(matcherGroupWithVariable);
- String group = replacePattern(curlyBracketMatcher
- .group(matcherGroupWithVariable), key,
- replacement);
- sb.append(nodeValue.substring(lastPos, start));
- sb.append(group);
- lastPos = end;
- find = curlyBracketMatcher.find();
- }
- if (firstFind) {
- sb.append(nodeValue.substring(lastPos, nodeValue
- .length()));
- nodeValue = sb.toString();
- node.setNodeValue(nodeValue);
- }
- }
- }
- }
- }
-
- private void insertParam(nsIDOMNode node, Map<String, String> paramsMap) {
-
- // update current node value
- updateNodeValue(node, paramsMap);
-
- nsIDOMNamedNodeMap attributes = node.getAttributes();
- if (null != attributes) {
- long len = attributes.getLength();
- for (int i = 0; i < len; i++) {
- nsIDOMNode item = attributes.item(i);
- // update attributes node
- updateNodeValue(item, paramsMap);
- }
- }
-
- nsIDOMNodeList children = node.getChildNodes();
- if (null != children) {
- long len = children.getLength();
- for (int i = 0; i < len; i++) {
- nsIDOMNode child = children.item(i);
- // update child node
- insertParam(child, paramsMap);
- }
- }
- }
-
- @Override
- public void validate(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument, VpeCreationData creationData) {
-
- Map<String, String> paramsMap = new HashMap<String, String>();
- NodeList sourceChildren = sourceNode.getChildNodes();
- int len = sourceChildren.getLength();
- for (int i = 0; i < len; i++) {
- Node sourceChild = sourceChildren.item(i);
- if (sourceChild.getNodeType() == Node.ELEMENT_NODE && "param".equals(sourceChild.getLocalName())) {
- String name = ((Element)sourceChild).getAttribute(NAME);
- String value = ((Element)sourceChild).getAttribute(VALUE);
- paramsMap.put(name, value);
- }
- }
- nsIDOMNode node = creationData.getNode();
- insertParam(node, paramsMap);
-
- TemplateFileInfo templateFileInfo = (TemplateFileInfo)creationData.getData();
- if (templateFileInfo != null) {
- VpeIncludeInfo includeInfo = pageContext.getVisualBuilder().popIncludeStack();
- if (includeInfo != null) {
- VpeCreatorUtil.releaseDocumentFromRead(includeInfo.getDocument());
- }
- }
- defineContainer.remove(sourceNode);
- }
- @Override
- public void beforeRemove(VpePageContext pageContext, Node sourceNode, nsIDOMNode visualNode, Object data) {
- TemplateFileInfo templateFileInfo = (TemplateFileInfo)data;
- if (templateFileInfo != null && templateFileInfo.templateFile != null) {
- pageContext.getEditPart().getController().getIncludeList().removeIncludeModel(templateFileInfo.templateFile);
- }
- }
- @Override
- public boolean isRecreateAtAttrChange(VpePageContext pageContext, Element sourceElement, nsIDOMDocument visualDocument, nsIDOMElement visualNode, Object data, String name, String value) {
-
- return true;
- }
-
- private void registerDefine(VpePageContext pageContext, Node defineContainer) {
- VpeTemplate template = null;
- NodeList sourceChildren = defineContainer.getChildNodes();
- int len = sourceChildren.getLength();
- for (int i = 0; i < len; i++) {
- Node sourceChild = sourceChildren.item(i);
- if (sourceChild.getNodeType() == Node.ELEMENT_NODE && "define".equals(sourceChild.getLocalName())) {
- if (template == null) {
- VpeTemplateManager templateManager = pageContext.getVisualBuilder().getTemplateManager();
- template = templateManager.getTemplate(pageContext, (Element)sourceChild, null);
- if (template == null) {
- break;
- }
- }
- pageContext.getVisualBuilder().registerNodes(new VpeElementMapping((Element)sourceChild, null, null, template, null, null));
- }
- }
- }
-
- private VpeCreationData createInclude(Document sourceDocument, nsIDOMDocument visualDocument) {
- nsIDOMElement visualNewElement = visualDocument.createElement(HTML.TAG_DIV);
- VpeVisualDomBuilder.markIncludeElement(visualNewElement);
- VpeCreationData creationData = new VpeCreationData(visualNewElement);
- VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualNewElement);
- NodeList sourceChildren = sourceDocument.getChildNodes();
- int len = sourceChildren.getLength();
- for (int i = 0; i < len; i++) {
- childrenInfo.addSourceChild(sourceChildren.item(i));
- }
- creationData.addChildrenInfo(childrenInfo);
- return creationData;
- }
- @Override
- public boolean containsText() {
- return false;
- }
-
- public static boolean isDefineContainer(Node sourceNode) {
- return defineContainer.contains(sourceNode);
-
- }
-
- protected abstract VpeCreationData createStub(String fileName, Node sourceElement, nsIDOMDocument visualDocument);
-
- static class TemplateFileInfo {
- IFile templateFile;
-
- TemplateFileInfo(IFile templateFile) {
- this.templateFile = templateFile;
- }
- }
-}
+/*******************************************************************************
+ * 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.jsf.vpe.facelets.template;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.jboss.tools.vpe.editor.VpeIncludeInfo;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
+import org.jboss.tools.vpe.editor.template.VpeTemplate;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMAttr;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNamedNodeMap;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+
+public abstract class VpeDefineContainerTemplate extends VpeAbstractTemplate {
+ protected static final String ATTR_TEMPLATE = "template";
+ protected static final String NAME = "name";
+ protected static final String VALUE = "value";
+ int count = 0;
+ private static Set<Node> defineContainer = new HashSet<Node>();
+
+ @Override
+ protected void init(Element templateElement) {
+ children = true;
+ modify = false;
+ initTemplateSections(templateElement, false, true, false, false, false);
+ }
+
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
+ String fileName = null;
+ Attr attr = ((Element)sourceNode).getAttributeNode(ATTR_TEMPLATE);
+ if (attr != null && attr.getNodeValue().trim().length() > 0) {
+ fileName = attr.getNodeValue().trim();
+ IFile file = VpeCreatorUtil.getFile(fileName, pageContext);
+ if (file != null) {
+ if (!pageContext.getVisualBuilder().isFileInIncludeStack(file)) {
+ registerDefine(pageContext, sourceNode);
+ Document document = pageContext.getVisualBuilder().getIncludeDocuments().get(file);
+ if (document == null) {
+ document = VpeCreatorUtil.getDocumentForRead(file, pageContext);
+ if (document != null)
+ pageContext.getVisualBuilder().getIncludeDocuments().put(file, document);
+ }
+ //Document document = VpeCreatorUtil.getDocumentForRead(file, pageContext);
+ if (document != null) {
+ VpeCreationData creationData = createInclude(document,
+ visualDocument);
+ creationData.setData(new TemplateFileInfo(file));
+ pageContext.getVisualBuilder().pushIncludeStack(
+ new VpeIncludeInfo((Element) sourceNode, file,
+ document));
+ defineContainer.add(sourceNode);
+ return creationData;
+ }
+ }
+ }
+ }
+ VpeCreationData creationData = createStub(fileName, (Element)sourceNode, visualDocument);
+ creationData.setData(null);
+ return creationData;
+ }
+
+ private String replacePattern(String origStr, String target,
+ String replacement) {
+ StringBuilder sb = new StringBuilder();
+ String word = "((\\w+)([\\.\\[\\]]*))";
+ Matcher m;
+ String variable;
+ String signs;
+ m = Pattern.compile(word).matcher(origStr);
+
+ // everything must be found here
+ int endIndex = 0;
+ int startIndex = 0;
+ while (m.find()) {
+ variable = m.group(2);
+ signs = m.group(3);
+ startIndex = m.start(2);
+
+ if ((startIndex != 0) && (endIndex != 0)
+ && (endIndex != startIndex)) {
+ sb.append(origStr.substring(endIndex, startIndex));
+ }
+
+ if (target.equals(variable)) {
+ sb.append(replacement);
+ } else {
+ sb.append(variable);
+ }
+ sb.append(signs);
+ endIndex = m.end(3);
+ }
+
+ // append the tail
+ if (endIndex != origStr.length()) {
+ sb.append(origStr.substring(endIndex, origStr.length()));
+ }
+
+ if (!"".equals(sb.toString())) {
+ return sb.toString();
+ }
+ return origStr;
+ }
+
+ private void updateNodeValue(nsIDOMNode node, Map<String, String> paramsMap) {
+ Set<String> keys = paramsMap.keySet();
+ if (null != node) {
+ String nodeValue = node.getNodeValue();
+ String curlyBracketResultPattern = "(" + Pattern.quote("#")
+ + "\\{(.+?)\\})+?";
+ int matcherGroupWithVariable = 2;
+
+ if ((null != nodeValue) && (!"".equals(nodeValue))) {
+ for (String key : keys) {
+ Matcher curlyBracketMatcher = Pattern.compile(
+ curlyBracketResultPattern).matcher(nodeValue);
+
+ String replacement = paramsMap.get(key);
+ if (replacement.startsWith("#{")
+ && replacement.endsWith("}")) {
+ // remove first 2 signs '#{'
+ replacement = replacement.substring(2);
+ // remove last '}' sign
+ replacement = replacement.substring(0, replacement
+ .length() - 1);
+ }
+
+ int lastPos = 0;
+ StringBuilder sb = new StringBuilder();
+ lastPos = 0;
+ sb = new StringBuilder();
+ curlyBracketMatcher.reset(nodeValue);
+ boolean firstFind = false;
+ boolean find = curlyBracketMatcher.find();
+ while (find) {
+ if (!firstFind) {
+ firstFind = true;
+ }
+ int start = curlyBracketMatcher
+ .start(matcherGroupWithVariable);
+ int end = curlyBracketMatcher
+ .end(matcherGroupWithVariable);
+ String group = replacePattern(curlyBracketMatcher
+ .group(matcherGroupWithVariable), key,
+ replacement);
+ sb.append(nodeValue.substring(lastPos, start));
+ sb.append(group);
+ lastPos = end;
+ find = curlyBracketMatcher.find();
+ }
+ if (firstFind) {
+ sb.append(nodeValue.substring(lastPos, nodeValue
+ .length()));
+ nodeValue = sb.toString();
+ node.setNodeValue(nodeValue);
+ }
+ }
+ }
+ }
+ }
+
+ private void insertParam(nsIDOMNode node, Map<String, String> paramsMap) {
+
+ // update current node value
+ updateNodeValue(node, paramsMap);
+
+ nsIDOMNamedNodeMap attributes = node.getAttributes();
+ if (null != attributes) {
+ long len = attributes.getLength();
+ for (int i = 0; i < len; i++) {
+ nsIDOMNode item = attributes.item(i);
+ // update attributes node
+ updateNodeValue(item, paramsMap);
+ }
+ }
+
+ nsIDOMNodeList children = node.getChildNodes();
+ if (null != children) {
+ long len = children.getLength();
+ for (int i = 0; i < len; i++) {
+ nsIDOMNode child = children.item(i);
+ // update child node
+ insertParam(child, paramsMap);
+ }
+ }
+ }
+
+ @Override
+ public void validate(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument, VpeCreationData creationData) {
+
+ Map<String, String> paramsMap = new HashMap<String, String>();
+ NodeList sourceChildren = sourceNode.getChildNodes();
+ int len = sourceChildren.getLength();
+ for (int i = 0; i < len; i++) {
+ Node sourceChild = sourceChildren.item(i);
+ if (sourceChild.getNodeType() == Node.ELEMENT_NODE && "param".equals(sourceChild.getLocalName())) {
+ String name = ((Element)sourceChild).getAttribute(NAME);
+ String value = ((Element)sourceChild).getAttribute(VALUE);
+ paramsMap.put(name, value);
+ }
+ }
+ nsIDOMNode node = creationData.getNode();
+ insertParam(node, paramsMap);
+
+ TemplateFileInfo templateFileInfo = (TemplateFileInfo)creationData.getData();
+ if (templateFileInfo != null) {
+ VpeIncludeInfo includeInfo = pageContext.getVisualBuilder().popIncludeStack();
+ if (includeInfo != null) {
+ // VpeCreatorUtil.releaseDocumentFromRead(includeInfo.getDocument());
+ }
+ }
+ defineContainer.remove(sourceNode);
+ }
+ @Override
+ public void beforeRemove(VpePageContext pageContext, Node sourceNode, nsIDOMNode visualNode, Object data) {
+ TemplateFileInfo templateFileInfo = (TemplateFileInfo)data;
+ if (templateFileInfo != null && templateFileInfo.templateFile != null) {
+ pageContext.getEditPart().getController().getIncludeList().removeIncludeModel(templateFileInfo.templateFile);
+ }
+ }
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext, Element sourceElement, nsIDOMDocument visualDocument, nsIDOMElement visualNode, Object data, String name, String value) {
+
+ return true;
+ }
+
+ private void registerDefine(VpePageContext pageContext, Node defineContainer) {
+ VpeTemplate template = null;
+ NodeList sourceChildren = defineContainer.getChildNodes();
+ int len = sourceChildren.getLength();
+ for (int i = 0; i < len; i++) {
+ Node sourceChild = sourceChildren.item(i);
+ if (sourceChild.getNodeType() == Node.ELEMENT_NODE && "define".equals(sourceChild.getLocalName())) {
+ if (template == null) {
+ VpeTemplateManager templateManager = pageContext.getVisualBuilder().getTemplateManager();
+ template = templateManager.getTemplate(pageContext, (Element)sourceChild, null);
+ if (template == null) {
+ break;
+ }
+ }
+ pageContext.getVisualBuilder().registerNodes(new VpeElementMapping((Element)sourceChild, null, null, template, null, null));
+ }
+ }
+ }
+
+ private VpeCreationData createInclude(Document sourceDocument, nsIDOMDocument visualDocument) {
+ nsIDOMElement visualNewElement = visualDocument.createElement(HTML.TAG_DIV);
+ VpeVisualDomBuilder.markIncludeElement(visualNewElement);
+ VpeCreationData creationData = new VpeCreationData(visualNewElement);
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualNewElement);
+ NodeList sourceChildren = sourceDocument.getChildNodes();
+ int len = sourceChildren.getLength();
+ for (int i = 0; i < len; i++) {
+ childrenInfo.addSourceChild(sourceChildren.item(i));
+ }
+ creationData.addChildrenInfo(childrenInfo);
+ return creationData;
+ }
+ @Override
+ public boolean containsText() {
+ return false;
+ }
+
+ public static boolean isDefineContainer(Node sourceNode) {
+ return defineContainer.contains(sourceNode);
+
+ }
+
+ protected abstract VpeCreationData createStub(String fileName, Node sourceElement, nsIDOMDocument visualDocument);
+
+ static class TemplateFileInfo {
+ IFile templateFile;
+
+ TemplateFileInfo(IFile templateFile) {
+ this.templateFile = templateFile;
+ }
+ }
+}
18 years
JBoss Tools SVN: r6990 - in trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp: support/kb and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-03-18 11:40:24 -0400 (Tue, 18 Mar 2008)
New Revision: 6990
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPTextJspKbConnector.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1896, patch from Snjezana Peco was applied. It's fixed a memmory link error for editiong *.xhtml files.
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2008-03-18 15:32:57 UTC (rev 6989)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2008-03-18 15:40:24 UTC (rev 6990)
@@ -1,1131 +1,1131 @@
-/*******************************************************************************
- * 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.jst.jsp.jspeditor;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextEvent;
-import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IOverviewRuler;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP;
-import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.DragSource;
-import org.eclipse.swt.dnd.DropTarget;
-import org.eclipse.swt.dnd.DropTargetAdapter;
-import org.eclipse.swt.dnd.DropTargetEvent;
-import org.eclipse.swt.dnd.DropTargetListener;
-import org.eclipse.swt.dnd.FileTransfer;
-import org.eclipse.swt.dnd.HTMLTransfer;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.editors.text.ILocationProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.ITextEditorActionConstants;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetSorter;
-import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
-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.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
-import org.eclipse.wst.sse.ui.internal.IModelProvider;
-import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
-import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
-import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
-import org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage;
-import org.eclipse.wst.sse.ui.internal.provisional.extensions.ConfigurationPointCalculator;
-import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration;
-import org.eclipse.wst.xml.core.internal.document.AttrImpl;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
-import org.jboss.tools.common.meta.action.XActionInvoker;
-import org.jboss.tools.common.model.XModelBuffer;
-import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.XModelTransferBuffer;
-import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
-import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
-import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
-import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.DropData;
-import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
-import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
-import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
-import org.jboss.tools.common.model.ui.texteditors.TextMerge;
-import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDrop;
-import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDropProvider;
-import org.jboss.tools.common.model.ui.views.palette.IIgnoreSelection;
-import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
-import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
-import org.jboss.tools.common.text.xml.IOccurrencePreferenceProvider;
-import org.jboss.tools.common.text.xml.XmlEditorPlugin;
-import org.jboss.tools.common.text.xml.ui.FreeCaretStyledText;
-import org.jboss.tools.jst.jsp.HTMLTextViewerConfiguration;
-import org.jboss.tools.jst.jsp.JSPTextViewerConfiguration;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
-import org.jboss.tools.jst.jsp.editor.ITextFormatter;
-import org.jboss.tools.jst.jsp.editor.IVisualContext;
-import org.jboss.tools.jst.jsp.editor.IVisualController;
-import org.jboss.tools.jst.jsp.outline.JSPContentOutlineConfiguration;
-import org.jboss.tools.jst.jsp.outline.JSPPropertySheetConfiguration;
-import org.jboss.tools.jst.jsp.preferences.VpePreference;
-import org.jboss.tools.jst.jsp.support.kb.WTPTextJspKbConnector;
-import org.jboss.tools.jst.jsp.text.xpl.IStructuredTextOccurrenceStructureProvider;
-import org.jboss.tools.jst.jsp.text.xpl.StructuredTextOccurrenceStructureProviderRegistry;
-import org.jboss.tools.jst.jsp.ui.action.ExtendedFormatAction;
-import org.jboss.tools.jst.jsp.ui.action.IExtendedAction;
-import org.jboss.tools.jst.web.tld.VpeTaglibManager;
-import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-/**
- * @author Jeremy
- *
- */
-public class JSPTextEditor extends StructuredTextEditor implements
- ITextListener, IJSPTextEditor, ITextFormatter,
- IOccurrencePreferenceProvider {
- private IStructuredTextOccurrenceStructureProvider fOccurrenceModelUpdater;
-
- TextEditorDrop dnd = new TextEditorDrop();
-
- JSPMultiPageEditor parentEditor;
-
- long timeStamp = -1;
-
- long savedTimeStamp = -1;
-
- IVisualController vpeController;
- //Added By Max Areshkau
- //Fix for JBIDE-788
- protected SourceEditorPageContext pageContext = null;
-
- public JSPTextEditor(JSPMultiPageEditor parentEditor) {
- JspEditorPlugin.getDefault().initDefaultPluginPreferences();
- dnd.setTextEditorDropProvider(new TextEditorDropProviderImpl());
- this.parentEditor = parentEditor;
- super
- .setSourceViewerConfiguration(new JSPTextViewerConfiguration());
- }
-
- protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
- if (config instanceof StructuredTextViewerConfigurationJSP) {
- if (!(config instanceof JSPTextViewerConfiguration)) {
- config = new JSPTextViewerConfiguration();
- }
- } else if (config instanceof StructuredTextViewerConfigurationHTML) {
- if (!(config instanceof HTMLTextViewerConfiguration)) {
- config = new HTMLTextViewerConfiguration();
- }
- } else {
- config = new JSPTextViewerConfiguration();
- }
- super.setSourceViewerConfiguration(config);
- }
-
- /** This is *only* for allowing unit tests to access the source configuration. */
- public SourceViewerConfiguration getSourceViewerConfigurationForTest () {
- return getSourceViewerConfiguration();
- }
- //Added By Max Areshkau
- //Fix for JBIDE-788
- public IVisualContext getPageContext() {
-
- if (pageContext==null) {
- pageContext = new SourceEditorPageContext();
- }
- IDocument document = getTextViewer().getDocument();
- int offset = this.getTextViewer().getTextWidget().getCaretOffset();
- IndexedRegion treeNode = ContentAssistUtils.getNodeAt(this.getTextViewer(), offset);
- Node node = (Node) treeNode;
- pageContext.setReferenceNode(node);
- pageContext.setDocument(document);
-
- return pageContext;
- }
-
- protected void initializeDrop(ITextViewer textViewer) {
-
- Composite c = textViewer.getTextWidget();
- Label l = new Label(c, SWT.NONE);
- l.dispose();
- }
-
- private ConfigurableContentOutlinePage fOutlinePage = null;
-
- private OutlinePageListener fOutlinePageListener = null;
-
- private IPropertySheetPage fPropertySheetPage;
-
- public Object getAdapter(Class adapter) {
- if (ISourceViewer.class.equals(adapter)) {
- return JSPTextEditor.this.getSourceViewer();
- } else if (IContentOutlinePage.class.equals(adapter)) {
- if (fOutlinePage == null || fOutlinePage.getControl() == null
- || fOutlinePage.getControl().isDisposed()) {
- IStructuredModel internalModel = getModel();
- ContentOutlineConfiguration cfg = new JSPContentOutlineConfiguration(
- this);
- if (cfg != null) {
- ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage();
- outlinePage.setConfiguration(cfg);
- if (internalModel != null) {
- outlinePage.setInputContentTypeIdentifier(internalModel
- .getContentTypeIdentifier());
- outlinePage.setInput(internalModel);
- }
-
- if (fOutlinePageListener == null) {
- fOutlinePageListener = new OutlinePageListener();
- }
-
- outlinePage
- .addSelectionChangedListener(fOutlinePageListener);
- outlinePage.addDoubleClickListener(fOutlinePageListener);
-
- fOutlinePage = outlinePage;
- }
- }
- return fOutlinePage;
- } else if (IPropertySheetPage.class == adapter) {
- if (fPropertySheetPage == null
- || fPropertySheetPage.getControl() == null
- || fPropertySheetPage.getControl().isDisposed()) {
- JSPPropertySheetConfiguration cfg = new JSPPropertySheetConfiguration();
- if (cfg != null) {
- ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage();
- propertySheetPage.setConfiguration(cfg);
- fPropertySheetPage = propertySheetPage;
- setSorter(cfg.getSorter(), propertySheetPage);
- }
- }
- return fPropertySheetPage;
- }
- return super.getAdapter(adapter);
- }
-
- private void setSorter(PropertySheetSorter sorter,
- ConfigurablePropertySheetPage sheet) {
- try {
- Method method = PropertySheetPage.class.getDeclaredMethod(
- "setSorter", new Class[] { PropertySheetSorter.class });
- method.setAccessible(true);
- method.invoke(sheet, new Object[] { sorter });
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public String getEditorId() {
- return JSPUIPlugin.ID;
- }
-
- public IStructuredTextOccurrenceStructureProvider getOccurrencePreferenceProvider() {
- return fOccurrenceModelUpdater;
- }
-
- public void createPartControl(Composite parent) {
- super.createPartControl(parent);
-
- StructuredTextOccurrenceStructureProviderRegistry registry = XmlEditorPlugin
- .getDefault().getOccurrenceStructureProviderRegistry(
- JspEditorPlugin.PLUGIN_ID);
- fOccurrenceModelUpdater = registry
- .getCurrentOccurrenceProvider(JspEditorPlugin.PLUGIN_ID);
-
- if (fOccurrenceModelUpdater != null)
- fOccurrenceModelUpdater.install(this, getTextViewer());
-
- installActivePropmtSupport();
-
- createDrop();
- setModified(false);
- getSourceViewer().removeTextListener(this);
- getSourceViewer().addTextListener(this);
-
- Object dtid = getSourceViewer().getTextWidget().getData("DropTarget");
- if (dtid != null) {
- if (dtid instanceof DropTarget) {
- DropTarget dropTarget = (DropTarget) dtid;
- dropTarget.addDropListener(new DropTargetAdapter() {
- private FreeCaretStyledText getFreeCaretControl(
- Object sourceOrTarget) {
- if (sourceOrTarget == null)
- return null;
-
- Object control = null;
-
- if (sourceOrTarget instanceof DropTarget) {
- control = ((DropTarget) sourceOrTarget)
- .getControl();
- } else if (sourceOrTarget instanceof DragSource) {
- control = ((DragSource) sourceOrTarget)
- .getControl();
- } else
- return null;
-
- if (control instanceof FreeCaretStyledText)
- return (FreeCaretStyledText) control;
- return null;
- }
-
- private int getPosition(StyledText t, int x, int y) {
- try {
- Point pp = t.toControl(x, y);
- x = pp.x;
- y = pp.y;
- int lineIndex = (t.getTopPixel() + y)
- / t.getLineHeight();
- if (lineIndex >= t.getLineCount()) {
- return t.getCharCount();
- } else {
- int c = 0;
- try {
- c = t.getOffsetAtLocation(new Point(x, y));
- if (c < 0)
- c = 0;
- } catch (Exception ex) {
- c = t.getOffsetAtLine(lineIndex + 1)
- - (t.getLineDelimiter() == null ? 0
- : t.getLineDelimiter()
- .length());
- }
- return c;
- }
- } catch (Exception e) {
- return 0;
- }
- }
-
- public void dragEnter(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(true);
- }
-
- public void dragLeave(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(false);
- }
-
- public void dragOperationChanged(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(false);
- }
-
- public void dragOver(DropTargetEvent event) {
- FreeCaretStyledText fcst = getFreeCaretControl(event.widget);
- int pos = getPosition(fcst, event.x, event.y);
- Point p = fcst.getLocationAtOffset(pos);
- fcst.myRedraw(p.x, p.y);
- }
-
- public void drop(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(false);
- }
- });
- }
- }
- }
-
- protected ISourceViewer createSourceViewer(Composite parent,
- IVerticalRuler ruler, int styles) {
- ISourceViewer sv = super.createSourceViewer(parent, ruler, styles);
- sv.getTextWidget().addFocusListener(new TextFocusListener());
- return sv;
- }
-
- protected StructuredTextViewer createStructedTextViewer(Composite parent,
- IVerticalRuler verticalRuler, int styles) {
- return new JSPStructuredTextViewer(parent, verticalRuler,
- getOverviewRuler(), isOverviewRulerVisible(), styles,
- parentEditor, this);
- }
-
- class TextFocusListener extends FocusAdapter {
- public void focusLost(FocusEvent e) {
- if (JSPTextEditor.super.isDirty()) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- Thread.sleep(200);
- } catch (InterruptedException exc) {
- JspEditorPlugin.getPluginLog().logError(exc);
- }
- save();
- }
- });
- }
- }
- }
-
- public void save() {
- if (!lock && isModified()) {
- lock = true;
- try {
- FileAnyImpl f = (FileAnyImpl) getModelObject();
- if (f != null)
- f.edit(getSourceViewer().getDocument().get());
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } finally {
- setModified(false);
- lock = false;
- }
- }
- }
-
- boolean modified = false;
-
- public void setModified(boolean set) {
- if (this.modified != set) {
- this.modified = set;
- if (set) {
- XModelObject o = getModelObject();
- if (o != null)
- o.setModified(true);
- }
- super.firePropertyChange(IEditorPart.PROP_DIRTY);
- }
- }
-
- public void updateModification() {
- //added by Max Areshkau
- //Fix for JBIDE-788
- getPageContext().refreshBundleValues();
-
- XModelObject object = getModelObject();
- if (object != null && !object.isModified() && isModified()) {
- setModified(false);
- } else {
- firePropertyChange(ITextEditor.PROP_DIRTY);
- }
- }
-
- public boolean isModified() {
- return modified;
- }
-
- protected void doSetInput(IEditorInput input) throws CoreException {
- super.doSetInput(XModelObjectEditorInput.checkInput(input));
- if (getSourceViewer() != null
- && getSourceViewer().getDocument() != null) {
- getSourceViewer().removeTextListener(this);
- getSourceViewer().addTextListener(this);
- }
- if (listener != null)
- listener.dispose();
- listener = null;
- XModelObject o = getModelObject();
- if (o instanceof FileAnyImpl) {
- listener = new BodyListenerImpl((FileAnyImpl) o);
- }
- }
-
- boolean lock = false;
-
- public boolean isDirty() {
- if (getEditorInput() instanceof IModelObjectEditorInput) {
- XModelObject o = getModelObject();
- if (o != null && o.isModified())
- return true;
- else {
- return isModified();
- }
- } else {
- return super.isDirty();
- }
- }
-
- public void doSave(IProgressMonitor monitor) {
- XModelObject o = getModelObject();
- super.doSave(monitor);
- if (o != null && (monitor == null || !monitor.isCanceled())) {
- if (o != null)
- save();
- if (getEditorInput() instanceof ILocationProvider) {
- XModelObject p = o.getParent();
- if (p instanceof FolderImpl) {
- ((FolderImpl) p).saveChild(o);
- }
- } else {
- o.setModified(false);
- XModelObjectLoaderUtil.updateModifiedOnSave(o);
- }
- super.firePropertyChange(IEditorPart.PROP_DIRTY);
- }
- }
-
- public void firePropertyChangeDirty() {
- super.firePropertyChange(IEditorPart.PROP_DIRTY);
- }
-
- public XModelObject getModelObject() {
- if (getEditorInput() instanceof IModelObjectEditorInput) {
- return ((IModelObjectEditorInput) getEditorInput())
- .getXModelObject();
- }
- return null;
- }
-
- class TextEditorDropProviderImpl implements TextEditorDropProvider {
-
- public ISourceViewer getSourceViewer() {
- return JSPTextEditor.this.getSourceViewer();
- }
-
- public XModelObject getModelObject() {
- return JSPTextEditor.this.getModelObject();
- }
-
- public void insert(Properties p) {
- PaletteInsertHelper.insertIntoEditor(getSourceViewer(), p);
- }
-
- }
-
- public void textChanged(TextEvent event) {
- if (event.getDocumentEvent() != null) {
- setModified(true);
- }
- }
-
- public void doRevertToSaved() {
- save();
- XModelObject o = getModelObject();
- if (o == null) {
- super.doRevertToSaved();
- return;
- }
- Properties p = new Properties();
- XActionInvoker.invoke("DiscardActions.Discard", o, p);
- if (!"true".equals(p.getProperty("done")))
- return;
- super.doRevertToSaved();
- if (o.isModified())
- o.setModified(false);
- modified = false;
- firePropertyChange(IEditorPart.PROP_DIRTY);
- updatePartControl(getEditorInput());
- }
-
- public IAnnotationModel getAnnotationModel() {
- return getSourceViewer().getAnnotationModel();
- }
-
- private WTPTextJspKbConnector wtpTextJspKbConnector;
-
- private void installActivePropmtSupport() {
- try {
- IDocument document = getTextViewer().getDocument();
- IStructuredModel model = null;
- if (getDocumentProvider() instanceof IModelProvider) {
- model = ((IModelProvider) getDocumentProvider())
- .getModel(getEditorInput());
- } else {
- if (document instanceof IStructuredDocument) {
- model = getModel();
- }
- }
- if (wtpTextJspKbConnector == null
- && model != null
- && (getContentType().toLowerCase().indexOf("jsp") != -1 || getContentType()
- .toLowerCase().indexOf("html") != -1)) {
- wtpTextJspKbConnector = new WTPTextJspKbConnector(
- getEditorInput(), document, model);
- wtpTextJspKbConnector.setTaglibManagerProvider(parentEditor);
- }
- } catch (Exception x) {
- JspEditorPlugin.getPluginLog().logError("Error while installing active prpmpting support", x);
- }
- }
-
- private String getContentType() {
- String type = null;
- try {
- type = getModel().getContentTypeIdentifier();
- } finally {
- if (type == null)
- type = "";
- }
- return type;
- }
-
- public WTPTextJspKbConnector getWTPTextJspKbConnector() {
- return wtpTextJspKbConnector;
- }
-
- public static class JSPStructuredTextViewer extends StructuredTextViewer
- implements VpeTaglibManagerProvider, IIgnoreSelection {
-
- boolean insertFromPallete = false;
-
- private VpeTaglibManagerProvider provider;
-
- private JSPTextEditor editor;
-
- private boolean ignore = false;
-
- public JSPStructuredTextViewer(Composite parent,
- IVerticalRuler verticalRuler, int styles) {
- super(parent, verticalRuler, null, false, styles);
- }
-
- public JSPStructuredTextViewer(Composite parent,
- IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
- boolean showAnnotationsOverview, int styles,
- VpeTaglibManagerProvider provider, JSPTextEditor editor) {
- super(parent, verticalRuler, overviewRuler,
- showAnnotationsOverview, styles);
- this.provider = provider;
- this.editor = editor;
- }
-
- protected StyledText createTextWidget(Composite parent, int styles) {
- return new FreeCaretStyledText(parent, styles);
- }
-
- public VpeTaglibManager getTaglibManager() {
- //added by Max Areshkau
- //Fix for JBIDE-788
- if (getEditor() != null) {
- if(getEditor().getPageContext() instanceof VpeTaglibManager)
-
-
- return (VpeTaglibManager)getEditor().getPageContext();
- }
- return null;
- }
-
- public boolean doesIgnore() {
- return ignore;
- }
-
- public void setIgnore(boolean ignore) {
- this.ignore = ignore;
- }
-
- public void doOperation(int operation) {
- if (operation == UNDO || operation == REDO
- || operation == FORMAT_DOCUMENT
- || operation == FORMAT_ACTIVE_ELEMENTS) {
- if (editor.getVPEController() != null) {
- editor.getVPEController().preLongOperation();
- }
- }
-
- super.doOperation(operation);
-
- if (operation == UNDO || operation == REDO
- || operation == FORMAT_DOCUMENT
- || operation == FORMAT_ACTIVE_ELEMENTS) {
- if (editor.getVPEController() != null) {
- editor.getVPEController().postLongOperation();
- }
- }
- }
-
- protected void handleDispose() {
- if (editor != null && editor.getSourceViewer() != null && editor.getSourceViewer().getTextWidget() != null && editor.getVPEController() != null) {
- StyledText widget = editor.getSourceViewer().getTextWidget();
- widget.removeSelectionListener(editor.getVPEController());
- }
- super.handleDispose();
- }
-
-
- /**
- * @return the editor
- */
- //Added By Max Areshkau
- //Fix for JBIDE-788
- public JSPTextEditor getEditor() {
- return editor;
- }
-
- /**
- * @param editor the editor to set
- */
- //Added By Max Areshkau
- //Fix for JBIDE-788
- public void setEditor(JSPTextEditor editor) {
- this.editor = editor;
- }
-
- }
- public JSPMultiPageEditor getParentEditor() {
- return parentEditor;
- }
-
- public void setVPEController(IVisualController c) {
- vpeController = c;
- }
-
- public IVisualController getVPEController() {
- return vpeController;
- }
-
- public void runDropCommand(final String flavor, final String data) {
- XModelBuffer b = XModelTransferBuffer.getInstance().getBuffer();
- final XModelObject o = b == null ? null : b.source();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if(o != null && !XModelTransferBuffer.getInstance().isEnabled()) {
- XModelTransferBuffer.getInstance().enable();
- XModelTransferBuffer.getInstance().getBuffer().addSource(o);
- }
- try {
- DropData dropData = new DropData(flavor,
- data,
- getEditorInput(), getSourceViewer(),
- getSelectionProvider());
- dropData.setAttributeName(dropContext.getAttributeName());
- IDropCommand dropCommand = DropCommandFactory.getInstance().getDropCommand(flavor, JSPTagProposalFactory.getInstance());
-
- boolean promptAttributes = "yes".equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
- dropCommand.getDefaultModel().setPromptForTagAttributesRequired(promptAttributes);
- dropCommand.execute(dropData);
- } finally {
- XModelTransferBuffer.getInstance().disable();
- }
- }
- });
- }
-
- private void createDrop() {
- DropTarget target = new DropTarget(getSourceViewer().getTextWidget(),
- DND.DROP_MOVE | DND.DROP_COPY);
- Transfer[] types = new Transfer[] { ModelTransfer.getInstance(),
- HTMLTransfer.getInstance(), TextTransfer.getInstance(),
- FileTransfer.getInstance() };
- target.setTransfer(types);
- target.addDropListener(new DTL());
- }
-
- DropContext dropContext = new DropContext();
-
- class DTL implements DropTargetListener {
- int lastpos = -1;
-
- int lastdetail = -1;
-
- public void dragEnter(DropTargetEvent event) {
- lastpos = -1;
- }
-
- public void dragLeave(DropTargetEvent event) {
- lastpos = -1;
- }
-
- public void dragOperationChanged(DropTargetEvent event) {
- }
-
- public void dragOver(DropTargetEvent event) {
- if (!isEditable()
- || (getModelObject() != null && !getModelObject()
- .isObjectEditable())) {
- event.detail = DND.DROP_NONE;
- return;
- }
- dropContext.setDropTargetEvent(event);
- if (dropContext.getFlavor() == null) {
- event.detail = DND.DROP_NONE;
- return;
- }
- // Drop from VPE to Source is forbidden
- if (dropContext.getFlavor().equals("text/html")) {
- if (InnerDragBuffer.object != null) {
- event.detail = DND.DROP_NONE;
- }
- return;
- }
- int pos = getPosition(event.x, event.y);
- if (lastpos == pos && pos >= 0) {
- pos = lastpos;
- event.detail = lastdetail;
- return;
- }
- lastpos = pos;
- dropContext.clean();
- getSourceViewer().getDocument();
- IndexedRegion region = getModel().getIndexedRegion(pos);
- if (region instanceof ElementImpl) {
- ElementImpl jspElement = (ElementImpl) region;
- NamedNodeMap attributes = jspElement.getAttributes();
- if (pos == jspElement.getStartOffset()
- || pos == jspElement.getEndStartOffset()) {
- event.detail = lastdetail = DND.DROP_MOVE;
- return;
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- Node attribute = attributes.item(i);
- if (attribute instanceof AttrImpl) {
- AttrImpl jspAttr = (AttrImpl) attribute;
- ITextRegion valueRegion = jspAttr.getValueRegion();
- if (valueRegion == null) {
- event.detail = lastdetail = DND.DROP_NONE;
- return;
- }
- int startPos = jspElement.getStartOffset()
- + valueRegion.getStart();
- int endPos = jspElement.getStartOffset()
- + valueRegion.getTextEnd();
- if (pos > startPos && pos < endPos) {
- dropContext.setOverAttributeValue(true);
- dropContext.setAttributeName(jspAttr.getNodeName());
- event.detail = lastdetail = DND.DROP_MOVE;
- return;
- }
- }
- }
- event.detail = lastdetail = DND.DROP_NONE;
- } else if (region instanceof Text
- && isInsideResponseRedirect((Text) region, pos
- - region.getStartOffset())) {
- dropContext.setOverAttributeValue(true);
- event.detail = lastdetail = DND.DROP_MOVE;
- } else if (region instanceof Text) {
- event.detail = lastdetail = DND.DROP_MOVE;
- } else if (region instanceof DocumentType) {
- event.detail = lastdetail = DND.DROP_NONE;
- } else if (region == null) {
- //new place
- event.detail = lastdetail = DND.DROP_MOVE;
- }
- }
-
- public void drop(DropTargetEvent event) {
- int offset = getPosition(event.x, event.y);
- selectAndReveal(offset, 0);
- dropContext.runDropCommand(JSPTextEditor.this, event);
- }
-
- public void dropAccept(DropTargetEvent event) {
- }
-
- }
-
- private int getPosition(int x, int y) {
- try {
- ISourceViewer v = getSourceViewer();
- StyledText t = v.getTextWidget();
- Point pp = t.toControl(x, y);
- x = pp.x;
- y = pp.y;
- int lineIndex = (t.getTopPixel() + y) / t.getLineHeight();
- if (lineIndex >= t.getLineCount()) {
- return t.getCharCount();
- } else {
- int c = 0;
- try {
- c = t.getOffsetAtLocation(new Point(x, y));
- if (c < 0)
- c = 0;
- } catch (Exception ex) {
- c = t.getOffsetAtLine(lineIndex + 1)
- - (t.getLineDelimiter() == null ? 0 : t
- .getLineDelimiter().length());
- }
- return c;
- }
- } catch (Exception e) {
- return 0;
- }
- }
-
- public String[] getConfigurationPoints() {
- String contentTypeIdentifierID = null;
- if (getModel() != null)
- contentTypeIdentifierID = getModel().getContentTypeIdentifier();
- return ConfigurationPointCalculator.getConfigurationPoints(this,
- contentTypeIdentifierID, ConfigurationPointCalculator.SOURCE,
- StructuredTextEditor.class);
- }
-
- public void formatTextRegion(IDocument document, IRegion region) {
- SourceViewerConfiguration conf = getSourceViewerConfiguration();
-
- if (conf instanceof StructuredTextViewerConfiguration) {
- StructuredTextViewerConfiguration stvc = (StructuredTextViewerConfiguration) conf;
- IContentFormatter f = stvc.getContentFormatter(getSourceViewer());
- f.format(document, region);
- }
- }
-
- Point storedSelection = new Point(0, 0);
-
- protected void handleCursorPositionChanged() {
- super.handleCursorPositionChanged();
- ISelection selection = getSelectionProvider().getSelection();
- Point p = getTextViewer().getTextWidget().getSelection();
- if (storedSelection == null || !storedSelection.equals(p)) {
- storedSelection = p;
- if (selection instanceof ITextSelection) {
- ITextSelection ts = (ITextSelection) selection;
- if (ts.getLength() == 0) {
- if (vpeController != null) {
- vpeController
- .selectionChanged(new SelectionChangedEvent(
- getSelectionProvider(),
- getSelectionProvider().getSelection()));
- }
- }
- }
- }
- }
-
- static int firingSelectionFailedCount = 0;
-
- private class OutlinePageListener implements IDoubleClickListener,
- ISelectionChangedListener {
- public void doubleClick(DoubleClickEvent event) {
- if (event.getSelection().isEmpty())
- return;
-
- int start = -1;
- int length = 0;
- if (event.getSelection() instanceof IStructuredSelection) {
- ISelection currentSelection = getSelectionProvider()
- .getSelection();
- if (currentSelection instanceof IStructuredSelection) {
- Object current = ((IStructuredSelection) currentSelection)
- .toArray();
- Object newSelection = ((IStructuredSelection) event
- .getSelection()).toArray();
- if (!current.equals(newSelection)) {
- IStructuredSelection selection = (IStructuredSelection) event
- .getSelection();
- Object o = selection.getFirstElement();
- if (o instanceof IndexedRegion) {
- start = ((IndexedRegion) o).getStartOffset();
- length = ((IndexedRegion) o).getEndOffset() - start;
- } else if (o instanceof ITextRegion) {
- start = ((ITextRegion) o).getStart();
- length = ((ITextRegion) o).getEnd() - start;
- } else if (o instanceof IRegion) {
- start = ((ITextRegion) o).getStart();
- length = ((ITextRegion) o).getLength();
- }
- }
- }
- } else if (event.getSelection() instanceof ITextSelection) {
- start = ((ITextSelection) event.getSelection()).getOffset();
- length = ((ITextSelection) event.getSelection()).getLength();
- }
- if (start > -1) {
- getSourceViewer().setRangeIndication(start, length, false);
- selectAndReveal(start, length);
- }
- }
-
- public void selectionChanged(SelectionChangedEvent event) {
- if (event.getSelection().isEmpty() || isFiringSelection())
- return;
-
- boolean ignoreSelection = false;
- if (getSourceViewer() != null
- && getSourceViewer() instanceof IIgnoreSelection) {
- IIgnoreSelection is = ((IIgnoreSelection) getSourceViewer());
- ignoreSelection = is.doesIgnore();
- }
- if (getSourceViewer() != null
- && getSourceViewer().getTextWidget() != null
- && !getSourceViewer().getTextWidget().isDisposed()
- && !getSourceViewer().getTextWidget().isFocusControl()
- && !ignoreSelection) {
- int start = -1;
- int length = 0;
- if (event.getSelection() instanceof IStructuredSelection) {
- ISelection current = getSelectionProvider().getSelection();
- if (current instanceof IStructuredSelection) {
- Object[] currentSelection = ((IStructuredSelection) current)
- .toArray();
- Object[] newSelection = ((IStructuredSelection) event
- .getSelection()).toArray();
- if (!Arrays.equals(currentSelection, newSelection)) {
- if (newSelection.length > 0) {
- /*
- * No ordering is guaranteed for multiple
- * selection
- */
- Object o = newSelection[0];
- if (o instanceof IndexedRegion) {
- start = ((IndexedRegion) o)
- .getStartOffset();
- int end = ((IndexedRegion) o)
- .getEndOffset();
- if (newSelection.length > 1) {
- for (int i = 1; i < newSelection.length; i++) {
- start = Math
- .min(
- start,
- ((IndexedRegion) newSelection[i])
- .getStartOffset());
- end = Math
- .max(
- end,
- ((IndexedRegion) newSelection[i])
- .getEndOffset());
- }
- length = end - start;
- }
- } else if (o instanceof ITextRegion) {
- start = ((ITextRegion) o).getStart();
- int end = ((ITextRegion) o).getEnd();
- if (newSelection.length > 1) {
- for (int i = 1; i < newSelection.length; i++) {
- start = Math
- .min(
- start,
- ((ITextRegion) newSelection[i])
- .getStart());
- end = Math
- .max(
- end,
- ((ITextRegion) newSelection[i])
- .getEnd());
- }
- length = end - start;
- }
- } else if (o instanceof IRegion) {
- start = ((IRegion) o).getOffset();
- int end = start + ((IRegion) o).getLength();
- if (newSelection.length > 1) {
- for (int i = 1; i < newSelection.length; i++) {
- start = Math.min(start,
- ((IRegion) newSelection[i])
- .getOffset());
- end = Math
- .max(
- end,
- ((IRegion) newSelection[i])
- .getOffset()
- + ((IRegion) newSelection[i])
- .getLength());
- }
- length = end - start;
- }
- }
- }
- }
- }
- } else if (event.getSelection() instanceof ITextSelection) {
- start = ((ITextSelection) event.getSelection()).getOffset();
- }
- if (start > -1) {
- updateRangeIndication0(event.getSelection());
- selectAndReveal(start, length);
- }
- }
- }
-
- Method m = null;
-
- private boolean isFiringSelection() {
- if (getSelectionProvider() == null)
- return false;
- if (firingSelectionFailedCount > 0)
- return false;
- try {
- if (m == null) {
- Class c = getSelectionProvider().getClass();
- m = c.getDeclaredMethod("isFiringSelection", new Class[0]);
- m.setAccessible(true);
- }
- Boolean b = (Boolean) m.invoke(getSelectionProvider(),
- new Object[0]);
- return b.booleanValue();
- } catch (Exception e) {
- firingSelectionFailedCount++;
- JspEditorPlugin.getPluginLog().logError(e);
- }
- return false;
- }
- }
-
- private void updateRangeIndication0(ISelection selection) {
- if (selection instanceof IStructuredSelection
- && !((IStructuredSelection) selection).isEmpty()) {
- Object[] objects = ((IStructuredSelection) selection).toArray();
- if (objects.length > 0) {
- int start = ((IndexedRegion) objects[0]).getStartOffset();
- int end = ((IndexedRegion) objects[objects.length - 1])
- .getEndOffset();
- getSourceViewer().setRangeIndication(start, end - start, false);
- } else {
- getSourceViewer().removeRangeIndication();
- }
- } else {
- if (selection instanceof ITextSelection) {
- getSourceViewer().setRangeIndication(
- ((ITextSelection) selection).getOffset(),
- ((ITextSelection) selection).getLength(), false);
- } else {
- getSourceViewer().removeRangeIndication();
- }
- }
- }
-
- protected IExtendedAction createExtendedAction(String actionID) {
- if (StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT
- .equals(actionID)
- || ITextEditorActionConstants.UNDO.equals(actionID)
- || ITextEditorActionConstants.REDO.equals(actionID)) {
- return new ExtendedFormatAction(this, actionID);
- }
- return null;
- }
-
- protected void initializeEditor() {
- super.initializeEditor();
- getPreferenceStore();
- }
-
- public void dispose() {
+/*******************************************************************************
+ * 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.jst.jsp.jspeditor;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextListener;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextEvent;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IOverviewRuler;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP;
+import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSource;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.DropTargetListener;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.HTMLTransfer;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.editors.text.ILocationProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.PropertySheetPage;
+import org.eclipse.ui.views.properties.PropertySheetSorter;
+import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
+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.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
+import org.eclipse.wst.sse.ui.internal.IModelProvider;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
+import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
+import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
+import org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage;
+import org.eclipse.wst.sse.ui.internal.provisional.extensions.ConfigurationPointCalculator;
+import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration;
+import org.eclipse.wst.xml.core.internal.document.AttrImpl;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
+import org.jboss.tools.common.meta.action.XActionInvoker;
+import org.jboss.tools.common.model.XModelBuffer;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelTransferBuffer;
+import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
+import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
+import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
+import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.DropData;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
+import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
+import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
+import org.jboss.tools.common.model.ui.texteditors.TextMerge;
+import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDrop;
+import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDropProvider;
+import org.jboss.tools.common.model.ui.views.palette.IIgnoreSelection;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
+import org.jboss.tools.common.text.xml.IOccurrencePreferenceProvider;
+import org.jboss.tools.common.text.xml.XmlEditorPlugin;
+import org.jboss.tools.common.text.xml.ui.FreeCaretStyledText;
+import org.jboss.tools.jst.jsp.HTMLTextViewerConfiguration;
+import org.jboss.tools.jst.jsp.JSPTextViewerConfiguration;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
+import org.jboss.tools.jst.jsp.editor.ITextFormatter;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.jsp.editor.IVisualController;
+import org.jboss.tools.jst.jsp.outline.JSPContentOutlineConfiguration;
+import org.jboss.tools.jst.jsp.outline.JSPPropertySheetConfiguration;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
+import org.jboss.tools.jst.jsp.support.kb.WTPTextJspKbConnector;
+import org.jboss.tools.jst.jsp.text.xpl.IStructuredTextOccurrenceStructureProvider;
+import org.jboss.tools.jst.jsp.text.xpl.StructuredTextOccurrenceStructureProviderRegistry;
+import org.jboss.tools.jst.jsp.ui.action.ExtendedFormatAction;
+import org.jboss.tools.jst.jsp.ui.action.IExtendedAction;
+import org.jboss.tools.jst.web.tld.VpeTaglibManager;
+import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * @author Jeremy
+ *
+ */
+public class JSPTextEditor extends StructuredTextEditor implements
+ ITextListener, IJSPTextEditor, ITextFormatter,
+ IOccurrencePreferenceProvider {
+ private IStructuredTextOccurrenceStructureProvider fOccurrenceModelUpdater;
+
+ TextEditorDrop dnd = new TextEditorDrop();
+
+ JSPMultiPageEditor parentEditor;
+
+ long timeStamp = -1;
+
+ long savedTimeStamp = -1;
+
+ IVisualController vpeController;
+ //Added By Max Areshkau
+ //Fix for JBIDE-788
+ protected SourceEditorPageContext pageContext = null;
+
+ public JSPTextEditor(JSPMultiPageEditor parentEditor) {
+ JspEditorPlugin.getDefault().initDefaultPluginPreferences();
+ dnd.setTextEditorDropProvider(new TextEditorDropProviderImpl());
+ this.parentEditor = parentEditor;
+ super
+ .setSourceViewerConfiguration(new JSPTextViewerConfiguration());
+ }
+
+ protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
+ if (config instanceof StructuredTextViewerConfigurationJSP) {
+ if (!(config instanceof JSPTextViewerConfiguration)) {
+ config = new JSPTextViewerConfiguration();
+ }
+ } else if (config instanceof StructuredTextViewerConfigurationHTML) {
+ if (!(config instanceof HTMLTextViewerConfiguration)) {
+ config = new HTMLTextViewerConfiguration();
+ }
+ } else {
+ config = new JSPTextViewerConfiguration();
+ }
+ super.setSourceViewerConfiguration(config);
+ }
+
+ /** This is *only* for allowing unit tests to access the source configuration. */
+ public SourceViewerConfiguration getSourceViewerConfigurationForTest () {
+ return getSourceViewerConfiguration();
+ }
+ //Added By Max Areshkau
+ //Fix for JBIDE-788
+ public IVisualContext getPageContext() {
+
+ if (pageContext==null) {
+ pageContext = new SourceEditorPageContext();
+ }
+ IDocument document = getTextViewer().getDocument();
+ int offset = this.getTextViewer().getTextWidget().getCaretOffset();
+ IndexedRegion treeNode = ContentAssistUtils.getNodeAt(this.getTextViewer(), offset);
+ Node node = (Node) treeNode;
+ pageContext.setReferenceNode(node);
+ pageContext.setDocument(document);
+
+ return pageContext;
+ }
+
+ protected void initializeDrop(ITextViewer textViewer) {
+
+ Composite c = textViewer.getTextWidget();
+ Label l = new Label(c, SWT.NONE);
+ l.dispose();
+ }
+
+ private ConfigurableContentOutlinePage fOutlinePage = null;
+
+ private OutlinePageListener fOutlinePageListener = null;
+
+ private IPropertySheetPage fPropertySheetPage;
+
+ public Object getAdapter(Class adapter) {
+ if (ISourceViewer.class.equals(adapter)) {
+ return JSPTextEditor.this.getSourceViewer();
+ } else if (IContentOutlinePage.class.equals(adapter)) {
+ if (fOutlinePage == null || fOutlinePage.getControl() == null
+ || fOutlinePage.getControl().isDisposed()) {
+ IStructuredModel internalModel = getModel();
+ ContentOutlineConfiguration cfg = new JSPContentOutlineConfiguration(
+ this);
+ if (cfg != null) {
+ ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage();
+ outlinePage.setConfiguration(cfg);
+ if (internalModel != null) {
+ outlinePage.setInputContentTypeIdentifier(internalModel
+ .getContentTypeIdentifier());
+ outlinePage.setInput(internalModel);
+ }
+
+ if (fOutlinePageListener == null) {
+ fOutlinePageListener = new OutlinePageListener();
+ }
+
+ outlinePage
+ .addSelectionChangedListener(fOutlinePageListener);
+ outlinePage.addDoubleClickListener(fOutlinePageListener);
+
+ fOutlinePage = outlinePage;
+ }
+ }
+ return fOutlinePage;
+ } else if (IPropertySheetPage.class == adapter) {
+ if (fPropertySheetPage == null
+ || fPropertySheetPage.getControl() == null
+ || fPropertySheetPage.getControl().isDisposed()) {
+ JSPPropertySheetConfiguration cfg = new JSPPropertySheetConfiguration();
+ if (cfg != null) {
+ ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage();
+ propertySheetPage.setConfiguration(cfg);
+ fPropertySheetPage = propertySheetPage;
+ setSorter(cfg.getSorter(), propertySheetPage);
+ }
+ }
+ return fPropertySheetPage;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ private void setSorter(PropertySheetSorter sorter,
+ ConfigurablePropertySheetPage sheet) {
+ try {
+ Method method = PropertySheetPage.class.getDeclaredMethod(
+ "setSorter", new Class[] { PropertySheetSorter.class });
+ method.setAccessible(true);
+ method.invoke(sheet, new Object[] { sorter });
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public String getEditorId() {
+ return JSPUIPlugin.ID;
+ }
+
+ public IStructuredTextOccurrenceStructureProvider getOccurrencePreferenceProvider() {
+ return fOccurrenceModelUpdater;
+ }
+
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+
+ StructuredTextOccurrenceStructureProviderRegistry registry = XmlEditorPlugin
+ .getDefault().getOccurrenceStructureProviderRegistry(
+ JspEditorPlugin.PLUGIN_ID);
+ fOccurrenceModelUpdater = registry
+ .getCurrentOccurrenceProvider(JspEditorPlugin.PLUGIN_ID);
+
+ if (fOccurrenceModelUpdater != null)
+ fOccurrenceModelUpdater.install(this, getTextViewer());
+
+ installActivePropmtSupport();
+
+ createDrop();
+ setModified(false);
+ getSourceViewer().removeTextListener(this);
+ getSourceViewer().addTextListener(this);
+
+ Object dtid = getSourceViewer().getTextWidget().getData("DropTarget");
+ if (dtid != null) {
+ if (dtid instanceof DropTarget) {
+ DropTarget dropTarget = (DropTarget) dtid;
+ dropTarget.addDropListener(new DropTargetAdapter() {
+ private FreeCaretStyledText getFreeCaretControl(
+ Object sourceOrTarget) {
+ if (sourceOrTarget == null)
+ return null;
+
+ Object control = null;
+
+ if (sourceOrTarget instanceof DropTarget) {
+ control = ((DropTarget) sourceOrTarget)
+ .getControl();
+ } else if (sourceOrTarget instanceof DragSource) {
+ control = ((DragSource) sourceOrTarget)
+ .getControl();
+ } else
+ return null;
+
+ if (control instanceof FreeCaretStyledText)
+ return (FreeCaretStyledText) control;
+ return null;
+ }
+
+ private int getPosition(StyledText t, int x, int y) {
+ try {
+ Point pp = t.toControl(x, y);
+ x = pp.x;
+ y = pp.y;
+ int lineIndex = (t.getTopPixel() + y)
+ / t.getLineHeight();
+ if (lineIndex >= t.getLineCount()) {
+ return t.getCharCount();
+ } else {
+ int c = 0;
+ try {
+ c = t.getOffsetAtLocation(new Point(x, y));
+ if (c < 0)
+ c = 0;
+ } catch (Exception ex) {
+ c = t.getOffsetAtLine(lineIndex + 1)
+ - (t.getLineDelimiter() == null ? 0
+ : t.getLineDelimiter()
+ .length());
+ }
+ return c;
+ }
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public void dragEnter(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(true);
+ }
+
+ public void dragLeave(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(false);
+ }
+
+ public void dragOperationChanged(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(false);
+ }
+
+ public void dragOver(DropTargetEvent event) {
+ FreeCaretStyledText fcst = getFreeCaretControl(event.widget);
+ int pos = getPosition(fcst, event.x, event.y);
+ Point p = fcst.getLocationAtOffset(pos);
+ fcst.myRedraw(p.x, p.y);
+ }
+
+ public void drop(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(false);
+ }
+ });
+ }
+ }
+ }
+
+ protected ISourceViewer createSourceViewer(Composite parent,
+ IVerticalRuler ruler, int styles) {
+ ISourceViewer sv = super.createSourceViewer(parent, ruler, styles);
+ sv.getTextWidget().addFocusListener(new TextFocusListener());
+ return sv;
+ }
+
+ protected StructuredTextViewer createStructedTextViewer(Composite parent,
+ IVerticalRuler verticalRuler, int styles) {
+ return new JSPStructuredTextViewer(parent, verticalRuler,
+ getOverviewRuler(), isOverviewRulerVisible(), styles,
+ parentEditor, this);
+ }
+
+ class TextFocusListener extends FocusAdapter {
+ public void focusLost(FocusEvent e) {
+ if (JSPTextEditor.super.isDirty()) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException exc) {
+ JspEditorPlugin.getPluginLog().logError(exc);
+ }
+ save();
+ }
+ });
+ }
+ }
+ }
+
+ public void save() {
+ if (!lock && isModified()) {
+ lock = true;
+ try {
+ FileAnyImpl f = (FileAnyImpl) getModelObject();
+ if (f != null)
+ f.edit(getSourceViewer().getDocument().get());
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } finally {
+ setModified(false);
+ lock = false;
+ }
+ }
+ }
+
+ boolean modified = false;
+
+ public void setModified(boolean set) {
+ if (this.modified != set) {
+ this.modified = set;
+ if (set) {
+ XModelObject o = getModelObject();
+ if (o != null)
+ o.setModified(true);
+ }
+ super.firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ }
+
+ public void updateModification() {
+ //added by Max Areshkau
+ //Fix for JBIDE-788
+ getPageContext().refreshBundleValues();
+
+ XModelObject object = getModelObject();
+ if (object != null && !object.isModified() && isModified()) {
+ setModified(false);
+ } else {
+ firePropertyChange(ITextEditor.PROP_DIRTY);
+ }
+ }
+
+ public boolean isModified() {
+ return modified;
+ }
+
+ protected void doSetInput(IEditorInput input) throws CoreException {
+ super.doSetInput(XModelObjectEditorInput.checkInput(input));
+ if (getSourceViewer() != null
+ && getSourceViewer().getDocument() != null) {
+ getSourceViewer().removeTextListener(this);
+ getSourceViewer().addTextListener(this);
+ }
+ if (listener != null)
+ listener.dispose();
+ listener = null;
+ XModelObject o = getModelObject();
+ if (o instanceof FileAnyImpl) {
+ listener = new BodyListenerImpl((FileAnyImpl) o);
+ }
+ }
+
+ boolean lock = false;
+
+ public boolean isDirty() {
+ if (getEditorInput() instanceof IModelObjectEditorInput) {
+ XModelObject o = getModelObject();
+ if (o != null && o.isModified())
+ return true;
+ else {
+ return isModified();
+ }
+ } else {
+ return super.isDirty();
+ }
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ XModelObject o = getModelObject();
+ super.doSave(monitor);
+ if (o != null && (monitor == null || !monitor.isCanceled())) {
+ if (o != null)
+ save();
+ if (getEditorInput() instanceof ILocationProvider) {
+ XModelObject p = o.getParent();
+ if (p instanceof FolderImpl) {
+ ((FolderImpl) p).saveChild(o);
+ }
+ } else {
+ o.setModified(false);
+ XModelObjectLoaderUtil.updateModifiedOnSave(o);
+ }
+ super.firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ }
+
+ public void firePropertyChangeDirty() {
+ super.firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+
+ public XModelObject getModelObject() {
+ if (getEditorInput() instanceof IModelObjectEditorInput) {
+ return ((IModelObjectEditorInput) getEditorInput())
+ .getXModelObject();
+ }
+ return null;
+ }
+
+ class TextEditorDropProviderImpl implements TextEditorDropProvider {
+
+ public ISourceViewer getSourceViewer() {
+ return JSPTextEditor.this.getSourceViewer();
+ }
+
+ public XModelObject getModelObject() {
+ return JSPTextEditor.this.getModelObject();
+ }
+
+ public void insert(Properties p) {
+ PaletteInsertHelper.insertIntoEditor(getSourceViewer(), p);
+ }
+
+ }
+
+ public void textChanged(TextEvent event) {
+ if (event.getDocumentEvent() != null) {
+ setModified(true);
+ }
+ }
+
+ public void doRevertToSaved() {
+ save();
+ XModelObject o = getModelObject();
+ if (o == null) {
+ super.doRevertToSaved();
+ return;
+ }
+ Properties p = new Properties();
+ XActionInvoker.invoke("DiscardActions.Discard", o, p);
+ if (!"true".equals(p.getProperty("done")))
+ return;
+ super.doRevertToSaved();
+ if (o.isModified())
+ o.setModified(false);
+ modified = false;
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ updatePartControl(getEditorInput());
+ }
+
+ public IAnnotationModel getAnnotationModel() {
+ return getSourceViewer().getAnnotationModel();
+ }
+
+ private WTPTextJspKbConnector wtpTextJspKbConnector;
+
+ private void installActivePropmtSupport() {
+ try {
+ IDocument document = getTextViewer().getDocument();
+ IStructuredModel model = null;
+ if (getDocumentProvider() instanceof IModelProvider) {
+ model = ((IModelProvider) getDocumentProvider())
+ .getModel(getEditorInput());
+ } else {
+ if (document instanceof IStructuredDocument) {
+ model = getModel();
+ }
+ }
+ if (wtpTextJspKbConnector == null
+ && model != null
+ && (getContentType().toLowerCase().indexOf("jsp") != -1 || getContentType()
+ .toLowerCase().indexOf("html") != -1)) {
+ wtpTextJspKbConnector = new WTPTextJspKbConnector(
+ getEditorInput(), document, model);
+ wtpTextJspKbConnector.setTaglibManagerProvider(parentEditor);
+ }
+ } catch (Exception x) {
+ JspEditorPlugin.getPluginLog().logError("Error while installing active prpmpting support", x);
+ }
+ }
+
+ private String getContentType() {
+ String type = null;
+ try {
+ type = getModel().getContentTypeIdentifier();
+ } finally {
+ if (type == null)
+ type = "";
+ }
+ return type;
+ }
+
+ public WTPTextJspKbConnector getWTPTextJspKbConnector() {
+ return wtpTextJspKbConnector;
+ }
+
+ public static class JSPStructuredTextViewer extends StructuredTextViewer
+ implements VpeTaglibManagerProvider, IIgnoreSelection {
+
+ boolean insertFromPallete = false;
+
+ private VpeTaglibManagerProvider provider;
+
+ private JSPTextEditor editor;
+
+ private boolean ignore = false;
+
+ public JSPStructuredTextViewer(Composite parent,
+ IVerticalRuler verticalRuler, int styles) {
+ super(parent, verticalRuler, null, false, styles);
+ }
+
+ public JSPStructuredTextViewer(Composite parent,
+ IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
+ boolean showAnnotationsOverview, int styles,
+ VpeTaglibManagerProvider provider, JSPTextEditor editor) {
+ super(parent, verticalRuler, overviewRuler,
+ showAnnotationsOverview, styles);
+ this.provider = provider;
+ this.editor = editor;
+ }
+
+ protected StyledText createTextWidget(Composite parent, int styles) {
+ return new FreeCaretStyledText(parent, styles);
+ }
+
+ public VpeTaglibManager getTaglibManager() {
+ //added by Max Areshkau
+ //Fix for JBIDE-788
+ if (getEditor() != null) {
+ if(getEditor().getPageContext() instanceof VpeTaglibManager)
+
+
+ return (VpeTaglibManager)getEditor().getPageContext();
+ }
+ return null;
+ }
+
+ public boolean doesIgnore() {
+ return ignore;
+ }
+
+ public void setIgnore(boolean ignore) {
+ this.ignore = ignore;
+ }
+
+ public void doOperation(int operation) {
+ if (operation == UNDO || operation == REDO
+ || operation == FORMAT_DOCUMENT
+ || operation == FORMAT_ACTIVE_ELEMENTS) {
+ if (editor.getVPEController() != null) {
+ editor.getVPEController().preLongOperation();
+ }
+ }
+
+ super.doOperation(operation);
+
+ if (operation == UNDO || operation == REDO
+ || operation == FORMAT_DOCUMENT
+ || operation == FORMAT_ACTIVE_ELEMENTS) {
+ if (editor.getVPEController() != null) {
+ editor.getVPEController().postLongOperation();
+ }
+ }
+ }
+
+ protected void handleDispose() {
+ if (editor != null && editor.getSourceViewer() != null && editor.getSourceViewer().getTextWidget() != null && editor.getVPEController() != null) {
+ StyledText widget = editor.getSourceViewer().getTextWidget();
+ widget.removeSelectionListener(editor.getVPEController());
+ }
+ super.handleDispose();
+ }
+
+
+ /**
+ * @return the editor
+ */
+ //Added By Max Areshkau
+ //Fix for JBIDE-788
+ public JSPTextEditor getEditor() {
+ return editor;
+ }
+
+ /**
+ * @param editor the editor to set
+ */
+ //Added By Max Areshkau
+ //Fix for JBIDE-788
+ public void setEditor(JSPTextEditor editor) {
+ this.editor = editor;
+ }
+
+ }
+ public JSPMultiPageEditor getParentEditor() {
+ return parentEditor;
+ }
+
+ public void setVPEController(IVisualController c) {
+ vpeController = c;
+ }
+
+ public IVisualController getVPEController() {
+ return vpeController;
+ }
+
+ public void runDropCommand(final String flavor, final String data) {
+ XModelBuffer b = XModelTransferBuffer.getInstance().getBuffer();
+ final XModelObject o = b == null ? null : b.source();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if(o != null && !XModelTransferBuffer.getInstance().isEnabled()) {
+ XModelTransferBuffer.getInstance().enable();
+ XModelTransferBuffer.getInstance().getBuffer().addSource(o);
+ }
+ try {
+ DropData dropData = new DropData(flavor,
+ data,
+ getEditorInput(), getSourceViewer(),
+ getSelectionProvider());
+ dropData.setAttributeName(dropContext.getAttributeName());
+ IDropCommand dropCommand = DropCommandFactory.getInstance().getDropCommand(flavor, JSPTagProposalFactory.getInstance());
+
+ boolean promptAttributes = "yes".equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
+ dropCommand.getDefaultModel().setPromptForTagAttributesRequired(promptAttributes);
+ dropCommand.execute(dropData);
+ } finally {
+ XModelTransferBuffer.getInstance().disable();
+ }
+ }
+ });
+ }
+
+ private void createDrop() {
+ DropTarget target = new DropTarget(getSourceViewer().getTextWidget(),
+ DND.DROP_MOVE | DND.DROP_COPY);
+ Transfer[] types = new Transfer[] { ModelTransfer.getInstance(),
+ HTMLTransfer.getInstance(), TextTransfer.getInstance(),
+ FileTransfer.getInstance() };
+ target.setTransfer(types);
+ target.addDropListener(new DTL());
+ }
+
+ DropContext dropContext = new DropContext();
+
+ class DTL implements DropTargetListener {
+ int lastpos = -1;
+
+ int lastdetail = -1;
+
+ public void dragEnter(DropTargetEvent event) {
+ lastpos = -1;
+ }
+
+ public void dragLeave(DropTargetEvent event) {
+ lastpos = -1;
+ }
+
+ public void dragOperationChanged(DropTargetEvent event) {
+ }
+
+ public void dragOver(DropTargetEvent event) {
+ if (!isEditable()
+ || (getModelObject() != null && !getModelObject()
+ .isObjectEditable())) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ dropContext.setDropTargetEvent(event);
+ if (dropContext.getFlavor() == null) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ // Drop from VPE to Source is forbidden
+ if (dropContext.getFlavor().equals("text/html")) {
+ if (InnerDragBuffer.object != null) {
+ event.detail = DND.DROP_NONE;
+ }
+ return;
+ }
+ int pos = getPosition(event.x, event.y);
+ if (lastpos == pos && pos >= 0) {
+ pos = lastpos;
+ event.detail = lastdetail;
+ return;
+ }
+ lastpos = pos;
+ dropContext.clean();
+ getSourceViewer().getDocument();
+ IndexedRegion region = getModel().getIndexedRegion(pos);
+ if (region instanceof ElementImpl) {
+ ElementImpl jspElement = (ElementImpl) region;
+ NamedNodeMap attributes = jspElement.getAttributes();
+ if (pos == jspElement.getStartOffset()
+ || pos == jspElement.getEndStartOffset()) {
+ event.detail = lastdetail = DND.DROP_MOVE;
+ return;
+ }
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Node attribute = attributes.item(i);
+ if (attribute instanceof AttrImpl) {
+ AttrImpl jspAttr = (AttrImpl) attribute;
+ ITextRegion valueRegion = jspAttr.getValueRegion();
+ if (valueRegion == null) {
+ event.detail = lastdetail = DND.DROP_NONE;
+ return;
+ }
+ int startPos = jspElement.getStartOffset()
+ + valueRegion.getStart();
+ int endPos = jspElement.getStartOffset()
+ + valueRegion.getTextEnd();
+ if (pos > startPos && pos < endPos) {
+ dropContext.setOverAttributeValue(true);
+ dropContext.setAttributeName(jspAttr.getNodeName());
+ event.detail = lastdetail = DND.DROP_MOVE;
+ return;
+ }
+ }
+ }
+ event.detail = lastdetail = DND.DROP_NONE;
+ } else if (region instanceof Text
+ && isInsideResponseRedirect((Text) region, pos
+ - region.getStartOffset())) {
+ dropContext.setOverAttributeValue(true);
+ event.detail = lastdetail = DND.DROP_MOVE;
+ } else if (region instanceof Text) {
+ event.detail = lastdetail = DND.DROP_MOVE;
+ } else if (region instanceof DocumentType) {
+ event.detail = lastdetail = DND.DROP_NONE;
+ } else if (region == null) {
+ //new place
+ event.detail = lastdetail = DND.DROP_MOVE;
+ }
+ }
+
+ public void drop(DropTargetEvent event) {
+ int offset = getPosition(event.x, event.y);
+ selectAndReveal(offset, 0);
+ dropContext.runDropCommand(JSPTextEditor.this, event);
+ }
+
+ public void dropAccept(DropTargetEvent event) {
+ }
+
+ }
+
+ private int getPosition(int x, int y) {
+ try {
+ ISourceViewer v = getSourceViewer();
+ StyledText t = v.getTextWidget();
+ Point pp = t.toControl(x, y);
+ x = pp.x;
+ y = pp.y;
+ int lineIndex = (t.getTopPixel() + y) / t.getLineHeight();
+ if (lineIndex >= t.getLineCount()) {
+ return t.getCharCount();
+ } else {
+ int c = 0;
+ try {
+ c = t.getOffsetAtLocation(new Point(x, y));
+ if (c < 0)
+ c = 0;
+ } catch (Exception ex) {
+ c = t.getOffsetAtLine(lineIndex + 1)
+ - (t.getLineDelimiter() == null ? 0 : t
+ .getLineDelimiter().length());
+ }
+ return c;
+ }
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public String[] getConfigurationPoints() {
+ String contentTypeIdentifierID = null;
+ if (getModel() != null)
+ contentTypeIdentifierID = getModel().getContentTypeIdentifier();
+ return ConfigurationPointCalculator.getConfigurationPoints(this,
+ contentTypeIdentifierID, ConfigurationPointCalculator.SOURCE,
+ StructuredTextEditor.class);
+ }
+
+ public void formatTextRegion(IDocument document, IRegion region) {
+ SourceViewerConfiguration conf = getSourceViewerConfiguration();
+
+ if (conf instanceof StructuredTextViewerConfiguration) {
+ StructuredTextViewerConfiguration stvc = (StructuredTextViewerConfiguration) conf;
+ IContentFormatter f = stvc.getContentFormatter(getSourceViewer());
+ f.format(document, region);
+ }
+ }
+
+ Point storedSelection = new Point(0, 0);
+
+ protected void handleCursorPositionChanged() {
+ super.handleCursorPositionChanged();
+ ISelection selection = getSelectionProvider().getSelection();
+ Point p = getTextViewer().getTextWidget().getSelection();
+ if (storedSelection == null || !storedSelection.equals(p)) {
+ storedSelection = p;
+ if (selection instanceof ITextSelection) {
+ ITextSelection ts = (ITextSelection) selection;
+ if (ts.getLength() == 0) {
+ if (vpeController != null) {
+ vpeController
+ .selectionChanged(new SelectionChangedEvent(
+ getSelectionProvider(),
+ getSelectionProvider().getSelection()));
+ }
+ }
+ }
+ }
+ }
+
+ static int firingSelectionFailedCount = 0;
+
+ private class OutlinePageListener implements IDoubleClickListener,
+ ISelectionChangedListener {
+ public void doubleClick(DoubleClickEvent event) {
+ if (event.getSelection().isEmpty())
+ return;
+
+ int start = -1;
+ int length = 0;
+ if (event.getSelection() instanceof IStructuredSelection) {
+ ISelection currentSelection = getSelectionProvider()
+ .getSelection();
+ if (currentSelection instanceof IStructuredSelection) {
+ Object current = ((IStructuredSelection) currentSelection)
+ .toArray();
+ Object newSelection = ((IStructuredSelection) event
+ .getSelection()).toArray();
+ if (!current.equals(newSelection)) {
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+ Object o = selection.getFirstElement();
+ if (o instanceof IndexedRegion) {
+ start = ((IndexedRegion) o).getStartOffset();
+ length = ((IndexedRegion) o).getEndOffset() - start;
+ } else if (o instanceof ITextRegion) {
+ start = ((ITextRegion) o).getStart();
+ length = ((ITextRegion) o).getEnd() - start;
+ } else if (o instanceof IRegion) {
+ start = ((ITextRegion) o).getStart();
+ length = ((ITextRegion) o).getLength();
+ }
+ }
+ }
+ } else if (event.getSelection() instanceof ITextSelection) {
+ start = ((ITextSelection) event.getSelection()).getOffset();
+ length = ((ITextSelection) event.getSelection()).getLength();
+ }
+ if (start > -1) {
+ getSourceViewer().setRangeIndication(start, length, false);
+ selectAndReveal(start, length);
+ }
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection().isEmpty() || isFiringSelection())
+ return;
+
+ boolean ignoreSelection = false;
+ if (getSourceViewer() != null
+ && getSourceViewer() instanceof IIgnoreSelection) {
+ IIgnoreSelection is = ((IIgnoreSelection) getSourceViewer());
+ ignoreSelection = is.doesIgnore();
+ }
+ if (getSourceViewer() != null
+ && getSourceViewer().getTextWidget() != null
+ && !getSourceViewer().getTextWidget().isDisposed()
+ && !getSourceViewer().getTextWidget().isFocusControl()
+ && !ignoreSelection) {
+ int start = -1;
+ int length = 0;
+ if (event.getSelection() instanceof IStructuredSelection) {
+ ISelection current = getSelectionProvider().getSelection();
+ if (current instanceof IStructuredSelection) {
+ Object[] currentSelection = ((IStructuredSelection) current)
+ .toArray();
+ Object[] newSelection = ((IStructuredSelection) event
+ .getSelection()).toArray();
+ if (!Arrays.equals(currentSelection, newSelection)) {
+ if (newSelection.length > 0) {
+ /*
+ * No ordering is guaranteed for multiple
+ * selection
+ */
+ Object o = newSelection[0];
+ if (o instanceof IndexedRegion) {
+ start = ((IndexedRegion) o)
+ .getStartOffset();
+ int end = ((IndexedRegion) o)
+ .getEndOffset();
+ if (newSelection.length > 1) {
+ for (int i = 1; i < newSelection.length; i++) {
+ start = Math
+ .min(
+ start,
+ ((IndexedRegion) newSelection[i])
+ .getStartOffset());
+ end = Math
+ .max(
+ end,
+ ((IndexedRegion) newSelection[i])
+ .getEndOffset());
+ }
+ length = end - start;
+ }
+ } else if (o instanceof ITextRegion) {
+ start = ((ITextRegion) o).getStart();
+ int end = ((ITextRegion) o).getEnd();
+ if (newSelection.length > 1) {
+ for (int i = 1; i < newSelection.length; i++) {
+ start = Math
+ .min(
+ start,
+ ((ITextRegion) newSelection[i])
+ .getStart());
+ end = Math
+ .max(
+ end,
+ ((ITextRegion) newSelection[i])
+ .getEnd());
+ }
+ length = end - start;
+ }
+ } else if (o instanceof IRegion) {
+ start = ((IRegion) o).getOffset();
+ int end = start + ((IRegion) o).getLength();
+ if (newSelection.length > 1) {
+ for (int i = 1; i < newSelection.length; i++) {
+ start = Math.min(start,
+ ((IRegion) newSelection[i])
+ .getOffset());
+ end = Math
+ .max(
+ end,
+ ((IRegion) newSelection[i])
+ .getOffset()
+ + ((IRegion) newSelection[i])
+ .getLength());
+ }
+ length = end - start;
+ }
+ }
+ }
+ }
+ }
+ } else if (event.getSelection() instanceof ITextSelection) {
+ start = ((ITextSelection) event.getSelection()).getOffset();
+ }
+ if (start > -1) {
+ updateRangeIndication0(event.getSelection());
+ selectAndReveal(start, length);
+ }
+ }
+ }
+
+ Method m = null;
+
+ private boolean isFiringSelection() {
+ if (getSelectionProvider() == null)
+ return false;
+ if (firingSelectionFailedCount > 0)
+ return false;
+ try {
+ if (m == null) {
+ Class c = getSelectionProvider().getClass();
+ m = c.getDeclaredMethod("isFiringSelection", new Class[0]);
+ m.setAccessible(true);
+ }
+ Boolean b = (Boolean) m.invoke(getSelectionProvider(),
+ new Object[0]);
+ return b.booleanValue();
+ } catch (Exception e) {
+ firingSelectionFailedCount++;
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ return false;
+ }
+ }
+
+ private void updateRangeIndication0(ISelection selection) {
+ if (selection instanceof IStructuredSelection
+ && !((IStructuredSelection) selection).isEmpty()) {
+ Object[] objects = ((IStructuredSelection) selection).toArray();
+ if (objects.length > 0) {
+ int start = ((IndexedRegion) objects[0]).getStartOffset();
+ int end = ((IndexedRegion) objects[objects.length - 1])
+ .getEndOffset();
+ getSourceViewer().setRangeIndication(start, end - start, false);
+ } else {
+ getSourceViewer().removeRangeIndication();
+ }
+ } else {
+ if (selection instanceof ITextSelection) {
+ getSourceViewer().setRangeIndication(
+ ((ITextSelection) selection).getOffset(),
+ ((ITextSelection) selection).getLength(), false);
+ } else {
+ getSourceViewer().removeRangeIndication();
+ }
+ }
+ }
+
+ protected IExtendedAction createExtendedAction(String actionID) {
+ if (StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT
+ .equals(actionID)
+ || ITextEditorActionConstants.UNDO.equals(actionID)
+ || ITextEditorActionConstants.REDO.equals(actionID)) {
+ return new ExtendedFormatAction(this, actionID);
+ }
+ return null;
+ }
+
+ protected void initializeEditor() {
+ super.initializeEditor();
+ getPreferenceStore();
+ }
+
+ public void dispose() {
// some things in the configuration need to clean
// up after themselves
getSourceViewer().removeTextListener(this);
@@ -1139,69 +1139,75 @@
}
fOutlinePage=null;
fOutlinePageListener=null;
- if (fOccurrenceModelUpdater != null) {
- fOccurrenceModelUpdater.uninstall();
- fOccurrenceModelUpdater = null;
- }
- super.dispose();
+ if (fOccurrenceModelUpdater != null) {
+ fOccurrenceModelUpdater.uninstall();
+ fOccurrenceModelUpdater = null;
+ }
+ if (pageContext != null) {
+ pageContext.dispose();
+ pageContext = null;
+ }
+
if (wtpTextJspKbConnector != null) {
wtpTextJspKbConnector.setTaglibManagerProvider(null);
+ wtpTextJspKbConnector.dispose();
wtpTextJspKbConnector = null;
}
- if (listener != null)
- listener.dispose();
- listener = null;
- }
-
- BodyListenerImpl listener = null;
-
- class BodyListenerImpl implements FileAnyImpl.BodyListener {
- FileAnyImpl file;
-
- BodyListenerImpl(FileAnyImpl file) {
- this.file = file;
- file.addListener(this);
- }
-
- public void bodyChanged(String body) {
- setText(body);
- }
-
- public void dispose() {
- file.removeListener(this);
- }
- }
-
- public void setText(String text) {
- if (getSourceViewer() == null
- || getSourceViewer().getDocument() == null)
- return;
- String txt = getSourceViewer().getDocument().get();
- if (txt != null && txt.length() > 0) {
- if (!TextMerge.replace(getSourceViewer().getDocument(), text)) {
- getSourceViewer().getDocument().set(text);
- }
- } else {
- getSourceViewer().getDocument().set(text);
- }
- }
-
- boolean isInsideResponseRedirect(Text textNode, int off) {
- if (off < 0)
- return false;
- String START = "response.sendRedirect(\"";
- String END = "\")";
- String text = textNode.getNodeValue();
- int i = 0;
- while (i < text.length() && i < off) {
- int i1 = text.indexOf(START, i);
- if (i1 < 0 || i1 + START.length() > off)
- return false;
- int i2 = text.indexOf(END, i1 + START.length());
- if (i2 < 0 || i2 >= off)
- return true;
- i = i2 + END.length();
- }
- return false;
- }
-}
+ super.dispose();
+ if (listener != null)
+ listener.dispose();
+ listener = null;
+ }
+
+ BodyListenerImpl listener = null;
+
+ class BodyListenerImpl implements FileAnyImpl.BodyListener {
+ FileAnyImpl file;
+
+ BodyListenerImpl(FileAnyImpl file) {
+ this.file = file;
+ file.addListener(this);
+ }
+
+ public void bodyChanged(String body) {
+ setText(body);
+ }
+
+ public void dispose() {
+ file.removeListener(this);
+ }
+ }
+
+ public void setText(String text) {
+ if (getSourceViewer() == null
+ || getSourceViewer().getDocument() == null)
+ return;
+ String txt = getSourceViewer().getDocument().get();
+ if (txt != null && txt.length() > 0) {
+ if (!TextMerge.replace(getSourceViewer().getDocument(), text)) {
+ getSourceViewer().getDocument().set(text);
+ }
+ } else {
+ getSourceViewer().getDocument().set(text);
+ }
+ }
+
+ boolean isInsideResponseRedirect(Text textNode, int off) {
+ if (off < 0)
+ return false;
+ String START = "response.sendRedirect(\"";
+ String END = "\")";
+ String text = textNode.getNodeValue();
+ int i = 0;
+ while (i < text.length() && i < off) {
+ int i1 = text.indexOf(START, i);
+ if (i1 < 0 || i1 + START.length() > off)
+ return false;
+ int i2 = text.indexOf(END, i1 + START.length());
+ if (i2 < 0 || i2 >= off)
+ return true;
+ i = i2 + END.length();
+ }
+ return false;
+ }
+}
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPTextJspKbConnector.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPTextJspKbConnector.java 2008-03-18 15:32:57 UTC (rev 6989)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPTextJspKbConnector.java 2008-03-18 15:40:24 UTC (rev 6990)
@@ -1,455 +1,458 @@
-/*******************************************************************************
- * 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.jst.jsp.support.kb;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
-import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
-import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.document.NodeContainer;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.jboss.tools.common.kb.KbConnector;
-import org.jboss.tools.common.kb.KbConnectorFactory;
-import org.jboss.tools.common.kb.KbConnectorType;
-import org.jboss.tools.common.kb.KbException;
-import org.jboss.tools.common.kb.KbResource;
-import org.jboss.tools.common.kb.TagDescriptor;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.web.tld.TaglibData;
-import org.jboss.tools.jst.web.tld.VpeTaglibListener;
-import org.jboss.tools.jst.web.tld.VpeTaglibManager;
-import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * @author Jeremy
- */
-public class WTPTextJspKbConnector implements KbConnector, VpeTaglibListener {
- private KbConnector kbConnector;
- private IDocument fDocument;
- private IEditorInput fEditorInput;
- private VpeTaglibManagerProvider taglibManagerProvider;
-
- protected IStructuredModel model;
- private Document dom;
- protected int timerTaskCount = 0;
-// protected boolean isGrammarInferenceEnabled;
- protected static Timer timer = new Timer(true);
-
- // Dinamic resources
-
- private WTPKbdBundleNameResource fBundleNameResourceRegistered = null;
- private WTPKbdBeanPropertyResource fBeanPropertyResourceRegistered = null;
- private WTPKbdBundlePropertyResource fBundlePropertyResourceRegistered = null;
- private WTPKbdActionResource fActionResourceRegistered = null;
- private WTPKbdBeanMethodResource fBeanMethodResourceRegistered = null;
- private WTPKbImageFileResource fImageFileResourced = null;
- private WTPKbdManagedBeanNameResource fManagedBeanNameResourceRegistered = null;
- private WTPKbJsfValuesResource fJSFValuesResource = null;
- WTPKbdTaglibResource fTaglibResource = null;
-
- public WTPTextJspKbConnector(IEditorInput editorInput, IDocument document, IStructuredModel model) {
- try {
- this.fDocument = document;
- this.fEditorInput = editorInput;
- this.model = model;
-
- this.dom = (model instanceof IDOMModel) ? ((IDOMModel) model).getDocument() : null;
-
- if (dom != null) {
- new MyDocumentAdapter(dom);
- }
- kbConnector = KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document);
- WTPKbdBundleNameResource bundleNameResource = new WTPKbdBundleNameResource(fEditorInput, this);
- if (bundleNameResource.isReadyToUse()) {
- fBundleNameResourceRegistered = bundleNameResource;
- registerResource(fBundleNameResourceRegistered);
- }
- WTPKbdBeanPropertyResource beanPropertyResource = new WTPKbdBeanPropertyResource(fEditorInput, this);
- if (beanPropertyResource.isReadyToUse()) {
- fBeanPropertyResourceRegistered = beanPropertyResource;
- registerResource(fBeanPropertyResourceRegistered);
- }
- WTPKbdBundlePropertyResource bundlePropertyResource = new WTPKbdBundlePropertyResource(fEditorInput, this);
- if (bundlePropertyResource.isReadyToUse()) {
- fBundlePropertyResourceRegistered = bundlePropertyResource;
- registerResource(fBundlePropertyResourceRegistered);
- }
- WTPKbdActionResource actionResource = new WTPKbdActionResource(fEditorInput, this);
- if (actionResource.isReadyToUse()) {
- fActionResourceRegistered = actionResource;
- registerResource(fActionResourceRegistered);
- }
- WTPKbdBeanMethodResource beanMethodResource = new WTPKbdBeanMethodResource(fEditorInput, this);
- if (beanMethodResource.isReadyToUse()) {
- fBeanMethodResourceRegistered = beanMethodResource;
- registerResource(fBeanMethodResourceRegistered);
- }
- WTPKbImageFileResource imageFileResource = new WTPKbImageFileResource(fEditorInput);
- if(imageFileResource.isReadyToUse()) {
- fImageFileResourced = imageFileResource;
- registerResource(fImageFileResourced);
- }
- WTPKbdManagedBeanNameResource managedBeanNameResource = new WTPKbdManagedBeanNameResource(fEditorInput, this);
- if(managedBeanNameResource.isReadyToUse()) {
- fManagedBeanNameResourceRegistered = managedBeanNameResource;
- registerResource(fManagedBeanNameResourceRegistered);
- }
- WTPKbJsfValuesResource resource = new WTPKbJsfValuesResource(editorInput, this);
- if(resource.isReadyToUse()) {
- fJSFValuesResource = resource;
- registerResource(fJSFValuesResource);
- }
- WTPKbdTaglibResource taglibResource = new WTPKbdTaglibResource(editorInput, this);
- if(taglibResource.isReadyToUse()) {
- fTaglibResource = taglibResource;
- registerResource(fTaglibResource);
- }
- invokeDelayedUpdateKnownTagLists();
- } catch(Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void setTaglibManagerProvider(VpeTaglibManagerProvider taglibManagerProvider) {
- this.taglibManagerProvider = taglibManagerProvider;
- }
-
-
- /**
- * @see org.jboss.tools.common.kb.KbConnector#queryTagInformation(java.lang.String)
- */
- public TagDescriptor getTagInformation(String query) throws KbException {
- return kbConnector.getTagInformation(query);
- }
-
- /**
- * @see org.jboss.tools.common.kb.KbConnector#getProposals(java.lang.String)
- */
- public Collection getProposals(String query) throws KbException {
- return kbConnector.getProposals(query);
- }
-
- /**
- * @see org.jboss.tools.common.kb.KbConnector#registerResource(org.jboss.tools.common.kb.KbResource)
- */
- public boolean registerResource(KbResource resource) {
- return kbConnector.registerResource(resource);
- }
-
- public KbConnector getConnector() {
- return kbConnector;
- }
-
- /**
- * @see org.jboss.tools.common.kb.KbConnector#unregisterResource(org.jboss.tools.common.kb.KbResource)
- */
- public void unregisterResource(KbResource resource) {
- kbConnector.unregisterResource(resource);
- }
-
- // Dinamic support
- private Map<String,Object> trackers = new HashMap<String,Object>();
- private Map<String,LoadBundleInfo> loadedBundles = new HashMap<String,LoadBundleInfo>();
-
- private final static String[] TRACKERS_TO_WATCH = {"http://java.sun.com/jsf/core",
- "https://ajax4jsf.dev.java.net/ajax"
- };
- private boolean taglibTrackerListenerInstalled = false;
-
- public void invokeDelayedUpdateKnownTagLists() {
- // Previous code is
- // timer.schedule(new MyTimerTask(), 500);
- initTaglibPrefixes();
- updateKnownTagLists();
- }
-
- private boolean isTrackerToWatch(String trackerUri) {
- for(int i=0; TRACKERS_TO_WATCH != null && i<TRACKERS_TO_WATCH.length; i++) {
- if (TRACKERS_TO_WATCH[i].equals(trackerUri)) {
- return true;
- }
- }
- return false;
- }
-
- public void initTaglibPrefixes() {
- trackers.clear();
- if(taglibManagerProvider==null || taglibManagerProvider.getTaglibManager()==null) {
- TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(fDocument);
- if(manager!=null) {
- List list = manager.getTaglibTrackers();
- for(int i=0; i<list.size(); i++) {
- TaglibTracker tracker = (TaglibTracker)list.get(i);
- if (isTrackerToWatch(tracker.getURI())) {
- trackers.put(tracker.getPrefix(), tracker);
- }
- }
- }
- } else {
- List list = taglibManagerProvider.getTaglibManager().getTagLibs();
- for(int i=0; i<list.size(); i++) {
- TaglibData data = (TaglibData)list.get(i);
- if (isTrackerToWatch(data.getUri())) {
- trackers.put(data.getPrefix(), data);
- }
- }
- }
- }
-
- public void taglibPrefixChanged(String[] prefixs) {
- trackers.clear();
- if(taglibManagerProvider==null || taglibManagerProvider.getTaglibManager()==null) {
- TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(fDocument);
- List list = manager.getTaglibTrackers();
- for(int i=0; i<list.size(); i++) {
- TaglibTracker tracker = (TaglibTracker)list.get(i);
- if (isTrackerToWatch(tracker.getURI())) {
- trackers.put(tracker.getPrefix(), tracker);
- }
- }
- } else {
- List list = taglibManagerProvider.getTaglibManager().getTagLibs();
- for(int i=0; i<list.size(); i++) {
- TaglibData data = (TaglibData)list.get(i);
- if (isTrackerToWatch(data.getUri())) {
- trackers.put(data.getPrefix(), data);
- }
- }
- }
- invokeDelayedUpdateKnownTagLists();
- }
-
- public void addTaglib(String uri, String prefix) {
- }
-
- public void removeTaglib(String uri, String prefix) {
- }
-
- private boolean installTaglibTrackerListener() {
- if (taglibTrackerListenerInstalled) {
- return true;
- }
- if(taglibManagerProvider!=null) {
- VpeTaglibManager manager = taglibManagerProvider.getTaglibManager();
- if(manager!=null) {
- manager.addTaglibListener(this);
- taglibTrackerListenerInstalled = true;
- return true;
- }
- }
- return false;
- }
-
- public void updateKnownTagLists() {
- loadedBundles.clear();
- Element element = dom.getDocumentElement();
- NodeList children = (NodeContainer)dom.getChildNodes();
- installTaglibTrackerListener();
- if (element != null) {
- for (int i = 0; children != null && i < children.getLength(); i++) {
- try {
- IDOMNode xmlnode = (IDOMNode)children.item(i);
- update((IDOMNode)xmlnode);
- } catch (Exception x) {
- JspEditorPlugin.getPluginLog().logError("Error while updating known tag lists", x);
- }
- }
- }
- }
-
- private void update(IDOMNode element) {
- if (element != null) {
- registerKbResourceForNode(element);
- for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child instanceof IDOMNode) {
- update((IDOMNode)child);
- }
- }
- }
- }
-
- public class LoadBundleInfo {
- IDOMNode loadBundleTag;
- String basename;
- String var;
-
- LoadBundleInfo(IDOMNode element, String basename, String var) {
- this.loadBundleTag = element;
- this.basename = basename;
- this.var = var;
- }
-
- int getLoadDeclarationOffset() {
- return loadBundleTag.getStartOffset();
- }
-
- public String getBaseName() {
- return basename;
- }
-
- String getVar() {
- return var;
- }
- }
-
- public Map getDeclaredBundles() {
- if (!taglibTrackerListenerInstalled) {
- initTaglibPrefixes();
- updateKnownTagLists();
- }
- return loadedBundles;
- }
-
- private void registerKbResourceForNode(IDOMNode node) {
- try {
- if (node == null) return;
- String name = node.getNodeName();
- if (name == null) return;
- if (!name.endsWith("loadBundle")) return;
- if (name.indexOf(':') == -1) return;
- String prefix = name.substring(0, name.indexOf(':'));
-
- if (!trackers.containsKey(prefix)) return;
-
- NamedNodeMap attributes = node.getAttributes();
- if (attributes == null) return;
- String basename = (attributes.getNamedItem("basename") == null ? null : attributes.getNamedItem("basename").getNodeValue());
- String var = (attributes.getNamedItem("var") == null ? null : attributes.getNamedItem("var").getNodeValue());
- if (basename == null || basename.length() == 0 ||
- var == null || var.length() == 0) return;
-
- loadedBundles.put(var, new LoadBundleInfo(node, basename, var));
- } catch (Exception x) {
- JspEditorPlugin.getPluginLog().logError("Error while registering kb resource", x);
- }
- }
-
- /**
- * This class listens to the changes in the CMDocument and triggers a CMDocument load
- */
- class MyDocumentAdapter extends DocumentAdapter {
- MyDocumentAdapter(Document document) {
- super(document);
- }
-
- public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int index) {
- switch (eventType) {
- case INodeNotifier.ADD :
- {
- if (newValue instanceof Element) {
- adapt((Element) newValue);
- }
- break;
- }
- case INodeNotifier.REMOVE:
- {
- Node node = (Node) notifier;
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- }
- break;
- }
-
- case INodeNotifier.CHANGE :
- case INodeNotifier.STRUCTURE_CHANGED :
- case INodeNotifier.CONTENT_CHANGED :
- {
- Node node = (Node) notifier;
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- switch (eventType) {
- case INodeNotifier.CHANGE :
- {
- break;
- }
- case INodeNotifier.STRUCTURE_CHANGED :
- {
- // structure change
- break;
- }
- case INodeNotifier.CONTENT_CHANGED :
- {
- // some content changed
- break;
- }
- }
- }
- else if (node.getNodeType() == Node.DOCUMENT_NODE) {
- } else {
- }
- break;
- }
- }
- invokeDelayedUpdateKnownTagLists();
- }
- }
-
- //
- protected class MyTimerTask extends TimerTask {
- public MyTimerTask() {
- super();
- timerTaskCount++;
- }
-
- public void run() {
- timerTaskCount--;
- if (timerTaskCount == 0) {
-// invokeCMDocumentLoad();
- initTaglibPrefixes();
- updateKnownTagLists();
- }
- }
- }
-
- // An abstract adapter that ensures that the children of a new Node are also adapted
- abstract class DocumentAdapter implements INodeAdapter {
- public DocumentAdapter(Document document) {
- ((INodeNotifier) document).addAdapter(this);
- adapt(document.getDocumentElement());
- }
-
- public void adapt(Element element) {
- if (element != null) {
- if (((INodeNotifier) element).getExistingAdapter(this) == null) {
- ((INodeNotifier) element).addAdapter(this);
-
- for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- adapt((Element) child);
- }
- }
- }
- }
- }
-
- public boolean isAdapterForType(Object type) {
- return type == this;
- }
-
- abstract public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int index);
- }
-
+/*******************************************************************************
+ * 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.jst.jsp.support.kb;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.xml.core.internal.document.NodeContainer;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.common.kb.KbConnector;
+import org.jboss.tools.common.kb.KbConnectorFactory;
+import org.jboss.tools.common.kb.KbConnectorType;
+import org.jboss.tools.common.kb.KbException;
+import org.jboss.tools.common.kb.KbResource;
+import org.jboss.tools.common.kb.TagDescriptor;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.jst.web.tld.VpeTaglibListener;
+import org.jboss.tools.jst.web.tld.VpeTaglibManager;
+import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Jeremy
+ */
+public class WTPTextJspKbConnector implements KbConnector, VpeTaglibListener {
+ private KbConnector kbConnector;
+ private IDocument fDocument;
+ private IEditorInput fEditorInput;
+ private VpeTaglibManagerProvider taglibManagerProvider;
+
+ protected IStructuredModel model;
+ private Document dom;
+ protected int timerTaskCount = 0;
+// protected boolean isGrammarInferenceEnabled;
+ protected static Timer timer = new Timer(true);
+
+ // Dinamic resources
+
+ private WTPKbdBundleNameResource fBundleNameResourceRegistered = null;
+ private WTPKbdBeanPropertyResource fBeanPropertyResourceRegistered = null;
+ private WTPKbdBundlePropertyResource fBundlePropertyResourceRegistered = null;
+ private WTPKbdActionResource fActionResourceRegistered = null;
+ private WTPKbdBeanMethodResource fBeanMethodResourceRegistered = null;
+ private WTPKbImageFileResource fImageFileResourced = null;
+ private WTPKbdManagedBeanNameResource fManagedBeanNameResourceRegistered = null;
+ private WTPKbJsfValuesResource fJSFValuesResource = null;
+ WTPKbdTaglibResource fTaglibResource = null;
+
+ public WTPTextJspKbConnector(IEditorInput editorInput, IDocument document, IStructuredModel model) {
+ try {
+ this.fDocument = document;
+ this.fEditorInput = editorInput;
+ this.model = model;
+
+ this.dom = (model instanceof IDOMModel) ? ((IDOMModel) model).getDocument() : null;
+
+ if (dom != null) {
+ new MyDocumentAdapter(dom);
+ }
+ kbConnector = KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document);
+ WTPKbdBundleNameResource bundleNameResource = new WTPKbdBundleNameResource(fEditorInput, this);
+ if (bundleNameResource.isReadyToUse()) {
+ fBundleNameResourceRegistered = bundleNameResource;
+ registerResource(fBundleNameResourceRegistered);
+ }
+ WTPKbdBeanPropertyResource beanPropertyResource = new WTPKbdBeanPropertyResource(fEditorInput, this);
+ if (beanPropertyResource.isReadyToUse()) {
+ fBeanPropertyResourceRegistered = beanPropertyResource;
+ registerResource(fBeanPropertyResourceRegistered);
+ }
+ WTPKbdBundlePropertyResource bundlePropertyResource = new WTPKbdBundlePropertyResource(fEditorInput, this);
+ if (bundlePropertyResource.isReadyToUse()) {
+ fBundlePropertyResourceRegistered = bundlePropertyResource;
+ registerResource(fBundlePropertyResourceRegistered);
+ }
+ WTPKbdActionResource actionResource = new WTPKbdActionResource(fEditorInput, this);
+ if (actionResource.isReadyToUse()) {
+ fActionResourceRegistered = actionResource;
+ registerResource(fActionResourceRegistered);
+ }
+ WTPKbdBeanMethodResource beanMethodResource = new WTPKbdBeanMethodResource(fEditorInput, this);
+ if (beanMethodResource.isReadyToUse()) {
+ fBeanMethodResourceRegistered = beanMethodResource;
+ registerResource(fBeanMethodResourceRegistered);
+ }
+ WTPKbImageFileResource imageFileResource = new WTPKbImageFileResource(fEditorInput);
+ if(imageFileResource.isReadyToUse()) {
+ fImageFileResourced = imageFileResource;
+ registerResource(fImageFileResourced);
+ }
+ WTPKbdManagedBeanNameResource managedBeanNameResource = new WTPKbdManagedBeanNameResource(fEditorInput, this);
+ if(managedBeanNameResource.isReadyToUse()) {
+ fManagedBeanNameResourceRegistered = managedBeanNameResource;
+ registerResource(fManagedBeanNameResourceRegistered);
+ }
+ WTPKbJsfValuesResource resource = new WTPKbJsfValuesResource(editorInput, this);
+ if(resource.isReadyToUse()) {
+ fJSFValuesResource = resource;
+ registerResource(fJSFValuesResource);
+ }
+ WTPKbdTaglibResource taglibResource = new WTPKbdTaglibResource(editorInput, this);
+ if(taglibResource.isReadyToUse()) {
+ fTaglibResource = taglibResource;
+ registerResource(fTaglibResource);
+ }
+ invokeDelayedUpdateKnownTagLists();
+ } catch(Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void setTaglibManagerProvider(VpeTaglibManagerProvider taglibManagerProvider) {
+ this.taglibManagerProvider = taglibManagerProvider;
+ }
+
+
+ /**
+ * @see org.jboss.tools.common.kb.KbConnector#queryTagInformation(java.lang.String)
+ */
+ public TagDescriptor getTagInformation(String query) throws KbException {
+ return kbConnector.getTagInformation(query);
+ }
+
+ /**
+ * @see org.jboss.tools.common.kb.KbConnector#getProposals(java.lang.String)
+ */
+ public Collection getProposals(String query) throws KbException {
+ return kbConnector.getProposals(query);
+ }
+
+ /**
+ * @see org.jboss.tools.common.kb.KbConnector#registerResource(org.jboss.tools.common.kb.KbResource)
+ */
+ public boolean registerResource(KbResource resource) {
+ return kbConnector.registerResource(resource);
+ }
+
+ public KbConnector getConnector() {
+ return kbConnector;
+ }
+
+ /**
+ * @see org.jboss.tools.common.kb.KbConnector#unregisterResource(org.jboss.tools.common.kb.KbResource)
+ */
+ public void unregisterResource(KbResource resource) {
+ kbConnector.unregisterResource(resource);
+ }
+
+ // Dinamic support
+ private Map<String,Object> trackers = new HashMap<String,Object>();
+ private Map<String,LoadBundleInfo> loadedBundles = new HashMap<String,LoadBundleInfo>();
+
+ private final static String[] TRACKERS_TO_WATCH = {"http://java.sun.com/jsf/core",
+ "https://ajax4jsf.dev.java.net/ajax"
+ };
+ private boolean taglibTrackerListenerInstalled = false;
+
+ public void invokeDelayedUpdateKnownTagLists() {
+ // Previous code is
+ // timer.schedule(new MyTimerTask(), 500);
+ initTaglibPrefixes();
+ updateKnownTagLists();
+ }
+
+ private boolean isTrackerToWatch(String trackerUri) {
+ for(int i=0; TRACKERS_TO_WATCH != null && i<TRACKERS_TO_WATCH.length; i++) {
+ if (TRACKERS_TO_WATCH[i].equals(trackerUri)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void initTaglibPrefixes() {
+ trackers.clear();
+ if(taglibManagerProvider==null || taglibManagerProvider.getTaglibManager()==null) {
+ TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(fDocument);
+ if(manager!=null) {
+ List list = manager.getTaglibTrackers();
+ for(int i=0; i<list.size(); i++) {
+ TaglibTracker tracker = (TaglibTracker)list.get(i);
+ if (isTrackerToWatch(tracker.getURI())) {
+ trackers.put(tracker.getPrefix(), tracker);
+ }
+ }
+ }
+ } else {
+ List list = taglibManagerProvider.getTaglibManager().getTagLibs();
+ for(int i=0; i<list.size(); i++) {
+ TaglibData data = (TaglibData)list.get(i);
+ if (isTrackerToWatch(data.getUri())) {
+ trackers.put(data.getPrefix(), data);
+ }
+ }
+ }
+ }
+
+ public void taglibPrefixChanged(String[] prefixs) {
+ trackers.clear();
+ if(taglibManagerProvider==null || taglibManagerProvider.getTaglibManager()==null) {
+ TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(fDocument);
+ List list = manager.getTaglibTrackers();
+ for(int i=0; i<list.size(); i++) {
+ TaglibTracker tracker = (TaglibTracker)list.get(i);
+ if (isTrackerToWatch(tracker.getURI())) {
+ trackers.put(tracker.getPrefix(), tracker);
+ }
+ }
+ } else {
+ List list = taglibManagerProvider.getTaglibManager().getTagLibs();
+ for(int i=0; i<list.size(); i++) {
+ TaglibData data = (TaglibData)list.get(i);
+ if (isTrackerToWatch(data.getUri())) {
+ trackers.put(data.getPrefix(), data);
+ }
+ }
+ }
+ invokeDelayedUpdateKnownTagLists();
+ }
+
+ public void addTaglib(String uri, String prefix) {
+ }
+
+ public void removeTaglib(String uri, String prefix) {
+ }
+
+ private boolean installTaglibTrackerListener() {
+ if (taglibTrackerListenerInstalled) {
+ return true;
+ }
+ if(taglibManagerProvider!=null) {
+ VpeTaglibManager manager = taglibManagerProvider.getTaglibManager();
+ if(manager!=null) {
+ manager.addTaglibListener(this);
+ taglibTrackerListenerInstalled = true;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void updateKnownTagLists() {
+ loadedBundles.clear();
+ Element element = dom.getDocumentElement();
+ NodeList children = (NodeContainer)dom.getChildNodes();
+ installTaglibTrackerListener();
+ if (element != null) {
+ for (int i = 0; children != null && i < children.getLength(); i++) {
+ try {
+ IDOMNode xmlnode = (IDOMNode)children.item(i);
+ update((IDOMNode)xmlnode);
+ } catch (Exception x) {
+ JspEditorPlugin.getPluginLog().logError("Error while updating known tag lists", x);
+ }
+ }
+ }
+ }
+
+ private void update(IDOMNode element) {
+ if (element != null) {
+ registerKbResourceForNode(element);
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child instanceof IDOMNode) {
+ update((IDOMNode)child);
+ }
+ }
+ }
+ }
+
+ public class LoadBundleInfo {
+ IDOMNode loadBundleTag;
+ String basename;
+ String var;
+
+ LoadBundleInfo(IDOMNode element, String basename, String var) {
+ this.loadBundleTag = element;
+ this.basename = basename;
+ this.var = var;
+ }
+
+ int getLoadDeclarationOffset() {
+ return loadBundleTag.getStartOffset();
+ }
+
+ public String getBaseName() {
+ return basename;
+ }
+
+ String getVar() {
+ return var;
+ }
+ }
+
+ public Map getDeclaredBundles() {
+ if (!taglibTrackerListenerInstalled) {
+ initTaglibPrefixes();
+ updateKnownTagLists();
+ }
+ return loadedBundles;
+ }
+
+ private void registerKbResourceForNode(IDOMNode node) {
+ try {
+ if (node == null) return;
+ String name = node.getNodeName();
+ if (name == null) return;
+ if (!name.endsWith("loadBundle")) return;
+ if (name.indexOf(':') == -1) return;
+ String prefix = name.substring(0, name.indexOf(':'));
+
+ if (!trackers.containsKey(prefix)) return;
+
+ NamedNodeMap attributes = node.getAttributes();
+ if (attributes == null) return;
+ String basename = (attributes.getNamedItem("basename") == null ? null : attributes.getNamedItem("basename").getNodeValue());
+ String var = (attributes.getNamedItem("var") == null ? null : attributes.getNamedItem("var").getNodeValue());
+ if (basename == null || basename.length() == 0 ||
+ var == null || var.length() == 0) return;
+
+ loadedBundles.put(var, new LoadBundleInfo(node, basename, var));
+ } catch (Exception x) {
+ JspEditorPlugin.getPluginLog().logError("Error while registering kb resource", x);
+ }
+ }
+
+ public void dispose() {
+ KbConnectorFactory.getIntstance().removeConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, fDocument);
+ }
+ /**
+ * This class listens to the changes in the CMDocument and triggers a CMDocument load
+ */
+ class MyDocumentAdapter extends DocumentAdapter {
+ MyDocumentAdapter(Document document) {
+ super(document);
+ }
+
+ public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int index) {
+ switch (eventType) {
+ case INodeNotifier.ADD :
+ {
+ if (newValue instanceof Element) {
+ adapt((Element) newValue);
+ }
+ break;
+ }
+ case INodeNotifier.REMOVE:
+ {
+ Node node = (Node) notifier;
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ }
+ break;
+ }
+
+ case INodeNotifier.CHANGE :
+ case INodeNotifier.STRUCTURE_CHANGED :
+ case INodeNotifier.CONTENT_CHANGED :
+ {
+ Node node = (Node) notifier;
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ switch (eventType) {
+ case INodeNotifier.CHANGE :
+ {
+ break;
+ }
+ case INodeNotifier.STRUCTURE_CHANGED :
+ {
+ // structure change
+ break;
+ }
+ case INodeNotifier.CONTENT_CHANGED :
+ {
+ // some content changed
+ break;
+ }
+ }
+ }
+ else if (node.getNodeType() == Node.DOCUMENT_NODE) {
+ } else {
+ }
+ break;
+ }
+ }
+ invokeDelayedUpdateKnownTagLists();
+ }
+ }
+
+ //
+ protected class MyTimerTask extends TimerTask {
+ public MyTimerTask() {
+ super();
+ timerTaskCount++;
+ }
+
+ public void run() {
+ timerTaskCount--;
+ if (timerTaskCount == 0) {
+// invokeCMDocumentLoad();
+ initTaglibPrefixes();
+ updateKnownTagLists();
+ }
+ }
+ }
+
+ // An abstract adapter that ensures that the children of a new Node are also adapted
+ abstract class DocumentAdapter implements INodeAdapter {
+ public DocumentAdapter(Document document) {
+ ((INodeNotifier) document).addAdapter(this);
+ adapt(document.getDocumentElement());
+ }
+
+ public void adapt(Element element) {
+ if (element != null) {
+ if (((INodeNotifier) element).getExistingAdapter(this) == null) {
+ ((INodeNotifier) element).addAdapter(this);
+
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ adapt((Element) child);
+ }
+ }
+ }
+ }
+ }
+
+ public boolean isAdapterForType(Object type) {
+ return type == this;
+ }
+
+ abstract public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int index);
+ }
+
}
\ No newline at end of file
18 years
JBoss Tools SVN: r6989 - in trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf: templates and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: dsakovich
Date: 2008-03-18 11:32:57 -0400 (Tue, 18 Mar 2008)
New Revision: 6989
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFReapeatTemplate.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml
Log:
http://jira.jboss.org/jira/browse/JBIDE-1922
Added: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFReapeatTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFReapeatTemplate.java (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFReapeatTemplate.java 2008-03-18 15:32:57 UTC (rev 6989)
@@ -0,0 +1,20 @@
+package org.jboss.tools.jsf.vpe.ajax4jsf.template;
+
+
+
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Node;
+
+public class Ajax4JSFReapeatTemplate extends VpeAbstractTemplate {
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ return new VpeCreationData(null);
+ }
+
+
+}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml 2008-03-18 14:55:47 UTC (rev 6988)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/templates/vpe-templates-ajax4jsf.xml 2008-03-18 15:32:57 UTC (rev 6989)
@@ -314,10 +314,10 @@
<vpe:template children="yes" file="{@viewId}" class="org.jboss.tools.vpe.editor.template.VpeIncludeTemplate"/>
</vpe:tag>
- <vpe:tag name="a4j:repeat" case-sensitive="yes">
- <vpe:template children="yes" modify="no">
- </vpe:template>
- </vpe:tag>
+ <vpe:tag name="a4j:repeat" case-sensitive="yes" haveVisualPreview="no">
+ <vpe:template children="yes" modify="yes" class="org.jboss.tools.jsf.vpe.ajax4jsf.template.Ajax4JSFReapeatTemplate">
+ </vpe:template>
+ </vpe:tag>
<vpe:tag name="a4j:portlet" case-sensitive="yes">
<vpe:template children="yes" modify="no">
18 years
JBoss Tools SVN: r6988 - trunk/as/docs/reference/en/images/perspective.
by jbosstools-commits@lists.jboss.org
Author: ochikvina
Date: 2008-03-18 10:55:47 -0400 (Tue, 18 Mar 2008)
New Revision: 6988
Modified:
trunk/as/docs/reference/en/images/perspective/perspective_12.png
trunk/as/docs/reference/en/images/perspective/perspective_25.png
Log:
http://jira.jboss.com/jira/browse/JBDS-280 - updating screenshots according to the task
Modified: trunk/as/docs/reference/en/images/perspective/perspective_12.png
===================================================================
(Binary files differ)
Modified: trunk/as/docs/reference/en/images/perspective/perspective_25.png
===================================================================
(Binary files differ)
18 years