Author: rob.stryker(a)jboss.com
Date: 2007-07-18 20:47:40 -0400 (Wed, 18 Jul 2007)
New Revision: 2512
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/DescriptorXPathPropertySheetPage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyContentProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyLabelProvider.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ConvertNodeToXPathDialog.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/XPathDialogs.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ServerFrame.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/DescriptorXPathViewProvider.java
Log:
A significant update to the descriptor model.
First, caches many less objects.
Second, the API is cleaner IMO.
Still needs some work but nothing major I believe. Wanted to get it into svn to test and
make sure no build errors.
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2007-07-18
17:37:24 UTC (rev 2511)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2007-07-19
00:47:40 UTC (rev 2512)
@@ -68,7 +68,7 @@
TwiddleDialog=Twiddle Dialog
TwiddleDialogExecute=Execute Twiddle
TwiddleDialogDone=Done
-TwiddleDialogArguments=Twiddle Arguments:
+TwiddleDialogArguments=Twiddle Arguments\:
TwiddleDialogTutorial=Twiddle Tutorial
@@ -82,18 +82,18 @@
XPathColumnLocation=Location
XPathColumnAttributeVals=Attribute Values
XPathColumnRawXML=Raw XML
-XPathName=Name:
-XPathPattern=XPath Pattern:
-XPathAttribute=Attribute Name:
+XPathName=Name\:
+XPathPattern=XPath Pattern\:
+XPathAttribute=Attribute Name\:
#preference page
PreferencePageServerTimeouts=Server Timeouts
PreferencePageStartTimeouts=Start Timeout
PreferencePageStopTimeouts=Stop Timeout
-PreferencePageUponTimeout=Upon Timeout:
-PreferencePageUponTimeoutAbort=Abort Server Start
-PreferencePageUponTimeoutIgnore=Set Server State to "Started"
+PreferencePageUponTimeout=Upon Timeout\:
+PreferencePageUponTimeoutAbort=Abort Server Transition
+PreferencePageUponTimeoutIgnore=Set Server State to Target State
#View Preference Page
ViewPreferencePageName=Name
@@ -101,30 +101,31 @@
ViewPreferencePageWeight=Weight
ViewPreferencePageDescription=Description
ViewExtensionEnablementDescription=Below is a list of extensions that may be enabled for
the\
+
JBoss Servers View. \n The enablement box designates whether the extension should be
present.\
+
The weight field \ndesignates how "heavy" each extension is. (Heavier elements
fall towards the bottom.)
-ViewExtensionPreferenceDescription=Below, you may set or clear any preferences specific
to each \
-view extension above. \nSome extensions may have no preferences to set.
+ViewExtensionPreferenceDescription=Below, you may set or clear any preferences specific
to each view extension above. \nSome extensions may have no preferences to set.
# Upgrade Wizard
UpgradeWizardTitle=Convert JBoss AS Launch Configurations
UpgradeWizardDescription=Starting and Stopping JBoss is no longer done through simple
launch configurations.\nInstead, webtools and its server functionality is being used,
which means your launch\nconfigurations must be converted into JBoss "servers"
and "runtimes".\n\n This wizard will help with that.
UpgradeWizardNoConvertableConfigs=You do not have any JBoss launch configurations to
convert, so you can just skip this page.
- UpgradeWizardDetails=Details:
- UpgradeWizardLaunchConfigName=Launch Configuration Name:
- UpgradeWizardLaunchHomeDir=Home Directory:
- UpgradeWizardLaunchJBossConfig=JBoss Configuration:
- UpgradeWizardLaunchStartArgs=Start Args:
- UpgradeWizardLaunchShutdownArgs=Shutdown Args:
- UpgradeWizardLaunchJRE=JRE:
+ UpgradeWizardDetails=Details\:
+ UpgradeWizardLaunchConfigName=Launch Configuration Name\:
+ UpgradeWizardLaunchHomeDir=Home Directory\:
+ UpgradeWizardLaunchJBossConfig=JBoss Configuration\:
+ UpgradeWizardLaunchStartArgs=Start Args\:
+ UpgradeWizardLaunchShutdownArgs=Shutdown Args\:
+ UpgradeWizardLaunchJRE=JRE\:
UpgradeWizardLaunchConvert=Convert?
UpgradeWizardLaunchConfigName2=Configuration Name
UpgradeWizardLaunchRuntimeName=Runtime Name
UpgradeWizardLaunchServerName=Server Name
UpgradeWizardLaunchMonitorMainTask=Converting Launch Configurations
UpgradeWizardLaunchMonitorConverting=Converting
- UpgradeWizardLaunchRuntimeNamesInUse=The following runtime names are already in use:
+ UpgradeWizardLaunchRuntimeNamesInUse=The following runtime names are already in use\:
UpgradeWizardLaunchServerNamesInUse=The following server names are already in use:
@@ -147,8 +148,8 @@
DescriptorXPathAttributeKeyValue=Attribute Key / Value
DescriptorXPathDescriptorValues=Descriptor Values
DescriptorXPathNameLocation=Name / Location
-DescriptorXPathServerName=Server Name:
-DescriptorXPathPortCategory=Port Category:
+DescriptorXPathServerName=Server Name\:
+DescriptorXPathPortCategory=Port Category\:
DescriptorXPathSimple=Show only xpath value in properties view.
DescriptorXPathComplex=Show all details in properties view.
DescriptorXPathMatch=Match
\ No newline at end of file
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ConvertNodeToXPathDialog.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ConvertNodeToXPathDialog.java 2007-07-18
17:37:24 UTC (rev 2511)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ConvertNodeToXPathDialog.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -23,16 +23,12 @@
import java.util.ArrayList;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
@@ -52,20 +48,23 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
-import
org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.SimpleXPathPreferenceTreeItem;
-import
org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.XPathPreferenceTreeItem;
-import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathCategory;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathModel;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
+import org.jboss.ide.eclipse.as.core.server.JBossServer;
import org.jboss.ide.eclipse.as.ui.Messages;
import org.jboss.ide.eclipse.as.ui.dialogs.XPathDialogs.XPathDialog;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+
+
/**
*
* @author rob.stryker(a)jboss.com
*/
+
+// TODO FIX ME!
public class ConvertNodeToXPathDialog extends XPathDialog {
private Node node;
private ArrayList keyRows;
@@ -183,6 +182,7 @@
// fill the combo
NamedNodeMap map = node.getAttributes();
+ System.out.println(map.getLength());
ArrayList list = new ArrayList();
list.add(NO_ATTRIBUTE);
int selectedIndex = 0;
@@ -278,29 +278,21 @@
public void run() {
ConvertNodeToXPathDialog d = new ConvertNodeToXPathDialog(new Shell(), node,
attributeName);
- int result = d.open();
+ int result = -1;
+ try {
+ result = d.open();
+ } catch(Exception e) {e.printStackTrace(); }
if( result == Window.OK) {
- IDeployableServer s = d.getServer();
- SimpleTreeItem tree = s.getAttributeHelper().getXPathPreferenceTree();
+ JBossServer s = d.getServer();
String category = d.getCategory();
- SimpleTreeItem[] categories = tree.getChildren();
- SimpleTreeItem categoryItem = null;
- for( int i = 0; i < categories.length; i++ ) {
- if( categories[i].getData().equals(category))
- categoryItem = categories[i];
+ XPathCategory cat = XPathModel.getDefault().getCategory(s, category);
+ if( cat == null ) {
+ cat = XPathModel.getDefault().addCategory(s, category);
}
-
- // If the category doesn't exist, create it
- if( categoryItem == null ) {
- categoryItem = new SimpleXPathPreferenceTreeItem(tree, category);
- }
-
- XPathPreferenceTreeItem dsfa = new XPathPreferenceTreeItem(categoryItem, d.getName(),
d.getXpath(), d.getAttribute());
- ServerAttributeHelper helper = s.getAttributeHelper();
- helper.saveXPathPreferenceTree(tree);
- helper.save();
+ XPathQuery q = new XPathQuery(d.getName(), s.getConfigDirectory(), null,
d.getXpath(), d.getAttribute());
+ cat.addQuery(q);
+ cat.save();
}
}
-
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/XPathDialogs.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/XPathDialogs.java 2007-07-18
17:37:24 UTC (rev 2511)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/XPathDialogs.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -28,7 +28,6 @@
import java.util.TreeSet;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
@@ -63,34 +62,37 @@
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel;
-import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem2;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XMLDocumentRepository;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathCategory;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathModel;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult.XPathResultNode;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
-import
org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.XPathPreferenceTreeItem;
import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
import org.jboss.ide.eclipse.as.ui.Messages;
-import
org.jboss.ide.eclipse.as.ui.views.server.providers.DescriptorXPathViewProvider.XPathPropertyLabelProvider;
+import
org.jboss.ide.eclipse.as.ui.views.server.providers.descriptors.XPathPropertyLabelProvider;
-public class XPathDialogs {
+/**
+ * A class with some XPath-related dialogs
+ */
+public class XPathDialogs {
public static class XPathCategoryDialog extends Dialog {
- private String textValue;
+ private String initialName;
+ private String currentText;
+ private JBossServer jbs;
private Label errorLabel;
- private SimpleTreeItem tree;
- public XPathCategoryDialog(Shell parentShell, SimpleTreeItem tree) {
+ public XPathCategoryDialog(Shell parentShell, JBossServer jbs) {
super(parentShell);
- this.tree = tree;
+ this.jbs = jbs;
}
- public XPathCategoryDialog(Shell parentShell, SimpleTreeItem tree, String startText) {
- super(parentShell);
- this.tree = tree;
- this.textValue = startText;
+ public XPathCategoryDialog(Shell parentShell, JBossServer jbs, String initialName) {
+ this(parentShell, jbs);
+ this.initialName = initialName;
}
@@ -126,8 +128,8 @@
tData.right = new FormAttachment(100, -5);
t.setLayoutData(tData);
- if( textValue != null ) {
- t.setText(textValue);
+ if( currentText != null ) {
+ t.setText(currentText);
}
t.addModifyListener(new ModifyListener() {
@@ -140,30 +142,22 @@
}
private void verifyText(String text) {
- boolean valid = true;
- SimpleTreeItem[] kids = tree.getChildren();
- for( int i = 0; i < kids.length; i++ ) {
- if( text.equals(kids[i].getData()))
- valid = false;
- }
-
+ boolean valid = !XPathModel.getDefault().containsCategory(jbs, text) || (initialName
!= null && initialName.equals(text));
if( valid ) {
errorLabel.setVisible(false);
- textValue = text;
+ currentText = text;
getButton(IDialogConstants.OK_ID).setEnabled(true);
} else {
errorLabel.setVisible(true);
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
-
}
public String getText() {
- return textValue;
+ return currentText;
}
}
-
public static class XPathDialog extends Dialog {
protected Label errorImage, errorLabel, descriptionLabel;
@@ -174,36 +168,35 @@
protected XPathProposalProvider proposalProvider;
- protected SimpleTreeItem tree;
- protected IDeployableServer server;
+ protected JBossServer server;
protected String name, xpath, attribute, category;
protected String originalName = null;
- protected XPathPreferenceTreeItem original = null;
+ protected XPathQuery original = null;
protected int previewId = 48879;
protected Tree previewTree;
protected TreeColumn column, column2, column3;
protected TreeViewer previewTreeViewer;
protected Composite main;
+ protected XMLDocumentRepository repository;
public XPathDialog(Shell parentShell) {
this(parentShell, null);
}
- public XPathDialog(Shell parentShell, IDeployableServer server) {
+ public XPathDialog(Shell parentShell, JBossServer server) {
this(parentShell, server, null);
}
- public XPathDialog(Shell parentShell, IDeployableServer server, String categoryName) {
+ public XPathDialog(Shell parentShell, JBossServer server, String categoryName) {
this(parentShell, server, categoryName, null);
}
- public XPathDialog(Shell parentShell, IDeployableServer server, String categoryName,
String originalName) {
+ public XPathDialog(Shell parentShell, JBossServer server, String categoryName, String
originalName) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
this.category = categoryName;
this.server = server;
this.originalName = this.name = originalName;
- if( server != null )
- this.tree = server.getAttributeHelper().getXPathPreferenceTree();
+ repository = new XMLDocumentRepository(XMLDocumentRepository.getDefault());
}
protected void configureShell(Shell shell) {
@@ -239,7 +232,7 @@
if( attribute != null ) attributeText.setText(attribute);
if( xpath != null ) xpathText.setText(xpath);
- proposalProvider = new XPathProposalProvider();
+ proposalProvider = new XPathProposalProvider(repository);
proposalProvider.setServer(server);
ContentProposalAdapter adapter = new
ContentProposalAdapter(xpathText, new TextContentAdapter(),
@@ -248,7 +241,7 @@
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
- XPathAttributeProposalProvider provider2 = new
XPathAttributeProposalProvider(xpathText);
+ XPathAttributeProposalProvider provider2 = new
XPathAttributeProposalProvider(repository, xpathText);
provider2.setServer(server);
ContentProposalAdapter adapter2 = new
ContentProposalAdapter(attributeText, new TextContentAdapter(),
@@ -269,7 +262,7 @@
serverCombo.setItems(names);
}
- if( categoryCombo != null && tree != null ) {
+ if( categoryCombo != null ) {
refreshCategoryCombo();
}
}
@@ -386,22 +379,21 @@
if( nameText.getText().equals("")) {
return Messages.XPathNameEmpty;
}
- if( tree != null ) {
- SimpleTreeItem[] categories = tree.getChildren();
- SimpleTreeItem categoryItem = null;
- for( int i = 0; i < categories.length; i++ ) {
- if( categories[i].getData().equals(category))
- categoryItem = categories[i];
- }
- if( categoryItem != null ) {
- SimpleTreeItem[] xpathNames = categoryItem.getChildren();
- boolean found = false;
- for( int i = 0; i < xpathNames.length; i++ ) {
- if(nameText.getText().equals( ((XPathPreferenceTreeItem)xpathNames[i]).getName()))
{
-
- if( originalName == null || !nameText.getText().equals(originalName))
- return Messages.XPathNameInUse;
- }
+ if( server == null ) return null;
+ XPathCategory[] categories =
XPathModel.getDefault().getCategories((JBossServer)server);
+ XPathCategory category = null;
+ for( int i = 0; i < categories.length; i++ ) {
+ if( categories[i].getName().equals(this.category))
+ category = categories[i];
+ }
+ if( category != null ) {
+ XPathQuery[] queries = category.getQueries();
+ boolean found = false;
+ for( int i = 0; i < queries.length; i++ ) {
+ if(nameText.getText().equals( ((XPathQuery)queries[i]).getName())) {
+
+ if( originalName == null || !nameText.getText().equals(originalName))
+ return Messages.XPathNameInUse;
}
}
}
@@ -411,19 +403,20 @@
protected void setServer(JBossServer s) {
server = s;
- tree = server.getAttributeHelper().getXPathPreferenceTree();
proposalProvider.setServer(s);
refreshCategoryCombo();
checkErrors();
}
protected void refreshCategoryCombo() {
- SimpleTreeItem[] categories = tree.getChildren();
- String[] categoryNames = new String[categories.length];
- for( int i = 0; i < categories.length; i++ ) {
- categoryNames[i] = (String)categories[i].getData();
+ if( server != null ) {
+ XPathCategory[] categories = XPathModel.getDefault().getCategories(server);
+ String[] categoryNames = new String[categories.length];
+ for( int i = 0; i < categories.length; i++ ) {
+ categoryNames[i] = (String)categories[i].getName();
+ }
+ categoryCombo.setItems(categoryNames);
}
- categoryCombo.setItems(categoryNames);
}
protected void previewPressed() {
@@ -435,10 +428,10 @@
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
final IProgressMonitor monitor2 = monitor;
- server.getDescriptorModel().refreshDescriptors(monitor2);
- XPathTreeItem[] item = server.getDescriptorModel().getXPath(xpathText.getText(),
attributeText.getText());
+ XPathQuery tmp = new XPathQuery("", server.getConfigDirectory(), null,
xpathText.getText(), attributeText.getText());
+ tmp.setRepository(repository);
final ArrayList list = new ArrayList();
- list.addAll(Arrays.asList(item));
+ list.addAll(Arrays.asList(tmp.getResults()));
Display.getDefault().asyncExec(new Runnable() {
public void run() {
previewTreeViewer.setInput(list);
@@ -493,10 +486,6 @@
previewTreeViewer = new TreeViewer(previewTree);
-
-
-
-
c.layout();
int pixel = Math.max(Math.max(nameLabel.getSize().x, xpathLabel.getSize().x),
attributeLabel.getSize().x);
pixel += 5;
@@ -540,19 +529,19 @@
previewTreeViewer.setContentProvider(new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
// we're a leaf
- if( parentElement instanceof XPathTreeItem2 )
+ if( parentElement instanceof XPathResultNode )
return new Object[0];
// we're a file node (blah.xml)
- if( parentElement instanceof XPathTreeItem ) {
- if( ((XPathTreeItem)parentElement).getChildren().length > 1 )
- return ((XPathTreeItem)parentElement).getChildren();
+ if( parentElement instanceof XPathFileResult ) {
+ if( ((XPathFileResult)parentElement).getChildren().length > 1 )
+ return ((XPathFileResult)parentElement).getChildren();
return new Object[0];
}
// we're the named element (JNDI)
- if( parentElement instanceof XPathPreferenceTreeItem ) {
- SimpleTreeItem[] kids = ((XPathPreferenceTreeItem)parentElement).getChildren();
+ if( parentElement instanceof XPathQuery ) {
+ XPathFileResult[] kids = ((XPathQuery)parentElement).getResults();
return kids;
}
@@ -638,7 +627,7 @@
public String getCategory() {
return category;
}
- public IDeployableServer getServer() {
+ public JBossServer getServer() {
return server;
}
@@ -663,20 +652,22 @@
public static class XPathAttributeProposalProvider extends XPathProposalProvider {
private Text elementText;
- public XPathAttributeProposalProvider(Text elementText) {
+ public XPathAttributeProposalProvider(XMLDocumentRepository repo, Text elementText) {
+ super(repo);
this.elementText = elementText;
}
public IContentProposal[] getProposals(String contents, int position) {
int type = getType(elementText.getText());
- if( type == 4 ) {
+ if( type == IN_ELEMENT ) {
String[] strings = getAttributeNameProposalStrings(elementText.getText(), contents);
return convertProposals(strings);
}
return new IContentProposal[0];
}
+
public String[] getAttributeNameProposalStrings(String parentPath, String remainder) {
ArrayList names = new ArrayList();
- XPathTreeItem2[] items = getXPath(parentPath);
+ XPathResultNode[] items = getXPath(parentPath);
String[] attributes;
for( int i = 0; i < items.length; i++ ) {
attributes = items[0].getElementAttributeNames();
@@ -691,69 +682,64 @@
public static class XPathProposalProvider implements IContentProposalProvider {
- private static final int NEW_ELEMENT = 1;
- private static final int NEW_ATTRIBUTE = 2;
- private static final int NEW_ATTRIBUTE_VALUE = 3;
- private static final int IN_ELEMENT = 4;
- private static final int IN_ATTRIBUTE = 5;
- private static final int IN_ATTRIBUTE_VALUE = 6;
- private static final int CLOSE_ATTRIBUTE = 7;
+ protected static final int NEW_ELEMENT = 1;
+ protected static final int NEW_ATTRIBUTE = 2;
+ protected static final int NEW_ATTRIBUTE_VALUE = 3;
+ protected static final int IN_ELEMENT = 4;
+ protected static final int IN_ATTRIBUTE = 5;
+ protected static final int IN_ATTRIBUTE_VALUE = 6;
+ protected static final int CLOSE_ATTRIBUTE = 7;
private IDeployableServer server;
- private ServerDescriptorModel model;
-
private HashMap xpathCache;
+ protected XMLDocumentRepository repository;
- public XPathProposalProvider() {
+ public XPathProposalProvider(XMLDocumentRepository repository) {
xpathCache = new HashMap();
+ this.repository = repository;
}
public void setServer(IDeployableServer server) {
this.server = server;
- if( server != null ) {
- String serverConfDir = server.getConfigDirectory();
- model = DescriptorModel.getDefault().getServerModel(new Path(serverConfDir));
- } else {
- model = null;
- }
- xpathCache = new HashMap();
}
public IContentProposal[] getProposals(String contents, int position) {
- if( model == null ) return new IContentProposal[]{};
-
if( contents.equals("") || contents.equals("/") ||
contents.equals(" ")) {
return new IContentProposal[] { new XPathContentProposal("/server/",
"/server/".length(), null, null)};
}
try {
- int type = getType(contents);
- if( type == NEW_ELEMENT ) return getElementProposals(contents, "");
- if( type == IN_ELEMENT ) return getElementProposals(contents);
- if( type == NEW_ATTRIBUTE ) return getAttributeNameProposals(contents.substring(0,
contents.length()-1), "");
- if( type == IN_ATTRIBUTE ) return getAttributeNameProposals(contents);
- if( type == NEW_ATTRIBUTE_VALUE ) return getAttributeValueProposals(contents,
"");
- if( type == IN_ATTRIBUTE_VALUE ) return getAttributeValueProposals(contents);
+ int type = getType(contents);
+ if( type == NEW_ELEMENT ) return getElementProposals(contents, "");
+ if( type == IN_ELEMENT ) return getElementProposals(contents);
+ if( type == NEW_ATTRIBUTE ) return getAttributeNameProposals(contents.substring(0,
contents.length()-1), "");
+ if( type == IN_ATTRIBUTE ) return getAttributeNameProposals(contents);
+ if( type == NEW_ATTRIBUTE_VALUE ) return getAttributeValueProposals(contents,
"");
+ if( type == IN_ATTRIBUTE_VALUE ) return getAttributeValueProposals(contents);
} catch( Exception e) {e.printStackTrace();}
return new IContentProposal[]{};
}
- protected XPathTreeItem2[] getXPath(String xpath) {
+ protected XPathResultNode[] getXPath(String xpath) {
+ if( server == null )
+ return new XPathResultNode[0];
+
if( xpathCache.containsKey(xpath)) {
ArrayList list = (ArrayList)xpathCache.get(xpath);
- return (XPathTreeItem2[]) list.toArray(new XPathTreeItem2[list.size()]);
+ return (XPathResultNode[]) list.toArray(new XPathResultNode[list.size()]);
}
-
+ XPathQuery tmp = new XPathQuery("", server.getConfigDirectory(),
"**/*.xml", xpath, null);
+ tmp.setRepository(repository);
ArrayList list = new ArrayList();
- XPathTreeItem[] items = model.getXPath(xpath);
+ XPathFileResult[] items = tmp.getResults();
for( int i = 0; i < items.length; i++ ) {
- SimpleTreeItem[] children = items[i].getChildren();
+ XPathResultNode[] children = items[i].getChildren();
for( int j = 0; j < children.length; j++ ) {
- XPathTreeItem2 i2 = (XPathTreeItem2)children[j];
+ XPathResultNode i2 = (XPathResultNode)children[j];
list.add(i2);
}
}
xpathCache.put(xpath, list);
- return (XPathTreeItem2[]) list.toArray(new XPathTreeItem2[list.size()]);
+ return (XPathResultNode[]) list.toArray(new XPathResultNode[list.size()]);
}
public IContentProposal[] getElementProposals(String path) {
@@ -769,7 +755,7 @@
public String[] getElementProposalStrings(String parentPath, String elementPrefix) {
TreeSet set = new TreeSet();
- XPathTreeItem2[] items = getXPath(parentPath + "*");
+ XPathResultNode[] items = getXPath(parentPath + "*");
for( int i = 0; i < items.length; i++ ) {
if( items[i].getElementName().startsWith(elementPrefix)) {
if( items[i].getElementName().equals(elementPrefix)) {
@@ -793,7 +779,7 @@
}
public String[] getAttributeNameProposalStrings(String parentPath, String remainder) {
ArrayList names = new ArrayList();
- XPathTreeItem2[] items = getXPath(parentPath);
+ XPathResultNode[] items = getXPath(parentPath);
String[] attributes;
for( int i = 0; i < items.length; i++ ) {
attributes = items[0].getElementAttributeNames();
@@ -822,7 +808,7 @@
if( remainder.startsWith("'")) remainder = remainder.substring(1);
ArrayList values = new ArrayList();
- XPathTreeItem2[] items = getXPath(parentElementPath);
+ XPathResultNode[] items = getXPath(parentElementPath);
String[] attributes;
for( int i = 0; i < items.length; i++ ) {
attributes = items[i].getElementAttributeValues(attName);
@@ -900,19 +886,5 @@
return label;
}
}
-
- public String[] getAllSuggegstions() {
- HashMap possibilities = new HashMap();
- XPathTreeItem[] items = model.getXPath("/server/mbean");
- for( int i = 0; i < items.length; i++ ) {
- SimpleTreeItem[] children = items[i].getChildren();
- for( int j = 0; j < children.length; j++ ) {
- XPathTreeItem2 i2 = (XPathTreeItem2)children[j];
- possibilities.put(i2.getElementName(), i2.getElementName());
- }
- }
- return (String[]) possibilities.keySet().toArray(new String[possibilities.size()]);
- }
-
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java 2007-07-18
17:37:24 UTC (rev 2511)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -212,7 +212,9 @@
return new Object[0];
return wrap(o, parentWrapper.getProvider());
}
- } catch( Exception e ) { e.printStackTrace(); }
+ } catch( Exception e ) {
+ //e.printStackTrace();
+ }
return new Object[0];
}
@@ -234,7 +236,6 @@
try {
providers[i].getDelegate().getContentProvider().inputChanged(viewer, oldInput,
newInput);
} catch( Exception e) {
- e.printStackTrace();
}
}
}
@@ -291,11 +292,11 @@
if( selected instanceof ServerViewProvider ) {
menu.add(disableCategoryAction);
}
+
+ //menu.add(new TempAction());
menu.add(new Separator());
}
-
-
public IPropertySheetPage getPropertySheet() {
return propertySheet;
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ServerFrame.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ServerFrame.java 2007-07-18
17:37:24 UTC (rev 2511)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ServerFrame.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -34,6 +34,8 @@
import org.eclipse.wst.server.ui.internal.Messages;
import org.eclipse.wst.server.ui.internal.ServerUIPlugin;
import org.eclipse.wst.server.ui.internal.actions.NewServerWizardAction;
+import org.eclipse.wst.server.ui.internal.view.servers.DeleteAction;
+import org.eclipse.wst.server.ui.internal.view.servers.ModuleSloshAction;
import org.eclipse.wst.server.ui.internal.view.servers.PublishAction;
import org.eclipse.wst.server.ui.internal.view.servers.PublishCleanAction;
import org.eclipse.wst.server.ui.internal.view.servers.StartAction;
@@ -118,20 +120,25 @@
protected void fillContextMenu(Shell shell, IMenuManager menu) {
menu.add(newServerAction);
- menu.add(new Separator());
- //menu.add(new DeleteAction(new Shell(), getSelectedServer()));
- menu.add(new Separator());
- menu.add(actions[1]);
- menu.add(actions[0]);
- menu.add(actions[3]);
- menu.add(actions[4]);
- menu.add(actions[5]);
- menu.add(new Separator());
- menu.add(twiddleAction);
- menu.add(editLaunchConfigAction);
- menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- twiddleAction.setEnabled(true);
- editLaunchConfigAction.setEnabled(true);
+ if( getSelectedServer() != null ) {
+ menu.add(new Separator());
+ menu.add(new DeleteAction(new Shell(), getSelectedServer()));
+ menu.add(new Separator());
+ menu.add(actions[1]);
+ menu.add(actions[0]);
+ menu.add(actions[3]);
+ menu.add(actions[4]);
+ menu.add(actions[5]);
+ menu.add(new Separator());
+ menu.add(twiddleAction);
+ menu.add(editLaunchConfigAction);
+ menu.add(actions[6]);
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ twiddleAction.setEnabled(true);
+ editLaunchConfigAction.setEnabled(true);
+ } else {
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
}
public IServer getSelectedServer() {
@@ -144,20 +151,20 @@
createActions();
- actions = new Action[8];
- // create the start actions
- actions[0] = new StartAction(shell, provider, ILaunchManager.DEBUG_MODE);
- actions[1] = new StartAction(shell, provider, ILaunchManager.RUN_MODE);
- actions[2] = new StartAction(shell, provider, ILaunchManager.PROFILE_MODE);
+ actions = new Action[] {
+ // create the start actions
+ new StartAction(shell, provider, ILaunchManager.DEBUG_MODE),
+ new StartAction(shell, provider, ILaunchManager.RUN_MODE),
+ new StartAction(shell, provider, ILaunchManager.PROFILE_MODE),
- // create the stop action
- actions[3] = new StopAction(shell, provider);
+ // create the stop action
+ new StopAction(shell, provider),
- // create the publish actions
- actions[4] = new PublishAction(shell, provider);
- actions[5] = new PublishCleanAction(shell, provider);
- actions[6] = editLaunchConfigAction;
- actions[7] = twiddleAction;
+ // create the publish actions
+ new PublishAction(shell, provider),
+ new PublishCleanAction(shell, provider),
+ new ModuleSloshAction(shell, provider)
+ };
}
protected void createActions() {
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/DescriptorXPathViewProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/DescriptorXPathViewProvider.java 2007-07-18
17:37:24 UTC (rev 2511)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/DescriptorXPathViewProvider.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -21,107 +21,61 @@
*/
package org.jboss.ide.eclipse.as.ui.views.server.providers;
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
-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.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.TreeEditor;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.wst.server.core.IServer;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem;
-import
org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem2;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathCategory;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathModel;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult.XPathResultNode;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
-import
org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.SimpleXPathPreferenceTreeItem;
-import
org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.XPathPreferenceTreeItem;
-import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
import org.jboss.ide.eclipse.as.ui.Messages;
+import org.jboss.ide.eclipse.as.ui.dialogs.XPathDialogs;
import org.jboss.ide.eclipse.as.ui.dialogs.XPathDialogs.XPathCategoryDialog;
import org.jboss.ide.eclipse.as.ui.dialogs.XPathDialogs.XPathDialog;
-import org.jboss.ide.eclipse.as.ui.preferencepages.ViewProviderPreferenceComposite;
-import org.jboss.ide.eclipse.as.ui.views.server.ExtensionTableViewer.ContentWrapper;
+import org.jboss.ide.eclipse.as.ui.views.server.JBossServerView;
import org.jboss.ide.eclipse.as.ui.views.server.extensions.JBossServerViewExtension;
import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
+import
org.jboss.ide.eclipse.as.ui.views.server.providers.descriptors.DescriptorXPathPropertySheetPage;
+// TODO FIX ME
public class DescriptorXPathViewProvider extends JBossServerViewExtension {
- private static final String XPATH_PROPERTY = "_XPATH_PROPERTY_";
-
private XPathTreeContentProvider contentProvider;
private XPathTreeLabelProvider labelProvider;
private DescriptorXPathPropertySheetPage propertyPage;
- private Action newXPathCategoryAction, deleteXPathCategoryAction, newXPathAction,
+ public Action newXPathCategoryAction, deleteXPathCategoryAction, newXPathAction,
editXPathAction, deleteXPathAction, editFileAction;
private IServer server;
- private IDeployableServer jbServer;
- private SimpleXPathPreferenceTreeItem root;
-
- private Object activeCategory;
+ private JBossServer jbServer;
+ private XPathCategory activeCategory;
private Object selectedPropertyObject;
@@ -133,29 +87,51 @@
}
protected void addListeners() {
+ JBossServerView.getDefault().getExtensionFrame().getViewer().
+ addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object o =
JBossServerView.getDefault().getExtensionFrame().getViewer().getSelectedElement();
+ if( o instanceof XPathCategory ) {
+ // show properties view
+ String propsId = "org.eclipse.ui.views.PropertySheet";
+ try {
+ IWorkbench work = PlatformUI.getWorkbench();
+ IWorkbenchWindow window = work.getActiveWorkbenchWindow();
+ window.getActivePage().showView(propsId);
+ if( propertyPage != null ) {
+ propertyPage.selectionChanged(JBossServerView.getDefault().getViewSite().getPart(),
JBossServerView.getDefault().getExtensionFrame().getViewer().getSelection());
+ }
+ } catch( PartInitException pie ) {
+ }
+ }
+ }
+ });
}
- protected void setActiveCategory(Object o) {
+ public void setActiveCategory(XPathCategory o) {
if( o != null && o != activeCategory) {
activeCategory = o;
}
}
- protected Object getActiveCategory() {
+
+ public XPathCategory getActiveCategory() {
return activeCategory;
}
- protected void setPropertySelection(Object o) {
+
+ public void setPropertySelection(Object o) {
selectedPropertyObject = o;
}
- protected Object getPropertySelection() {
+
+ public Object getPropertySelection() {
return selectedPropertyObject;
}
+
protected class XPathTreeContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object parentElement) {
if( parentElement instanceof ServerViewProvider ) {
- SimpleXPathPreferenceTreeItem root = getRoot();
- if( root == null ) return new Object[]{};
- return root.getChildren();
+ if( jbServer == null ) return new Object[]{};
+ return XPathModel.getDefault().getCategories(jbServer);
}
return new Object[0];
}
@@ -173,21 +149,23 @@
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if( oldInput != newInput ) {
server = (IServer)newInput;
- jbServer = server == null ? null : ServerConverter.getDeployableServer(server);
- root = null;
+ jbServer = server == null ? null : ServerConverter.getJBossServer(server);
}
}
}
+
protected class XPathTreeLabelProvider extends LabelProvider {
+
public Image getImage(Object element) {
- if( element instanceof SimpleXPathPreferenceTreeItem) {
+ if( element instanceof XPathCategory) {
return
PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
return null;
}
+
public String getText(Object element) {
- if( element instanceof SimpleXPathPreferenceTreeItem) {
- return ((SimpleXPathPreferenceTreeItem)element).getData().toString();
+ if( element instanceof XPathCategory) {
+ return ((XPathCategory)element).getName();
}
return "";
}
@@ -202,30 +180,14 @@
return labelProvider;
}
- public SimpleXPathPreferenceTreeItem getRoot() {
- if( root == null && jbServer != null) {
- root = jbServer.getAttributeHelper().getXPathPreferenceTree();
- }
- return root;
- }
-
- public void setRoot(SimpleXPathPreferenceTreeItem root) {
- this.root = root;
- }
-
-
public void createActions() {
newXPathCategoryAction = new Action() {
public void run() {
- SimpleTreeItem item = getRoot();
- XPathCategoryDialog d =
- new XPathCategoryDialog(Display.getCurrent().getActiveShell(), item);
+ XPathCategoryDialog d = new XPathDialogs.XPathCategoryDialog(
+ Display.getCurrent().getActiveShell(), jbServer);
if( d.open() == Window.OK ) {
- String newCategory = d.getText();
- SimpleXPathPreferenceTreeItem child = new SimpleXPathPreferenceTreeItem(item,
newCategory);
- ServerAttributeHelper helper = jbServer.getAttributeHelper();
- helper.saveXPathPreferenceTree(getRoot());
- helper.save();
+ XPathModel.getDefault().addCategory(jbServer, d.getText());
+ XPathModel.getDefault().save(jbServer);
refreshViewer();
}
}
@@ -234,20 +196,15 @@
deleteXPathCategoryAction= new Action() {
public void run() {
- Object selected = getActiveCategory();
- if( selected instanceof SimpleXPathPreferenceTreeItem &&
((SimpleXPathPreferenceTreeItem)selected).getParent().equals(getRoot())) {
- int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
- MessageBox messageBox = new MessageBox (Display.getCurrent().getActiveShell(),
style);
- messageBox.setText (Messages.DescriptorXPathRemoveCategory + "?");
- messageBox.setMessage (Messages.DescriptorXPathRemoveCategoryDesc);
- if( messageBox.open () == SWT.YES ) {
- getRoot().deleteChild(((SimpleXPathPreferenceTreeItem)selected));
- ServerAttributeHelper helper = jbServer.getAttributeHelper();
- helper.saveXPathPreferenceTree(getRoot());
- helper.save();
- setActiveCategory(null);
- refreshViewer();
- }
+ int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
+ MessageBox messageBox = new MessageBox (Display.getCurrent().getActiveShell(),
style);
+ messageBox.setText (Messages.DescriptorXPathRemoveCategory + "?");
+ messageBox.setMessage (Messages.DescriptorXPathRemoveCategoryDesc);
+ if( messageBox.open () == SWT.YES ) {
+ XPathModel.getDefault().removeCategory(jbServer, getActiveCategory().getName());
+ XPathModel.getDefault().save(jbServer);
+ setActiveCategory(null);
+ refreshViewer();
}
}
};
@@ -256,23 +213,21 @@
newXPathAction = new Action() {
public void run() {
- SimpleTreeItem tree = getRoot();
- Object o = getActiveCategory();
- if( o != null && o instanceof SimpleXPathPreferenceTreeItem) {
- String category = (String) ((SimpleXPathPreferenceTreeItem)o).getData();
- XPathDialog d = new XPathDialog(Display.getCurrent().getActiveShell(), jbServer,
category);
+ XPathCategory category = getActiveCategory();
+ if( category != null ) {
+ String categoryName = category.getName();
+ XPathDialog d = new XPathDialog(Display.getCurrent().getActiveShell(), jbServer,
categoryName);
if( d.open() == Window.OK ) {
- SimpleTreeItem[] categories = tree.getChildren();
- SimpleTreeItem categoryItem = null;
- for( int i = 0; i < categories.length; i++ ) {
- if( categories[i].getData().equals(category))
- categoryItem = categories[i];
+ XPathCategory[] categoryList = XPathModel.getDefault().getCategories(jbServer);
+ XPathCategory categoryItem = null;
+ for( int i = 0; i < categoryList.length; i++ ) {
+ if( categoryList[i].getName().equals(category.getName()))
+ categoryItem = categoryList[i];
}
if( categoryItem != null ) {
- XPathPreferenceTreeItem dsfa = new XPathPreferenceTreeItem(categoryItem,
d.getName(), d.getXpath(), d.getAttribute());
- ServerAttributeHelper helper = jbServer.getAttributeHelper();
- helper.saveXPathPreferenceTree(getRoot());
- helper.save();
+ XPathQuery query = new XPathQuery(d.getName(), jbServer.getConfigDirectory(),
null, d.getXpath(), d.getAttribute());
+ categoryItem.addQuery(query);
+ XPathModel.getDefault().save(jbServer);
refreshViewer();
}
}
@@ -284,22 +239,20 @@
editXPathAction = new Action() {
public void run() {
Object o = getPropertySelection();
- if( o != null && o instanceof XPathPreferenceTreeItem) {
- XPathPreferenceTreeItem original = (XPathPreferenceTreeItem)o;
- String category = (String) original.getParent().getData();
+ if( o != null && o instanceof XPathQuery) {
+ XPathQuery original = (XPathQuery)o;
+ XPathCategory category = original.getCategory();
XPathDialog d = new XPathDialog(Display.getCurrent().getActiveShell(),
- jbServer, category, original.getName());
- d.setAttribute(original.getAttributeName());
- d.setXpath(original.getXPath());
+ jbServer, category.getName(), original.getName());
+ d.setAttribute(original.getAttribute());
+ d.setXpath(original.getXpathPattern());
if( d.open() == Window.OK ) {
- original.setAttributeName(d.getAttribute());
- original.setXPath(d.getXpath());
+ original.setAttribute(d.getAttribute());
+ original.setXpathPattern(d.getXpath());
original.setName(d.getName());
- ServerAttributeHelper helper = jbServer.getAttributeHelper();
- helper.saveXPathPreferenceTree(getRoot());
- helper.save();
+ category.save();
refreshViewer();
}
}
@@ -310,11 +263,10 @@
deleteXPathAction = new Action() {
public void run() {
Object o = getPropertySelection();
- if( o instanceof XPathPreferenceTreeItem ) {
- ((XPathPreferenceTreeItem)o).getParent().deleteChild((XPathPreferenceTreeItem)o);
- ServerAttributeHelper helper = jbServer.getAttributeHelper();
- helper.saveXPathPreferenceTree(getRoot());
- helper.save();
+ if( o instanceof XPathQuery ) {
+ XPathCategory cat = ((XPathQuery)o).getCategory();
+ cat.removeQuery((XPathQuery)o);
+ cat.save();
refreshViewer();
}
}
@@ -325,20 +277,27 @@
public void run() {
try {
Object o = getPropertySelection();
- File file = ((XPathTreeItem)o).getFile();
- IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(file.getAbsolutePath()));
-
- IWorkbench wb = PlatformUI.getWorkbench();
- IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
- IWorkbenchPage page = win.getActivePage();
-// IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(file);
-
- if( eclipseFile != null ) {
- IEditorInput input = new FileEditorInput(eclipseFile);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(file.getName());
- page.openEditor(input, desc.getId());
+ Path p = null;
+ if( o instanceof XPathFileResult ) {
+ p = new Path(((XPathFileResult)o).getFileLocation());
+ } else if( o instanceof XPathResultNode ) {
+ p = new Path(((XPathResultNode)o).getFileLocation());
}
+ if( p != null ) {
+
+
+ IFileStore fileStore =
EFS.getLocalFileSystem().getStore(p.removeLastSegments(1));
+ fileStore = fileStore.getChild(p.lastSegment());
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+
+ if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists())
{
+ try {
+ IDE.openEditorOnFileStore(page, fileStore);
+ } catch (PartInitException e) {}
+ }
+ }
} catch( Exception exc ) {
}
}
@@ -353,734 +312,34 @@
return;
}
- if( selection instanceof SimpleXPathPreferenceTreeItem ) {
- setActiveCategory(((SimpleXPathPreferenceTreeItem)selection));
- menu.add(this.newXPathAction);
- menu.add(this.deleteXPathCategoryAction);
- menu.add(new Separator());
+ if( selection instanceof XPathCategory ) {
+ try {
+ setActiveCategory((XPathCategory)selection);
+ menu.add(this.newXPathAction);
+ menu.add(this.deleteXPathCategoryAction);
+ menu.add(new Separator());
+ } catch( Exception e ) { e.printStackTrace(); }
}
}
-
- // Preference Page
- public ViewProviderPreferenceComposite createPreferenceComposite(Composite parent) {
- return null; // new DescriptorPreferencePage(parent);
- }
-
- public class DescriptorPreferencePage extends ViewProviderPreferenceComposite {
-
- private Combo portsCategoryCombo;
- private Combo serversCombo;
-
- private JBossServer[] servers;
-
- private HashMap serverToCategoryList;
- private HashMap serverToDefaultPortCat;
- private HashMap serverToAttributeHelper;
-
- public DescriptorPreferencePage(Composite parent) {
- super(parent, SWT.NONE);
- setLayout(new FormLayout());
-
- serverToCategoryList = new HashMap();
- serverToDefaultPortCat = new HashMap();
- serverToAttributeHelper = new HashMap();
-
-
-
- Composite defaultPortComp = new Composite(this, SWT.BORDER);
- FormData portData = new FormData();
- portData.left = new FormAttachment(0,5);
- portData.top = new FormAttachment(0,5);
- portData.right = new FormAttachment(50,-5);
- defaultPortComp.setLayoutData(portData);
- fillPortPreferences(defaultPortComp);
- }
-
- private ServerAttributeHelper getAttributeHelper(JBossServer server) {
- Object helper = serverToAttributeHelper.get(server);
- if( helper == null ) {
- helper = server.getAttributeHelper();
- serverToAttributeHelper.put(server, helper);
- }
- return (ServerAttributeHelper)helper;
- }
-
- protected void fillPortPreferences(Composite portComp) {
- portComp.setLayout(new RowLayout(SWT.VERTICAL));
-
- servers = ServerConverter.getAllJBossServers();
- String[] serverNames = new String[servers.length];
- for( int i = 0; i < servers.length; i++ )
- serverNames[i] = servers[i].getServer().getName();
-
- portComp.setLayout(new RowLayout(SWT.VERTICAL));
-
- Label nameLabel = new Label(portComp, SWT.NONE);
- nameLabel.setText(Messages.DescriptorXPathServerName);
-
- serversCombo = new Combo(portComp, SWT.READ_ONLY);
- serversCombo.setItems(serverNames);
-
- Label categoryLabel = new Label(portComp, SWT.NONE);
- categoryLabel.setText(Messages.DescriptorXPathPortCategory);
-
- portsCategoryCombo = new Combo(portComp, SWT.READ_ONLY);
-
-
- serversCombo.addSelectionListener(new SelectionListener() {
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- public void widgetSelected(SelectionEvent e) {
- serverComboChanged();
- }
- });
-
- portsCategoryCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- JBossServer server = getSelectedServer();
- if( server != null ) {
- int index = portsCategoryCombo.getSelectionIndex();
- String selectedCategory = portsCategoryCombo.getItem(index);
- serverToDefaultPortCat.put(server, selectedCategory);
- }
- }
-
- } );
- }
- private void serverComboChanged() {
- JBossServer s = getSelectedServer();
- if( s != null ) {
- Object o = serverToCategoryList.get(s);
- ArrayList list;
- if( o == null ) {
- ServerAttributeHelper helper = getAttributeHelper(s);
- SimpleXPathPreferenceTreeItem tree = helper.getXPathPreferenceTree();
- SimpleTreeItem[] children = tree.getChildren();
- String[] categoryNames = new String[children.length];
- for( int i = 0; i < children.length; i++ ) {
- categoryNames[i] = (String)children[i].getData();
- }
- list = new ArrayList();
- list.addAll(Arrays.asList(categoryNames));
- String portDir = helper.getDefaultPortCategoryName();
- serverToDefaultPortCat.put(s, portDir);
- serverToCategoryList.put(s, list);
- } else {
- list = (ArrayList)o;
- }
- portsCategoryCombo.setItems((String[]) list
- .toArray(new String[list.size()]));
-
- String portDir = (String)serverToDefaultPortCat.get(s);
- if( portDir != null ) {
- int index2 = portsCategoryCombo.indexOf(portDir);
- portsCategoryCombo.select(index2);
- }
- }
- }
- private JBossServer getSelectedServer() {
- int index = serversCombo.getSelectionIndex();
- String selected = serversCombo.getItem(index);
- if( selected == null ) return null;
-
- for( int i = 0; i < servers.length; i++ ) {
- if( servers[i].getServer().getName().equals(selected)) {
- return servers[i];
- }
- }
- return null;
- }
-
-
- public boolean isValid() {
- return true;
- }
- public boolean performCancel() {
- return true;
- }
- public boolean performOk() {
- // now save default port categories
- ServerAttributeHelper helper;
- for( int i = 0; i < servers.length; i++ ) {
- helper = (ServerAttributeHelper)serverToAttributeHelper.get(servers[i]);
- String category = (String)serverToDefaultPortCat.get(servers[i]);
- if( category != null ) {
- helper.setDefaultPortCategoryName(category);
- helper.save();
- }
- }
- return true;
- }
- public void dispose() {
- super.dispose();
- }
- }
-
-
-
-
// Property Sheet Page
public IPropertySheetPage getPropertySheetPage() {
if( propertyPage == null ) {
- propertyPage = new DescriptorXPathPropertySheetPage();
+ propertyPage = new DescriptorXPathPropertySheetPage(this);
}
return propertyPage;
}
- public class DescriptorXPathPropertySheetPage implements IPropertySheetPage {
- private TreeViewer xpathTreeViewer;
- private TreeColumn column, column2;//, column3;
- private Tree xpathTree;
- private XPathPropertyLabelProvider labelProvider;
-
- private Group xPathGroup;
-
- public void createControl(Composite parent) {
- createXPathGroup(parent);
- addViewerMenus();
- }
-
- public XPathPropertyLabelProvider getLabelProvider() {
- if( labelProvider == null ) {
- labelProvider = new XPathPropertyLabelProvider();
- }
- return labelProvider;
- }
-
- private void addViewerMenus() {
- MenuManager menuManager = new MenuManager("#PopupMenu");
- menuManager.setRemoveAllWhenShown(true);
- final Shell shell = xpathTree.getShell();
- menuManager.addMenuListener(new IMenuListener() {
- public void menuAboutToShow(IMenuManager mgr) {
- xpathTreeMenuAboutToShow(shell, mgr);
- }
- });
- Menu menu = menuManager.createContextMenu(xpathTree);
- xpathTree.setMenu(menu);
- }
-
- private void xpathTreeMenuAboutToShow(Shell shell, IMenuManager menu) {
- menu.add(newXPathAction);
- if( getPropertySelection() != null && getPropertySelection() instanceof
XPathPreferenceTreeItem) {
- menu.add(editXPathAction);
- menu.add(deleteXPathAction);
- }
- if( getPropertySelection() != null && getPropertySelection() instanceof
XPathTreeItem
- && ((XPathTreeItem)getPropertySelection()).getFile() != null ) {
- menu.add(editFileAction);
- }
- }
-
-
- public void dispose() {
- }
-
- public Control getControl() {
- return xPathGroup;
- }
-
- public void setActionBars(IActionBars actionBars) {
- }
-
- public void setFocus() {
- }
-
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- //input = null;
- Object element = ((IStructuredSelection)selection).getFirstElement();
- if( element instanceof ContentWrapper ) {
- element = ((ContentWrapper)element).getElement();
- }
- if( element != null && element != getActiveCategory()) {
- setActiveCategory(element);
- forceDescriptorRefresh(element);
- }
- }
-
- protected void forceDescriptorRefresh(final Object element) {
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- final IProgressMonitor monitor2 = monitor;
- jbServer.getDescriptorModel().refreshDescriptors(monitor2);
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- xpathTreeViewer.setInput(element);
- xpathTreeViewer.expandToLevel(2);
- //jbServer.getAttributeHelper().setServerPorts(root);
- }
- });
- }
- };
- try {
- new ProgressMonitorDialog(new Shell()).run(false, true, op);
- } catch( Exception e) {
- e.printStackTrace();
- }
- }
-
- protected class XPathTreeLabelProvider implements ITableLabelProvider {
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
- public String getColumnText(Object element, int columnIndex) {
- if( element instanceof XPathTreeItem ) {
- Object data = ((XPathTreeItem)element).getData();
- if( data instanceof File) {
- if( columnIndex == 0 ) {
- return ((File)data).getName();
- }
- if( columnIndex == 1 && ((XPathTreeItem)element).getChildren().length == 1
) {
- element = ((XPathTreeItem)element).getChildren()[0];
- }
- }
- }
-
- if( element instanceof XPathPreferenceTreeItem) {
- if( columnIndex == 0 ) return
((XPathPreferenceTreeItem)element).getName().toString();
- if( columnIndex == 1 ) {
- Object o = ((XPathPreferenceTreeItem)element).getProperty(XPATH_PROPERTY);
- return o == null ? "" : o.toString();
- }
- }
- if( element instanceof SimpleXPathPreferenceTreeItem ) {
- if( columnIndex == 0 )
- return ((SimpleXPathPreferenceTreeItem)element).getData().toString();
- }
- return "";
- }
- public void addListener(ILabelProviderListener listener) {
- }
- public void dispose() {
- }
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
- public void removeListener(ILabelProviderListener listener) {
- }
- }
- protected class XPathTreeSelectionListener implements Listener {
-
- private final Color black;
- private final TreeItem[] lastItem;
- private final TreeEditor editor;
- private int mouseX;
-
- public XPathTreeSelectionListener() {
- black = Display.getCurrent().getSystemColor (SWT.COLOR_BLACK);
- lastItem = new TreeItem [1];
- editor = new TreeEditor (xpathTree);
- mouseX = 0;
- }
-
-
- private boolean canEditLocationColumn(TreeItem item) {
- if( item == null || item != lastItem[0] ) return false;
- return false;
- }
-
- private boolean canEditAttributeColumn(TreeItem item) {
- // if we're the "JNDI" line then we're editing the xpath's
attribute name (code, name, etc)
- if( item.getData() instanceof XPathPreferenceTreeItem ) {
- return false;
- }
-
- // if we're a file entry under "JNDI", and have multiple matches, no
editing on this line
- if( item.getData() instanceof XPathTreeItem &&
((XPathTreeItem)item.getData()).getChildren().length > 1 ) return false;
-
- return true;
- }
-
- private boolean canEditValueColumn(TreeItem item) {
- return false;
- }
-
- private int getColumnToEdit(TreeItem item) {
- boolean locColumn = canEditLocationColumn(item);
- boolean attributeColumn = canEditAttributeColumn(item);
- boolean valueColumn = canEditValueColumn(item);
- int total = 0;
- if( locColumn ) total++;
- if(attributeColumn) total++;
- if(valueColumn) total++;
-
- if( total == 0 ) return -1;
- if( total == 1 ) {
- if( locColumn ) return 0;
- if(attributeColumn) return 1;
- if( valueColumn) return 2;
- }
-
- // we CAN edit more than one. Where's the mouse?
- if( mouseX < column.getWidth() && locColumn ) return 0;
- if( mouseX < (column.getWidth() + column2.getWidth()) && valueColumn )
return 1;
- return 2;
- }
-
-
- public void handleEvent (Event event) {
- TreeItem[] selectedItems = xpathTree.getSelection();
- if( selectedItems.length != 1 ) return;
-
- final TreeItem item = selectedItems[0];
-
- final int column = getColumnToEdit(item);
-
- if( column == -1 ) {
- lastItem[0] = item;
- return;
- }
-
- boolean isCarbon = SWT.getPlatform ().equals ("carbon");
- final Composite composite = new Composite (xpathTree, SWT.NONE);
- if (!isCarbon) composite.setBackground (black);
- final Text text = new Text (composite, SWT.NONE);
- final int inset = isCarbon ? 0 : 1;
- composite.addListener (SWT.Resize, new Listener () {
- public void handleEvent (Event e) {
- Rectangle rect = composite.getClientArea ();
- text.setBounds (rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height
- inset * 2);
- }
- });
- Listener textListener = new Listener () {
- public void handleEvent (final Event e) {
- switch (e.type) {
- case SWT.FocusOut:
- treeviewerEditorTextChanged(item, text, column);
- composite.dispose ();
- break;
- case SWT.Verify:
- String newText = text.getText();
- String leftText = newText.substring (0, e.start);
- String rightText = newText.substring (e.end, newText.length ());
- GC gc = new GC (text);
- Point size = gc.textExtent (leftText + e.text + rightText);
- gc.dispose ();
- size = text.computeSize (size.x, SWT.DEFAULT);
- editor.horizontalAlignment = SWT.LEFT;
- Rectangle itemRect = item.getBounds (), rect = xpathTree.getClientArea ();
- editor.minimumWidth = Math.max (size.x, itemRect.width) + inset * 2;
- int left = itemRect.x, right = rect.x + rect.width;
- editor.minimumWidth = Math.min (editor.minimumWidth, right - left);
- editor.minimumHeight = size.y + inset * 2;
- editor.setColumn(column);
- editor.layout ();
- break;
- case SWT.Traverse:
- switch (e.detail) {
- case SWT.TRAVERSE_RETURN:
- treeviewerEditorTextChanged(item, text, column);
- //FALL THROUGH
- case SWT.TRAVERSE_ESCAPE:
- composite.dispose ();
- e.doit = false;
- }
- break;
- }
- }
- };
- text.addListener (SWT.FocusOut, textListener);
- text.addListener (SWT.Traverse, textListener);
- text.addListener (SWT.Verify, textListener);
- editor.setEditor (composite, item);
- text.setText (item.getText(column));
- text.selectAll ();
- text.setFocus ();
-
- lastItem [0] = item;
- }
-
- public int getMouseX() {
- return mouseX;
- }
-
- public void setMouseX(int mouseX) {
- this.mouseX = mouseX;
- }
- }
-
- protected void createXPathGroup(Composite main) {
- xPathGroup = new Group(main, SWT.NONE);
-
- xPathGroup.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- }
- } );
-
- int groupWidth = 500;
-
- xPathGroup.setText(Messages.DescriptorXPathDescriptorValues);
- FormData groupData = new FormData();
- groupData.right = new FormAttachment(100, -5);
- groupData.left = new FormAttachment(0, 5);
- groupData.top = new FormAttachment(0,5);
- groupData.bottom = new FormAttachment(100, -5);
- xPathGroup.setLayoutData(groupData);
-
- xPathGroup.setLayout(new FormLayout());
-
-
- final Tree xpathTree = new Tree(xPathGroup, SWT.BORDER | SWT.FULL_SELECTION);
- this.xpathTree = xpathTree;
-
- column = new TreeColumn(xpathTree, SWT.NONE);
- column2 = new TreeColumn(xpathTree, SWT.NONE);
-// column3 = new TreeColumn(xpathTree, SWT.NONE);
-
- column.setText(Messages.DescriptorXPathNameLocation);
- column2.setText(Messages.DescriptorXPathAttributeValue);
-// column3.setText(Messages.DescriptorXPathXPathXML);
-
- column.setWidth(groupWidth * 10 / 20);
- column2.setWidth(groupWidth * 10 / 20);
-// column3.setWidth(groupWidth * 7 / 20);
-
-
- FormData treeData = new FormData();
- treeData.left = new FormAttachment(0,5);
- treeData.right = new FormAttachment(100, -5);
- treeData.top = new FormAttachment(0,5);
- treeData.bottom = new FormAttachment(100, -5);
- xpathTree.setLayoutData(treeData);
-
- xpathTree.setHeaderVisible(true);
- xpathTree.setLinesVisible(true);
-
-
- xpathTreeViewer = new TreeViewer(xpathTree);
- xpathTreeViewer.setContentProvider(new XPathPropertyContentProvider());
- labelProvider = getLabelProvider();
- labelProvider.setSimple(true);
- xpathTreeViewer.setLabelProvider(labelProvider);
-
- final XPathTreeSelectionListener selListener = new XPathTreeSelectionListener();
- xpathTree.addListener (SWT.MouseDoubleClick, selListener);
- xpathTree.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( xpathTree.getSelection().length == 1 ) {
- Object sel = xpathTree.getSelection()[0].getData();
- setPropertySelection(sel);
- }
- }
- });
-
- // alerts the top listener as to the mouse position, to know which column is
serverViewerSelection
- xpathTree.addListener(SWT.MouseMove, new Listener() {
- public void handleEvent(Event event) {
- selListener.setMouseX(event.x);
- }
- });
- }
-
- private void treeviewerEditorTextChanged(TreeItem item, Text text, int column) {
- if( column == 0 ) {
- xpathTextKeyChanged(item, text);
- } else if( column == 1 ) {
- xpathTextValueChanged(item, text);
- } else if( column == 2 ) {
- // TODO add to own method
- if( item.getData() instanceof XPathPreferenceTreeItem ) {
- String xp = ((XPathPreferenceTreeItem)item.getData()).getXPath();
- if( !xp.equals(text.getText())) {
- ((XPathPreferenceTreeItem)item.getData()).setXPath(text.getText());
- xpathTreeViewer.refresh();
- }
- }
-
- }
- }
-
- private void xpathTextValueChanged(TreeItem item, Text text) {
- if( text.isDisposed() || item.isDisposed()) return;
-
- // xpath changed entirely
- if( item.getData() instanceof XPathPreferenceTreeItem ) {
- String att = ((XPathPreferenceTreeItem)item.getData()).getAttributeName();
- if( att != null && !att.equals(text.getText())) {
- ((XPathPreferenceTreeItem)item.getData()).setAttributeName(text.getText());
- xpathTreeViewer.refresh();
- }
- return;
- }
-
-
- // we're changing the value in the actual descriptor.
- XPathTreeItem2 itemToChange = getChangedNode(item.getData());
- if( itemToChange != null && itemToChange instanceof XPathTreeItem2 ) {
-
- // if its unchanged do nothing
- if( ((XPathTreeItem2)itemToChange).getText().equals(text.getText())) {
- return;
- }
-
- // set the text and add the document to the list of dirty ones
- ((XPathTreeItem2)itemToChange).setText(text.getText());
- if( itemToChange.getDocument() != null ) {
- itemToChange.saveDescriptor();
- }
- xpathTreeViewer.refresh(item.getData());
- }
- }
-
- private void xpathTextKeyChanged(TreeItem item, Text text) {
- // "JNDI"
- if( text.isDisposed() || item.isDisposed()) return;
-
- if( item.getData() instanceof XPathPreferenceTreeItem ) {
-
- SimpleXPathPreferenceTreeItem parentItem =
(SimpleXPathPreferenceTreeItem)((SimpleXPathPreferenceTreeItem)item.getData()).getParent();
- SimpleTreeItem[] kids = parentItem.getChildren();
-
- boolean valid = true;
- String textString = text.getText();
- for( int i = 0; i < kids.length; i++ ) {
- if( textString.equals(((XPathPreferenceTreeItem)kids[i]).getName()))
- valid = false;
- }
-
- if( valid ) {
- ((XPathPreferenceTreeItem)item.getData()).setName(text.getText());
- ServerAttributeHelper helper = jbServer.getAttributeHelper();
- helper.saveXPathPreferenceTree(parentItem.getParent());
- helper.save();
- xpathTreeViewer.refresh();
- }
- return;
- }
- }
-
- private XPathTreeItem2 getChangedNode(Object data) {
- // if we are the node to change, change me
- if( data instanceof XPathTreeItem2 ) {
- return (XPathTreeItem2)data;
- }
-
- // if we're a node which represents a file, but only have one matched node, thats
the node.
- if( data instanceof XPathTreeItem &&
((XPathTreeItem)data).getChildren().length == 1 ) {
- return (XPathTreeItem2) (((XPathTreeItem)data).getChildren()[0]);
- }
-
- // if we're a top level tree item (JNDI), with one file child and one mbean
grandchild, the grandchild is the node
- if( data instanceof XPathPreferenceTreeItem &&
((XPathPreferenceTreeItem)data).getChildren().length == 1 ) {
- XPathTreeItem item = ((XPathTreeItem)
((XPathPreferenceTreeItem)data).getChildren()[0]);
- if( item.getChildren().length == 1 )
- return (XPathTreeItem2)item.getChildren()[0];
- }
- return null;
- }
- }
-
- public static class XPathPropertyLabelProvider extends LabelProvider implements
ITableLabelProvider {
-
- private boolean simple = false;
- public void setSimple(boolean val) {
- simple = val;
- }
-
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
- public String getColumnText(Object element, int columnIndex) {
- if( element instanceof XPathTreeItem ) {
- Object data = ((XPathTreeItem)element).getData();
- if( data instanceof File) {
- if( columnIndex == 0 ) {
- return ((File)data).getName();
- }
- if( ((XPathTreeItem)element).getChildren().length == 1 ) {
- element = ((XPathTreeItem)element).getChildren()[0];
- }
- }
- }
-
- if( element instanceof XPathTreeItem2) {
- XPathTreeItem2 element2 = (XPathTreeItem2)element;
- if( columnIndex == 0 ) return Messages.DescriptorXPathMatch + element2.getIndex();
- if( columnIndex == 1 ) return element2.getText();
- if( columnIndex == 2 && !simple) return element2.elementAsXML();
- }
-
- if( element instanceof XPathPreferenceTreeItem) {
- if( columnIndex == 0 ) return
((XPathPreferenceTreeItem)element).getName().toString();
- if( columnIndex == 1 && !simple) return
((XPathPreferenceTreeItem)element).getAttributeName();
- if( columnIndex == 2 && !simple) return
((XPathPreferenceTreeItem)element).getXPath();
- }
- if( element instanceof SimpleXPathPreferenceTreeItem ) {
- if( columnIndex == 0 )
- return ((SimpleXPathPreferenceTreeItem)element).getData().toString();
- }
- return "";
- }
- }
-
-
protected void refreshViewer() {
if( isEnabled() ) {
try {
super.refreshViewer();
if( propertyPage != null ) {
- propertyPage.xpathTreeViewer.refresh();
+ propertyPage.getViewer().refresh();
}
} catch(Exception e) {
}
}
}
-
- protected class XPathPropertyContentProvider implements ITreeContentProvider {
- public Object[] getChildren(Object parentElement) {
- // we're a leaf
- if( parentElement instanceof XPathTreeItem2 )
- return new Object[0];
-
- // we're a file node (blah.xml)
- if( parentElement instanceof XPathTreeItem ) {
- if( ((XPathTreeItem)parentElement).getChildren().length > 1 )
- return ((XPathTreeItem)parentElement).getChildren();
- return new Object[0];
- }
-
- // we're the named element (JNDI)
- if( parentElement instanceof XPathPreferenceTreeItem ) {
- SimpleTreeItem[] kids = ((XPathPreferenceTreeItem)parentElement).getChildren();
- return kids;
- }
-
- // re-creates it from scratch... hrmm
- if( parentElement instanceof ServerViewProvider )
- return jbServer.getAttributeHelper().getXPathPreferenceTree().getChildren();
- return new Object[0];
- }
- public Object getParent(Object element) {
- return null;
- }
- public boolean hasChildren(Object element) {
- return getChildren(element).length > 0 ? true : false;
- }
- public Object[] getElements(Object inputElement) {
- if( inputElement instanceof SimpleXPathPreferenceTreeItem ) {
- SimpleTreeItem[] items =
((SimpleXPathPreferenceTreeItem)inputElement).getChildren();
- for( int i = 0; i < items.length; i++ )
- ensureLoaded((SimpleXPathPreferenceTreeItem)items[i]);
- return items;
- }
- return new Object[0];
- }
- public void ensureLoaded(SimpleXPathPreferenceTreeItem item) {
- if( item instanceof XPathPreferenceTreeItem ) {
- ((XPathPreferenceTreeItem)item).ensureLoaded(jbServer);
- }
- }
- public void dispose() {
- }
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- }
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/DescriptorXPathPropertySheetPage.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/DescriptorXPathPropertySheetPage.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/DescriptorXPathPropertySheetPage.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -0,0 +1,406 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.descriptors;
+
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TreeEditor;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathCategory;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult.XPathResultNode;
+import org.jboss.ide.eclipse.as.ui.Messages;
+import org.jboss.ide.eclipse.as.ui.views.server.ExtensionTableViewer.ContentWrapper;
+import org.jboss.ide.eclipse.as.ui.views.server.providers.DescriptorXPathViewProvider;
+
+public class DescriptorXPathPropertySheetPage implements IPropertySheetPage {
+ private TreeViewer xpathTreeViewer;
+ private TreeColumn column, column2;//, column3;
+ private Tree xpathTree;
+ private XPathPropertyLabelProvider labelProvider;
+ private DescriptorXPathViewProvider provider;
+ private Composite loading, wrapper;
+ private PageBook book;
+
+ public DescriptorXPathPropertySheetPage(DescriptorXPathViewProvider provider) {
+ this.provider = provider;
+ }
+
+ public TreeViewer getViewer() { return xpathTreeViewer; }
+
+ public void createControl(Composite parent) {
+ book = new PageBook(parent, SWT.NONE);
+
+ createLoadingComposite(book);
+ createXPathComposite(book);
+ addViewerMenus();
+ }
+
+ public XPathPropertyLabelProvider getLabelProvider() {
+ if( labelProvider == null ) {
+ labelProvider = new XPathPropertyLabelProvider();
+ }
+ return labelProvider;
+ }
+
+ private void addViewerMenus() {
+ MenuManager menuManager = new MenuManager("#PopupMenu");
+ menuManager.setRemoveAllWhenShown(true);
+ final Shell shell = xpathTree.getShell();
+ menuManager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager mgr) {
+ xpathTreeMenuAboutToShow(shell, mgr);
+ }
+ });
+ Menu menu = menuManager.createContextMenu(xpathTree);
+ xpathTree.setMenu(menu);
+ }
+
+ private void xpathTreeMenuAboutToShow(Shell shell, IMenuManager menu) {
+ Object selected = provider.getPropertySelection();
+ menu.add(provider.newXPathAction);
+ if( selected != null && selected instanceof XPathQuery) {
+ menu.add(provider.editXPathAction);
+ menu.add(provider.deleteXPathAction);
+ }
+ if( selected != null &&
+ (selected instanceof XPathResultNode || selected instanceof XPathFileResult ))
+ menu.add(provider.editFileAction);
+ }
+
+
+ public void dispose() {
+ }
+
+ public Control getControl() {
+ return book;
+ }
+
+ public void setActionBars(IActionBars actionBars) {
+ }
+
+ public void setFocus() {
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ //input = null;
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ if( element instanceof ContentWrapper ) {
+ element = ((ContentWrapper)element).getElement();
+ }
+ if( element != null //)&& element != provider.getActiveCategory()
+ && element instanceof XPathCategory) {
+ // show loading
+ book.showPage(loading);
+ final XPathCategory cat = (XPathCategory)element;
+ new Thread() {
+ public void run() {
+ // force load everything
+ forceLoad(cat);
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ // do this stuff async
+ book.showPage(wrapper);
+ provider.setActiveCategory((XPathCategory)cat);
+ xpathTreeViewer.setInput(cat);
+ xpathTreeViewer.expandToLevel(2);
+ }
+ });
+ }
+ }.start();
+ }
+ }
+
+ protected void forceLoad(XPathCategory cat) {
+ XPathQuery[] queries = cat.getQueries();
+ XPathFileResult[] results;
+ for( int i = 0; i < queries.length; i++ ) {
+ results = queries[i].getResults();
+ for( int j = 0; j < results.length; j++ ) {
+ results[j].getChildren();
+ }
+ }
+ }
+
+ protected class XPathTreeSelectionListener implements Listener {
+
+ private final Color black;
+ private final TreeItem[] lastItem;
+ private final TreeEditor editor;
+ private int mouseX;
+
+ public XPathTreeSelectionListener() {
+ black = Display.getCurrent().getSystemColor (SWT.COLOR_BLACK);
+ lastItem = new TreeItem [1];
+ editor = new TreeEditor (xpathTree);
+ mouseX = 0;
+ }
+
+
+ public int countResultNodes(XPathQuery query) {
+ int count = 0;
+ XPathFileResult[] files = query.getResults();
+ for( int i = 0; i < files.length; i++ ) {
+ count += files[i].getChildren().length;
+ }
+ return count;
+ }
+
+ // can not modify name or location
+ private boolean canEditLocationColumn(TreeItem item) {
+ return false;
+ }
+
+ // can only modify value under certain circumstances
+ private boolean canEditValueColumn(TreeItem item) {
+ Object o = item.getData();
+ if( o instanceof XPathQuery && countResultNodes((XPathQuery)o) == 1 )
+ return true;
+ if( o instanceof XPathFileResult && ((XPathFileResult)o).getChildren().length
== 1 )
+ return true;
+ if( o instanceof XPathResultNode ) return true;
+ return false;
+ }
+
+ private int getColumnToEdit(TreeItem item) {
+ boolean locColumn = canEditLocationColumn(item);
+ boolean valueColumn = canEditValueColumn(item);
+ int total = 0;
+ if( locColumn ) total++;
+ if(valueColumn) total++;
+
+ if( total == 0 ) return -1;
+ if( total == 1 ) {
+ if( locColumn ) return 0;
+ if( valueColumn) return 1;
+ }
+
+ // we CAN edit more than one. Where's the mouse?
+ if( mouseX < column.getWidth() && locColumn ) return 0;
+ if( mouseX < (column.getWidth() + column2.getWidth()) && valueColumn )
return 1;
+ return 2;
+ }
+
+
+ public void handleEvent (Event event) {
+ TreeItem[] selectedItems = xpathTree.getSelection();
+ if( selectedItems.length != 1 ) return;
+
+ final TreeItem item = selectedItems[0];
+
+ final int column = getColumnToEdit(item);
+
+ if( column == -1 ) {
+ lastItem[0] = item;
+ return;
+ }
+
+ boolean isCarbon = SWT.getPlatform ().equals ("carbon");
+ final Composite composite = new Composite (xpathTree, SWT.NONE);
+ if (!isCarbon) composite.setBackground (black);
+ final Text text = new Text (composite, SWT.NONE);
+ final int inset = isCarbon ? 0 : 1;
+ composite.addListener (SWT.Resize, new Listener () {
+ public void handleEvent (Event e) {
+ Rectangle rect = composite.getClientArea ();
+ text.setBounds (rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height
- inset * 2);
+ }
+ });
+ Listener textListener = new Listener () {
+ public void handleEvent (final Event e) {
+ switch (e.type) {
+ case SWT.FocusOut:
+ treeviewerEditorTextChanged(item, text, column);
+ composite.dispose ();
+ break;
+ case SWT.Verify:
+ String newText = text.getText();
+ String leftText = newText.substring (0, e.start);
+ String rightText = newText.substring (e.end, newText.length ());
+ GC gc = new GC (text);
+ Point size = gc.textExtent (leftText + e.text + rightText);
+ gc.dispose ();
+ size = text.computeSize (size.x, SWT.DEFAULT);
+ editor.horizontalAlignment = SWT.LEFT;
+ Rectangle itemRect = item.getBounds (), rect = xpathTree.getClientArea ();
+ editor.minimumWidth = Math.max (size.x, itemRect.width) + inset * 2;
+ int left = itemRect.x, right = rect.x + rect.width;
+ editor.minimumWidth = Math.min (editor.minimumWidth, right - left);
+ editor.minimumHeight = size.y + inset * 2;
+ editor.setColumn(column);
+ editor.layout ();
+ break;
+ case SWT.Traverse:
+ switch (e.detail) {
+ case SWT.TRAVERSE_RETURN:
+ treeviewerEditorTextChanged(item, text, column);
+ //FALL THROUGH
+ case SWT.TRAVERSE_ESCAPE:
+ composite.dispose ();
+ e.doit = false;
+ }
+ break;
+ }
+ }
+ };
+ text.addListener (SWT.FocusOut, textListener);
+ text.addListener (SWT.Traverse, textListener);
+ text.addListener (SWT.Verify, textListener);
+ editor.setEditor (composite, item);
+ text.setText (item.getText(column));
+ text.selectAll ();
+ text.setFocus ();
+
+ lastItem [0] = item;
+ }
+
+ public int getMouseX() {
+ return mouseX;
+ }
+
+ public void setMouseX(int mouseX) {
+ this.mouseX = mouseX;
+ }
+ }
+
+ protected void createLoadingComposite(Composite book) {
+ loading = new Composite(book, SWT.NONE);
+ loading.setLayout(new FillLayout());
+ Label load = new Label(loading, SWT.NONE);
+ load.setText("Loading");
+ }
+
+ protected void createXPathComposite(Composite book) {
+ wrapper = new Composite(book, SWT.NONE);
+ int groupWidth = 500;
+
+ FormData groupData = new FormData();
+ groupData.right = new FormAttachment(100, -5);
+ groupData.left = new FormAttachment(0, 5);
+ groupData.top = new FormAttachment(0,5);
+ groupData.bottom = new FormAttachment(100, -5);
+ wrapper.setLayoutData(groupData);
+ wrapper.setLayout(new FormLayout());
+
+ final Tree xpathTree = new Tree(wrapper, SWT.BORDER | SWT.FULL_SELECTION);
+ this.xpathTree = xpathTree;
+
+ column = new TreeColumn(xpathTree, SWT.NONE);
+ column2 = new TreeColumn(xpathTree, SWT.NONE);
+
+ column.setText(Messages.DescriptorXPathNameLocation);
+ column2.setText(Messages.DescriptorXPathAttributeValue);
+
+ column.setWidth(groupWidth * 10 / 20);
+ column2.setWidth(groupWidth * 10 / 20);
+
+ FormData treeData = new FormData();
+ treeData.left = new FormAttachment(0,5);
+ treeData.right = new FormAttachment(100, -5);
+ treeData.top = new FormAttachment(0,5);
+ treeData.bottom = new FormAttachment(100, -5);
+ xpathTree.setLayoutData(treeData);
+
+ xpathTree.setHeaderVisible(true);
+ xpathTree.setLinesVisible(true);
+
+
+ xpathTreeViewer = new TreeViewer(xpathTree);
+ xpathTreeViewer.setContentProvider(new XPathPropertyContentProvider());
+ labelProvider = getLabelProvider();
+ xpathTreeViewer.setLabelProvider(labelProvider);
+
+ final XPathTreeSelectionListener selListener = new XPathTreeSelectionListener();
+ xpathTree.addListener (SWT.MouseDoubleClick, selListener);
+ xpathTree.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if( xpathTree.getSelection().length == 1 ) {
+ Object sel = xpathTree.getSelection()[0].getData();
+ provider.setPropertySelection(sel);
+ }
+ }
+ });
+
+ // alerts the top listener as to the mouse position, to know which column is
serverViewerSelection
+ xpathTree.addListener(SWT.MouseMove, new Listener() {
+ public void handleEvent(Event event) {
+ selListener.setMouseX(event.x);
+ }
+ });
+ }
+
+ private void treeviewerEditorTextChanged(TreeItem item, Text text, int column) {
+ if( column == 1 ) {
+ if( text.isDisposed() || item.isDisposed()) return;
+
+ // we're changing the value in the actual descriptor.
+ XPathResultNode itemToChange = getChangedNode(item.getData());
+ if( itemToChange != null ) {
+
+ // if its unchanged do nothing
+ if( itemToChange.getText().equals(text.getText())) {
+ return;
+ }
+
+ // set the text and add the document to the list of dirty ones
+ itemToChange.setText(text.getText());
+ if( itemToChange.getDocument() != null ) {
+ itemToChange.saveDescriptor();
+ }
+ xpathTreeViewer.refresh(item.getData());
+ }
+ }
+ }
+
+ private XPathResultNode getChangedNode(Object data) {
+ // if we are the node to change, change me
+ if( data instanceof XPathResultNode ) {
+ return (XPathResultNode)data;
+ }
+
+ // if we're a node which represents a file, but only have one matched node, thats
the node.
+ if( data instanceof XPathFileResult &&
((XPathFileResult)data).getChildren().length == 1 ) {
+ return (XPathResultNode) (((XPathFileResult)data).getChildren()[0]);
+ }
+
+ // if we're a top level tree item (JNDI), with one file child and one mbean
grandchild, the grandchild is the node
+ if( data instanceof XPathQuery && ((XPathQuery)data).getResults().length == 1 )
{
+ XPathFileResult item = ((XPathFileResult) ((XPathQuery)data).getResults()[0]);
+ if( item.getChildren().length == 1 )
+ return (XPathResultNode)item.getChildren()[0];
+ }
+ return null;
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyContentProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyContentProvider.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyContentProvider.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -0,0 +1,71 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.descriptors;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathCategory;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult.XPathResultNode;
+import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
+
+public class XPathPropertyContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ // we're a leaf
+ if( parentElement instanceof XPathResultNode ) {
+ return new Object[0];
+ }
+
+ // we're a file node (blah.xml)
+ if( parentElement instanceof XPathFileResult ) {
+ if( ((XPathFileResult)parentElement).getChildren().length == 1 )
+ return new Object[0];
+ return ((XPathFileResult)parentElement).getChildren();
+ }
+
+ // we're the named element (JNDI)
+ if( parentElement instanceof XPathQuery) {
+ if( countResultNodes((XPathQuery)parentElement) == 1 ) {
+ return new Object[0];
+ } else {
+ return ((XPathQuery)parentElement).getResults();
+ }
+ }
+
+ // re-creates it from scratch... hrmm
+ if( parentElement instanceof ServerViewProvider )
+ return new Object[] {"ERROR"}; //XPathModel.getDefault().getCategories()
+ return new Object[0];
+ }
+
+ public int countResultNodes(XPathQuery query) {
+ int count = 0;
+ XPathFileResult[] files = query.getResults();
+ for( int i = 0; i < files.length; i++ ) {
+ count += files[i].getChildren().length;
+ }
+ return count;
+ }
+
+ 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 XPathCategory ) {
+ return ((XPathCategory)inputElement).getQueries();
+ }
+ return new Object[0];
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyLabelProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyLabelProvider.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/descriptors/XPathPropertyLabelProvider.java 2007-07-19
00:47:40 UTC (rev 2512)
@@ -0,0 +1,57 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.descriptors;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathQuery;
+import org.jboss.ide.eclipse.as.core.model.descriptor.XPathFileResult.XPathResultNode;
+import org.jboss.ide.eclipse.as.ui.Messages;
+
+public class XPathPropertyLabelProvider extends LabelProvider implements
ITableLabelProvider {
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ if( element instanceof XPathQuery) {
+ if( columnIndex == 0 ) return ((XPathQuery)element).getName();
+ if( columnIndex == 1 ) {
+ XPathResultNode[] nodes = getResultNodes(((XPathQuery)element));
+ if( nodes.length == 1 )
+ return nodes[0].getText();
+ }
+ }
+
+ if( element instanceof XPathFileResult ) {
+ XPathFileResult result = (XPathFileResult)element;
+ if( columnIndex == 0 ) {
+ return result.getFileLocation().substring(result.getQuery().getBaseDir().length());
+ }
+ if( result.getChildren().length == 1 ) {
+ element = result.getChildren()[0];
+ }
+ }
+
+ if( element instanceof XPathResultNode ) {
+ XPathResultNode element2 = (XPathResultNode)element;
+ if( columnIndex == 0 ) return Messages.DescriptorXPathMatch + element2.getIndex();
+ if( columnIndex == 1 ) return element2.getText();
+ }
+
+ return null;
+ }
+
+ public XPathResultNode[] getResultNodes(XPathQuery query) {
+ int count = 0;
+ ArrayList l = new ArrayList();
+ XPathFileResult[] files = query.getResults();
+ for( int i = 0; i < files.length; i++ ) {
+ l.addAll(Arrays.asList(files[i].getChildren()));
+ }
+ return (XPathResultNode[]) l.toArray(new XPathResultNode[l.size()]);
+ }
+
+}