[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors ...
Robert Stryker
rawblem at gmail.com
Thu Nov 16 17:45:30 EST 2006
User: rawb
Date: 06/11/16 17:45:30
Added: as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors
ServiceXMLCorrectionAssistantProvider.java
ServicexmlModelHandler.java
ServiceXMLEditorConfiguration.java
ServiceXMLOutlineConfiguration.java
AdaptorFactoryProviderForServiceXML.java
Log:
Initial Revision
Revision Changes Path
1.1 date: 2006/11/16 22:45:30; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors/ServiceXMLCorrectionAssistantProvider.java
Index: ServiceXMLCorrectionAssistantProvider.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.ui.mbeans.editors;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
import org.eclipse.wst.sse.ui.internal.correction.IQuickAssistProcessor;
import org.eclipse.wst.sse.ui.internal.correction.IQuickFixProcessor;
import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.text.IXMLPartitions;
import org.eclipse.wst.xml.ui.internal.correction.CorrectionAssistantProviderXML;
import org.eclipse.wst.xml.ui.internal.correction.CorrectionProcessorXML;
import org.eclipse.wst.xml.ui.internal.correction.QuickAssistProcessorXML;
import org.eclipse.wst.xml.ui.internal.correction.QuickFixProcessorXML;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
import org.jboss.ide.eclipse.as.ui.mbeans.Messages;
import org.jboss.ide.eclipse.as.ui.util.ServiceXMLEditorUtil;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ServiceXMLCorrectionAssistantProvider extends CorrectionAssistantProviderXML {
public ServiceXMLCorrectionAssistantProvider() {
super();
}
public IContentAssistant getCorrectionAssistant(ISourceViewer sourceViewer) {
IContentAssistant ca = null;
if (sourceViewer != null) {
ContentAssistant assistant = new ContentAssistant();
if (sourceViewer != null) {
IContentAssistProcessor correctionProcessor = new CorrectionProcessorServiceXML(sourceViewer);
assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_DEFAULT);
assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_CDATA);
assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_COMMENT);
assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_DECLARATION);
assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_PI);
assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.DTD_SUBSET);
}
ca = assistant;
}
return ca;
}
public static class CorrectionProcessorServiceXML extends CorrectionProcessorXML {
protected IQuickAssistProcessor fQuickAssistProcessor;
protected IQuickFixProcessor fQuickFixProcessor;
public CorrectionProcessorServiceXML(ISourceViewer sourceViewer) {
super(sourceViewer);
}
protected IQuickAssistProcessor getQuickAssistProcessor() {
if (fQuickAssistProcessor == null)
fQuickAssistProcessor = new QuickAssistProcessorServiceXML();
return fQuickAssistProcessor;
}
protected IQuickFixProcessor getQuickFixProcessor() {
if (fQuickFixProcessor == null)
fQuickFixProcessor = new QuickFixProcessorXML();
return fQuickFixProcessor;
}
}
public static class QuickAssistProcessorServiceXML extends QuickAssistProcessorXML {
public boolean canAssist(StructuredTextViewer viewer, int offset) {
if( super.canAssist(viewer, offset)) return true;
IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
if( mbeanHasAdditionalAttributes(node)) return true;
return false;
}
private boolean mbeanHasAdditionalAttributes( IDOMNode node ) {
int length = mbeanGetMissingAttributes(node).length;
return length == 0 ? false : true;
}
private String[] mbeanGetMissingAttributes( IDOMNode node ) {
Node parentNode = node.getParentNode();
if( node.getNodeName().equals("mbean") || (node.getNodeName().equals("#text") && parentNode.getNodeName().equals("mbean"))) {
Node mbeanNode = node.getNodeName().equals("mbean") ? node : parentNode;
NamedNodeMap attributes = mbeanNode.getAttributes();
for( int i = 0; i < attributes.getLength(); i++ ) {
if( attributes.item(i).getNodeName().equals("code")) {
// we found our code element, now lets get the IType.
String codeClass = attributes.item(i).getNodeValue();
IType type = ServiceXMLEditorUtil.findType(codeClass);
if( type != null ) {
IMethod[] methods = ServiceXMLEditorUtil.getAllMethods(type);
ArrayList attributeNames = new ArrayList(Arrays.asList(ServiceXMLEditorUtil.findAttributesFromMethods(methods, "")));
NodeList mbeanChildren = mbeanNode.getChildNodes();
// count children named 'attribute'
for( int j = 0; j < mbeanChildren.getLength(); j++ ) {
if( mbeanChildren.item(j).getNodeName().equals("attribute")) {
try {
Node t = mbeanChildren.item(j).getAttributes().getNamedItem("name");
String attName = t.getNodeValue();
attributeNames.remove(attName);
} catch( Exception e ) {
e.printStackTrace();
}
}
}
return (String[]) attributeNames.toArray(new String[attributeNames.size()]);
}
}
}
}
return new String[] { };
}
public ICompletionProposal[] getProposals(StructuredTextViewer viewer, int offset) throws CoreException {
ArrayList props = new ArrayList();
if( super.canAssist(viewer, offset)) props.addAll(Arrays.asList(super.getProposals(viewer, offset)));
IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
addMissingAttributesProposal(node, props);
return (ICompletionProposal[]) props.toArray(new ICompletionProposal[props.size()]);
}
protected void addMissingAttributesProposal(IDOMNode node, ArrayList proposals) {
String[] missing = mbeanGetMissingAttributes(node);
if( missing.length == 0 ) return;
Node parentNode = node.getParentNode();
Node mbeanNode = node.getNodeName().equals("mbean") ? node : parentNode;
// how many tabs?
Node newParent = mbeanNode;
StringBuffer attributeIndent = new StringBuffer();
StringBuffer mbeanClosingIndent = new StringBuffer();
boolean starting = true;
attributeIndent.append("\n");
mbeanClosingIndent.append("\n");
while( newParent != null && !(newParent instanceof DocumentImpl)) {
newParent = newParent.getParentNode();
attributeIndent.append("\t");
if( starting )
starting = false;
else
mbeanClosingIndent.append("\t");
}
StringBuffer buf = new StringBuffer();
for( int i = 0; i < missing.length; i++ ) {
buf.append(attributeIndent);
buf.append("<attribute name=\"");
buf.append(missing[i]);
buf.append("\"></attribute>");
}
buf.append(mbeanClosingIndent);
// where to put it
IDOMNode lastChild = (IDOMNode)mbeanNode.getLastChild();
int endOffset = lastChild.getEndOffset();
Image elImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ELEMENT);
proposals.add( new CompletionProposal(buf.toString(), endOffset, 0, 0,
elImage, Messages.ServiceXMLAddAttributeTags, null, null) );
}
}
}
1.1 date: 2006/11/16 22:45:30; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors/ServicexmlModelHandler.java
Index: ServicexmlModelHandler.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.ui.mbeans.editors;
import org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector;
import org.eclipse.wst.sse.core.internal.document.IDocumentLoader;
import org.eclipse.wst.sse.core.internal.ltk.modelhandler.AbstractModelHandler;
import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler;
import org.eclipse.wst.sse.core.internal.provisional.IModelLoader;
import org.eclipse.wst.xml.core.internal.encoding.XMLDocumentCharsetDetector;
import org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader;
import org.eclipse.wst.xml.core.internal.modelhandler.XMLModelLoader;
public class ServicexmlModelHandler extends AbstractModelHandler implements IModelHandler{
final static String CONTENTTYPE_ID = "org.jboss.ide.eclipse.as.ui.mbeans.servicexml"; //$NON-NLS-1$
final private static String MODELHANDLER_ID = "org.jboss.ide.eclipse.as.ui.servicexmlModelHandler"; //$NON-NLS-1$
public ServicexmlModelHandler() {
super();
setId(MODELHANDLER_ID);
setAssociatedContentTypeId(CONTENTTYPE_ID);
}
public IDocumentCharsetDetector getEncodingDetector() {
return new XMLDocumentCharsetDetector();
}
public IDocumentLoader getDocumentLoader() {
return new XMLDocumentLoader();
}
public IModelLoader getModelLoader() {
return new XMLModelLoader();
}
}
1.1 date: 2006/11/16 22:45:30; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors/ServiceXMLEditorConfiguration.java
Index: ServiceXMLEditorConfiguration.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.ui.mbeans.editors;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.SearchRequestor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitionTypes;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions;
import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.eclipse.wst.xml.ui.internal.contentassist.NoRegionContentAssistProcessor;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
import org.jboss.ide.eclipse.as.ui.util.BaseXMLHyperlinkUtil;
import org.jboss.ide.eclipse.as.ui.util.PackageTypeSearcher;
import org.jboss.ide.eclipse.as.ui.util.ServiceXMLEditorUtil;
import org.jboss.ide.eclipse.as.ui.util.PackageTypeSearcher.ResultFilter;
import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public class ServiceXMLEditorConfiguration extends
StructuredTextViewerConfigurationXML {
public ServiceXMLEditorConfiguration() {
super();
}
protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
IContentAssistProcessor[] processors = null;
if ((partitionType == IStructuredPartitionTypes.DEFAULT_PARTITION) || (partitionType == IXMLPartitions.XML_DEFAULT)) {
processors = new IContentAssistProcessor[] { new ServiceXMLContentAssistProcessor() };
//processors = new IContentAssistProcessor[]{new CFGXMLContentAssistProcessor()};
}
else if (partitionType == IStructuredPartitionTypes.UNKNOWN_PARTITION) {
processors = new IContentAssistProcessor[]{new NoRegionContentAssistProcessor()};
}
return processors;
}
public class ServiceXMLContentAssistProcessor extends XMLContentAssistProcessor {
private HashMap children;
private HashMap attributes;
public ServiceXMLContentAssistProcessor() {
super();
children = new HashMap();
attributes = new HashMap();
fillChildren();
fillAttributes();
}
private class ChildOccurances {
public static final String ZERO_OR_ONE = "_ZERO_OR_ONE_";
public static final String ONE = "_ONE_";
public static final String ZERO_TO_INFINITY = "_ZERO_TO_INFINITY_";
public static final String ONE_TO_INFINITY = "_ONE_TO_INFINITY_";
public String name;
public String numOccurances;
public ChildOccurances(String name, String numOcc) {
this.name = name;
this.numOccurances = numOcc;
}
}
private class DTDAttributes {
public static final int REQUIRED = 1;
public static final int IMPLIED = 2;
public static final int FIXED = 3;
public static final int CDATA_TYPE = 1;
public static final int ENUM_TYPE = 2;
public String name;
public int mandatory;
public int dataType;
public String[] enumOptions;
public String defaultValue;
public DTDAttributes(String name, int dataType, int mandatory ) {
this(name, mandatory, dataType, null);
}
public DTDAttributes(String name, int dataType, int mandatory, String defaultValue) {
this(name, mandatory, dataType, defaultValue, new String[0]);
}
public DTDAttributes(String name, int dataType, int mandatory, String defaultValue, String[] enumOptions) {
this.name = name;
this.enumOptions = enumOptions;
this.mandatory = mandatory;
this.dataType = dataType;
this.defaultValue = defaultValue == null ? "" : defaultValue;
}
}
private void fillChildren() {
ArrayList list = new ArrayList();
list.add(new ChildOccurances("loader-repository", ChildOccurances.ZERO_OR_ONE));
list.add(new ChildOccurances("local-directory", ChildOccurances.ZERO_TO_INFINITY));
list.add(new ChildOccurances("classpath", ChildOccurances.ZERO_TO_INFINITY));
list.add(new ChildOccurances("mbean", ChildOccurances.ZERO_TO_INFINITY));
children.put("server", list);
list = new ArrayList();
list.add(new ChildOccurances("loader-repository-config", ChildOccurances.ZERO_TO_INFINITY));
children.put("loader-repository", list);
children.put("loader-repository-config", new ArrayList());
children.put("local-directory", new ArrayList());
children.put("classpath", new ArrayList());
list = new ArrayList();
list.add(new ChildOccurances("constructor", ChildOccurances.ZERO_OR_ONE));
list.add(new ChildOccurances("xmbean", ChildOccurances.ZERO_OR_ONE));
list.add(new ChildOccurances("attribute", ChildOccurances.ZERO_TO_INFINITY));
list.add(new ChildOccurances("depends", ChildOccurances.ZERO_TO_INFINITY));
list.add(new ChildOccurances("depends-list", ChildOccurances.ZERO_TO_INFINITY));
children.put("mbean", list);
children.put("xmbean", new ArrayList());
list = new ArrayList();
list.add(new ChildOccurances("arg", ChildOccurances.ZERO_TO_INFINITY));
children.put("constructor", list);
children.put("arg", new ArrayList());
children.put("attribute", new ArrayList());
children.put("property", new ArrayList());
list = new ArrayList();
list.add(new ChildOccurances("mbean", ChildOccurances.ZERO_TO_INFINITY));
children.put("depends", list);
list = new ArrayList();
list.add(new ChildOccurances("depends-list-element", ChildOccurances.ONE_TO_INFINITY));
children.put("depends-list", list);
list = new ArrayList();
list.add(new ChildOccurances("mbean", ChildOccurances.ZERO_TO_INFINITY));
children.put("depends-list-element", list);
}
private void fillAttributes() {
attributes.put("server", new ArrayList());
/*
* <!ELEMENT loader-repository (#PCDATA | loader-repository-config)*>
* <!ATTLIST loader-repository loaderRepositoryClass CDATA #IMPLIED>
*/
attributes.put("loader-repository", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("loaderRepositoryClass", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
/*
* <!ELEMENT loader-repository-config (#PCDATA)>
* <!ATTLIST loader-repository-config configParserClass CDATA #IMPLIED>
*/
attributes.put("loader-repository-config", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("configParserClass", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
/*
* <!ELEMENT local-directory EMPTY>
* <!ATTLIST local-directory path CDATA #IMPLIED>
*/
attributes.put("local-directory", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("path", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
/*
<!ELEMENT classpath EMPTY>
<!ATTLIST classpath codebase CDATA #REQUIRED>
<!ATTLIST classpath archives CDATA #IMPLIED>
*/
attributes.put("classpath", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("codebase", DTDAttributes.CDATA_TYPE, DTDAttributes.REQUIRED),
new DTDAttributes("archives", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
/*
<!ELEMENT mbean (constructor? , xmbean? , attribute* , depends* , depends-list*)>
<!ATTLIST mbean code CDATA #REQUIRED>
<!ATTLIST mbean name CDATA #REQUIRED>
<!ATTLIST mbean interface CDATA #IMPLIED>
<!ATTLIST mbean xmbean-dd CDATA #IMPLIED>
<!ATTLIST mbean xmbean-code CDATA #IMPLIED>
*/
attributes.put("mbean", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("code", DTDAttributes.CDATA_TYPE, DTDAttributes.REQUIRED),
new DTDAttributes("name", DTDAttributes.CDATA_TYPE, DTDAttributes.REQUIRED),
new DTDAttributes("interface", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED),
new DTDAttributes("xmbean-dd", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED),
new DTDAttributes("xmbean-code", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
/*
<!ELEMENT arg EMPTY>
<!ATTLIST arg type CDATA #IMPLIED>
<!ATTLIST arg value CDATA #REQUIRED>
*/
attributes.put("arg", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("type", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED),
new DTDAttributes("value", DTDAttributes.CDATA_TYPE, DTDAttributes.REQUIRED)
}));
/*
<!ELEMENT attribute ANY>
<!ATTLIST attribute name CDATA #REQUIRED>
<!ATTLIST attribute replace (true | false) 'true'>
<!ATTLIST attribute trim (true | false) 'true'>
<!ATTLIST attribute attributeClass CDATA #IMPLIED>
<!ATTLIST attribute serialDataType (text | javaBean | jbxb) 'text'>
*/
attributes.put("attribute", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("name", DTDAttributes.CDATA_TYPE, DTDAttributes.REQUIRED),
new DTDAttributes("replace", DTDAttributes.ENUM_TYPE,
DTDAttributes.IMPLIED, "true", new String[] { "true", "false" }),
new DTDAttributes("trim", DTDAttributes.ENUM_TYPE,
DTDAttributes.IMPLIED, "true", new String[] { "true", "false" }),
new DTDAttributes("attributeClass", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED),
new DTDAttributes("serialDataType", DTDAttributes.ENUM_TYPE,
DTDAttributes.IMPLIED, "text", new String[] { "text", "javaBean", "jbxb"})
}));
/*
<!ELEMENT property (#PCDATA)>
<!ATTLIST property name CDATA #REQUIRED>
*/
attributes.put("property", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("name", DTDAttributes.CDATA_TYPE, DTDAttributes.REQUIRED)
}));
/*
<!ELEMENT depends (#PCDATA | mbean)*>
<!ATTLIST depends optional-attribute-name CDATA #IMPLIED>
<!ATTLIST depends proxy-type CDATA #IMPLIED>
*/
attributes.put("depends", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("optional-attribute-name", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED),
new DTDAttributes("proxy-type", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
/*
<!ELEMENT depends-list (depends-list-element)+>
<!ATTLIST depends-list optional-attribute-name CDATA #IMPLIED>
*/
attributes.put("depends-list", Arrays.asList(new DTDAttributes[] {
new DTDAttributes("type", DTDAttributes.CDATA_TYPE, DTDAttributes.IMPLIED)
}));
}
protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) {
super.addEmptyDocumentProposals(contentAssistRequest);
int beginPosition = contentAssistRequest.getReplacementBeginPosition();
String text = "<server>";
int cursorPos = text.length();
contentAssistRequest.addProposal(new CompletionProposal(text, beginPosition,
0, cursorPos, null, text, null, null));
text += "\n\t\n</server>";
contentAssistRequest.addProposal(new CompletionProposal(text, beginPosition,
0, cursorPos+2, null, text.replaceAll("\n", "").replaceAll("\t", ""), null, null));
}
/**
* Seems to be unreachable for me.
* If <server> is not present, it seems to not even call the subclass... wierd
*/
protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) {
super.addStartDocumentProposals(contentAssistRequest);
}
protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) {
String parentElement = contentAssistRequest.getParent().getNodeName();
String thisNode = contentAssistRequest.getNode().getNodeName();
if( thisNode.equals("#text")) thisNode = "";
ArrayList possibleNodes = (ArrayList)children.get(parentElement);
ChildOccurances occ;
for( int i = 0; i < possibleNodes.size(); i++ ) {
occ = (ChildOccurances)possibleNodes.get(i);
if( occ.name.startsWith(thisNode)) {
createAndAddTagCompletionProposals(contentAssistRequest.getNode(), occ, contentAssistRequest.getParent(),
contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest, true);
}
}
}
protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) {
super.addTagInsertionProposals(contentAssistRequest, childPosition);
String parentElement = contentAssistRequest.getParent().getNodeName();
ArrayList possibleNodes = (ArrayList)children.get(parentElement);
if( possibleNodes == null ) return;
ChildOccurances occ;
for( int i = 0; i < possibleNodes.size(); i++ ) {
occ = (ChildOccurances)possibleNodes.get(i);
createAndAddTagCompletionProposals(contentAssistRequest.getNode(), occ, contentAssistRequest.getParent(),
contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest, false);
}
}
private void createAndAddTagCompletionProposals(org.w3c.dom.Node thisNode, ChildOccurances occ,
org.w3c.dom.Node parentNode, int beginPosition, ContentAssistRequest contentAssistRequest, boolean isTagOpened ) {
if( !confirmsOccuranceRequirements(thisNode, parentNode, occ)) return;
Image propImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
/*
* Our tag suggestions should be:
* <element></element>
* <element requiredAttribute="defaultValue" otherRequiredAtt="otherDefault" thirdRequiredNoDefault=""></element>
*/
// <element></element>
String nName = (thisNode.getNodeName().equals("#text") ? "" : thisNode.getNodeName());
String emptyCompletionText = occ.name + ">";
int cursorLoc = emptyCompletionText.length();
emptyCompletionText += "</" + occ.name + ">";
String descriptionText = "";
if( !isTagOpened ) {
emptyCompletionText = "<" + emptyCompletionText;
cursorLoc++;
}
descriptionText = occ.name;
contentAssistRequest.addProposal(new CompletionProposal(emptyCompletionText, beginPosition,
nName.length(), cursorLoc, propImage, descriptionText, null, null));
if( attributes.containsKey(occ.name) ) {
List l = (List)attributes.get(occ.name);
Iterator i = l.iterator();
cursorLoc = -1;
String attributes = "";
while( i.hasNext()) {
DTDAttributes attribute = (DTDAttributes)i.next();
if( attribute.mandatory == DTDAttributes.REQUIRED) {
attributes += " " + attribute.name + "=\"" + attribute.defaultValue + "\"";
if( cursorLoc == -1 && attribute.defaultValue.equals("")) {
cursorLoc = occ.name.length() + attributes.length() - 1;
}
}
}
String requiredCompletionText = occ.name + attributes + "></" + occ.name + ">";
if( !isTagOpened ) {
requiredCompletionText = "<" + requiredCompletionText;
cursorLoc++;
}
descriptionText = occ.name + " (with attributes)";
if( !attributes.equals("")) {
contentAssistRequest.addProposal(new CompletionProposal(requiredCompletionText,
beginPosition, nName.length(), cursorLoc != -1 ? cursorLoc : requiredCompletionText.length(),
propImage, descriptionText, null, null));
}
}
}
private boolean confirmsOccuranceRequirements(org.w3c.dom.Node thisNode, org.w3c.dom.Node parentNode,ChildOccurances occ) {
// if only allowed once, prevent second usage?
return true;
}
protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) {
super.addAttributeNameProposals(contentAssistRequest);
Image attImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
ArrayList activeAttributes = new ArrayList();
NamedNodeMap nnl = contentAssistRequest.getNode().getAttributes();
for( int i = 0; i < nnl.getLength(); i++ ) {
activeAttributes.add(nnl.item(i).getNodeName());
}
String elementName = contentAssistRequest.getNode().getNodeName();
String match = contentAssistRequest.getMatchString();
List list = (List)attributes.get(elementName);
Iterator i = list.iterator();
while(i.hasNext()) {
DTDAttributes att = (DTDAttributes)i.next();
if( att.name.startsWith(match) && !activeAttributes.contains(att.name)) {
String txt = att.name + "=\"" + att.defaultValue + "\"";
contentAssistRequest.addProposal(new CompletionProposal(txt, contentAssistRequest.getReplacementBeginPosition(),
match.length(), txt.length()-1, attImage, att.name, null, null));
}
}
}
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
String elementName = contentAssistRequest.getNode().getNodeName();
String match = contentAssistRequest.getMatchString();
String text = contentAssistRequest.getText();
int beginPos = contentAssistRequest.getReplacementBeginPosition();
// find the attribute we're inside of, because the contentAssistRequester only returns the element (BOO!)
NamedNodeMap map = contentAssistRequest.getNode().getAttributes();
boolean found = false;
AttrImpl attribute = null;
for( int i = 0; i < map.getLength() && !found; i++ ) {
Node tmp = map.item(i);
if( tmp instanceof AttrImpl ) {
int start = ((AttrImpl)tmp).getStartOffset();
int end = ((AttrImpl)tmp).getEndOffset();
if( beginPos > start && beginPos < end ) {
found = true;
attribute = (AttrImpl)tmp;
}
}
}
if( found ) {
if( elementName.equals("mbean") && attribute.getName().equals("code")) {
handleCodeClassNameCompletion(contentAssistRequest);
}
if( elementName.equals("attribute") && attribute.getName().equals("name")) {
handleAttributeNamesCompletion(contentAssistRequest);
}
}
}
protected void handleCodeClassNameCompletion(ContentAssistRequest contentAssistRequest) {
String match = contentAssistRequest.getMatchString();
String attributeCurrentValue;
if( match.startsWith("\"")) attributeCurrentValue = match.substring(1);
else attributeCurrentValue = match;
ResultFilter filter = new ResultFilter() {
public boolean accept(Object found) {
try {
if( found instanceof IPackageFragment ) {
return ((IPackageFragment)found).containsJavaResources();
} else if( found instanceof IType ) {
// only show MBeans
IType type = (IType)found;
String[] interfaces = type.getSuperInterfaceNames();
for( int i = 0; i < interfaces.length; i++ ) {
if( interfaces[i].equals(type.getElementName() + "MBean")) {
return true;
}
}
}
} catch( JavaModelException jme ) {
}
return false;
}
};
PackageTypeSearcher searcher = new PackageTypeSearcher(attributeCurrentValue, filter);
ICompletionProposal[] props = searcher.generateProposals(contentAssistRequest.getReplacementBeginPosition()+1);
for( int i = 0; i < props.length; i++ )
contentAssistRequest.addProposal(props[i]);
}
protected void handleAttributeNamesCompletion(ContentAssistRequest contentAssistRequest) {
String match = contentAssistRequest.getMatchString();
String attributeCurrentValue;
if( match.startsWith("\"")) attributeCurrentValue = match.substring(1);
else attributeCurrentValue = match;
Node node = contentAssistRequest.getNode();
Node mbeanNode = node.getParentNode();
NamedNodeMap mbeanAttributes = mbeanNode.getAttributes();
Node att = mbeanAttributes.getNamedItem("code");
String codeClass = att.getNodeValue();
IType type = ServiceXMLEditorUtil.findType(codeClass);
if( type != null ) {
IMethod[] methods = ServiceXMLEditorUtil.getAllMethods(type);
String[] attributeNames = ServiceXMLEditorUtil.findAttributesFromMethods(methods, attributeCurrentValue);
int beginReplacement = contentAssistRequest.getReplacementBeginPosition()+1;
// Now turn them into proposals
for( int i = 0; i < attributeNames.length; i++ ) {
CompletionProposal cp = new CompletionProposal(attributeNames[i], beginReplacement,
attributeCurrentValue.length(), beginReplacement + attributeNames[i].length());
contentAssistRequest.addProposal(cp);
}
}
}
/**
* Gets all methods that this type, or its super-types, have.
* @param type
* @return
*/
}
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
if (sourceViewer == null || hyperLinksEnabled() ) {
return null;
}
IHyperlinkDetector[] baseDetectors = super.getHyperlinkDetectors(sourceViewer);
ServiceXMLHyperLinkDetector hyperlinkDetector = new ServiceXMLHyperLinkDetector();
if(baseDetectors==null || baseDetectors.length==0) {
return new IHyperlinkDetector[] { hyperlinkDetector };
} else {
IHyperlinkDetector[] result = new IHyperlinkDetector[baseDetectors.length+1];
result[0] = hyperlinkDetector;
for (int i = 0; i < baseDetectors.length; i++) {
result[i+1] = baseDetectors[i];
}
return result;
}
}
private boolean hyperLinksEnabled() {
return !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED);
}
public class ServiceXMLHyperLinkDetector extends BaseXMLHyperlinkUtil implements IHyperlinkDetector {
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (region == null || textViewer == null) {
return null;
}
IDocument document = textViewer.getDocument();
Node currentNode = getCurrentNode(document, region.getOffset() );
Attr attr = getCurrentAttrNode(currentNode, region.getOffset());
if( currentNode.getNodeName().equals("mbean") && attr != null && attr.getName().equals("code")) {
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
SearchPattern codePattern = SearchPattern.createPattern(attr.getValue(),
IJavaSearchConstants.CLASS,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
SearchEngine searchEngine = new SearchEngine();
LocalSearchRequestor requestor = new LocalSearchRequestor();
try {
searchEngine.search(codePattern, new SearchParticipant[]
{SearchEngine.getDefaultSearchParticipant()}, scope, requestor, new NullProgressMonitor());
Object[] results = requestor.getResults();
if( results.length == 1 ) {
if( results[0] instanceof IJavaElement )
return new IHyperlink[] {
new ServiceXMLHyperlink((IJavaElement)results[0],
getHyperlinkRegion(attr)) };
}
} catch( Exception ce ) {
ce.printStackTrace();
}
}
return null;
}
protected class ServiceXMLHyperlink implements IHyperlink {
private IJavaElement element;
private IRegion region;
public ServiceXMLHyperlink(IJavaElement element, IRegion region ) {
this.element = element;
this.region = region;
}
public IRegion getHyperlinkRegion() {
return region;
}
public String getHyperlinkText() {
return null;
}
public String getTypeLabel() {
return null;
}
public void open() {
try {
IEditorPart part = EditorUtility.openInEditor(element, true);
if(part!=null) {
EditorUtility.revealInEditor(part, element);
}
} catch (JavaModelException e) {
// ignore...TODO?
e.printStackTrace();
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
protected class LocalSearchRequestor extends SearchRequestor {
private ArrayList list;
public LocalSearchRequestor() {
list = new ArrayList();
}
public void acceptSearchMatch(SearchMatch match) throws CoreException {
list.add(match.getElement());
}
public Object[] getResults() {
return list.toArray();
}
}
}
}
1.1 date: 2006/11/16 22:45:30; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors/ServiceXMLOutlineConfiguration.java
Index: ServiceXMLOutlineConfiguration.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.ui.mbeans.editors;
import java.util.ArrayList;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.sse.ui.internal.IReleasable;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
import org.eclipse.wst.xml.core.internal.document.DOMModelImpl;
import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager;
import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
import org.eclipse.wst.xml.ui.views.contentoutline.XMLContentOutlineConfiguration;
import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public class ServiceXMLOutlineConfiguration extends
XMLContentOutlineConfiguration {
private ILabelProvider fLabelProvider = null;
private IContentProvider fLocalContentProvider = null;
public ServiceXMLOutlineConfiguration() {
super();
}
public ILabelProvider getLabelProvider(TreeViewer viewer) {
if (fLabelProvider == null) {
fLabelProvider = new ServiceXMLLabelProvider(super.getLabelProvider(viewer));
}
return fLabelProvider;
}
private class ServiceXMLLabelProvider extends LabelProvider {
private ILabelProvider delegate;
private ServiceXMLLabelProvider(ILabelProvider delegate) {
this.delegate = delegate;
}
public Image getImage(Object element) {
try {
return delegate.getImage(element);
} catch( Exception e ) {
if( element instanceof Node && ((Node)element).getNodeType() == Node.ATTRIBUTE_NODE ) {
return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
}
return null;
}
}
private String getNodeName(Object object) {
StringBuffer nodeName = new StringBuffer();
Node node = (Node) object;
nodeName.append(node.getNodeName());
if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
nodeName.insert(0, "DOCTYPE:"); //$NON-NLS-1$
}
return nodeName.toString();
}
public String getText(Object element) {
try {
return delegate.getText(element);
} catch( Exception e ) {
e.printStackTrace();
return null;
}
}
}
public IContentProvider getContentProvider(TreeViewer viewer) {
IContentProvider parentProvider = super.getContentProvider(viewer);
if( fLocalContentProvider == null ) {
fLocalContentProvider = new ServiceXMLContentProvider();
}
return fLocalContentProvider;
}
private class ServiceXMLContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object parentElement) {
Node node = (Node) parentElement;
ArrayList v = new ArrayList();
// First add the attributes
NamedNodeMap map = node.getAttributes();
if( map != null ) {
for( int i = 0; i < map.getLength(); i++ ) {
Node current = map.item(i);
v.add(current);
}
}
// Now add element children
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
Node n = child;
if (n.getNodeType() != Node.TEXT_NODE)
v.add(n);
}
return v.toArray();
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return getChildren(element).length > 0 ? true : false;
}
public Object[] getElements(Object inputElement) {
if( inputElement instanceof DOMModelImpl ) System.out.println(((DOMModelImpl)inputElement).getBaseLocation());
Object topNode = inputElement;
if (inputElement instanceof IDOMModel)
topNode = ((IDOMModel) inputElement).getDocument();
return getChildren(topNode);
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
private ActionManagerMenuListener fContextMenuFiller = null;
/**
* Pilfered from superclass, where it's currently PRIVATE (BOOOO!)
*/
private class ActionManagerMenuListener implements IMenuListener, IReleasable {
private XMLNodeActionManager fActionManager;
private TreeViewer fTreeViewer;
public ActionManagerMenuListener(TreeViewer viewer) {
fTreeViewer = viewer;
}
public void menuAboutToShow(IMenuManager manager) {
if (fActionManager == null) {
fActionManager = createNodeActionManager(fTreeViewer);
}
fActionManager.fillContextMenu(manager, fTreeViewer.getSelection());
}
public void release() {
fTreeViewer = null;
if (fActionManager != null) {
fActionManager.setModel(null);
}
}
}
public IMenuListener getMenuListener(TreeViewer viewer) {
if (fContextMenuFiller == null) {
fContextMenuFiller = new ActionManagerMenuListener(viewer);
}
return fContextMenuFiller;
}
}
1.1 date: 2006/11/16 22:45:30; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.ui.mbeans/src/org/jboss/ide/eclipse/as/ui/mbeans/editors/AdaptorFactoryProviderForServiceXML.java
Index: AdaptorFactoryProviderForServiceXML.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.ui.mbeans.editors;
import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IDocumentTypeHandler;
import org.eclipse.wst.xml.ui.internal.registry.AdapterFactoryProviderForXML;
public class AdaptorFactoryProviderForServiceXML extends
AdapterFactoryProviderForXML {
public boolean isFor(IDocumentTypeHandler contentTypeDescription) {
//return (contentTypeDescription instanceof ServicexmlModelHandler);
return true;
}
}
More information about the jboss-cvs-commits
mailing list