[jbosstools-commits] JBoss Tools SVN: r6672 - in trunk/common/plugins/org.jboss.tools.common.model.ui: src/org/jboss/tools/common/model/ui/editors/dnd/context and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Mar 3 11:38:12 EST 2008


Author: scabanovich
Date: 2008-03-03 11:38:11 -0500 (Mon, 03 Mar 2008)
New Revision: 6672

Added:
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/ICustomVariable.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java
Log:
JBIDE-1433 More decorators added.


Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd	2008-03-03 16:38:11 UTC (rev 6672)
@@ -88,6 +88,13 @@
                </documentation>
             </annotation>
          </attribute>
+         <attribute name="class" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
          <attribute name="description" type="string">
             <annotation>
                <documentation>

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -14,6 +14,8 @@
 import java.net.MalformedURLException;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.jboss.tools.common.model.ui.ModelUIPlugin;
 import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
 import org.eclipse.swt.dnd.DropTargetEvent;
@@ -73,6 +75,7 @@
 	}
 	
 	TransferHolder[] TRANSFERS = {
+		new TransferHolder(LocalSelectionTransfer.getTransfer(), new LocalTransferProcessor()),
 		new TransferHolder(ModelTransfer.getInstance(), new ModelTransferProcessor()),
 		new TransferHolder(HTMLTransfer.getInstance(), new HTMLTransferProcessor()),
 		new TransferHolder(FileTransfer.getInstance(), new FileTransferProcessor()),
@@ -136,6 +139,7 @@
 	}
 	
 	private boolean dropAsFileObject(XModelObject o) {
+		if(o == null) return false;
 		if(o.getFileType() != XModelObject.FILE || isOverAttributeValue) return false;
     	if(TLDUtil.isTaglib(o)) return false;
     	String extension = o.getAttributeValue("extension");
@@ -186,6 +190,18 @@
 		}
 	}
 
+	class LocalTransferProcessor extends TransferProcessor {
+		public void process(TransferData data) {
+			flavor = "application/x-moz-file";
+			Object ooo = LocalSelectionTransfer.getTransfer().getSelection();
+			if(ooo instanceof StructuredSelection) {
+				ooo = ((StructuredSelection)ooo).getFirstElement();
+				InnerDragBuffer.object = ooo;
+			}
+			mimeData = ooo == null ? null : ooo.toString();
+		}
+	}
+
 	class FileTransferProcessor extends TransferProcessor {
 		public void process(TransferData data) {
 			flavor = "application/x-moz-file";

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -17,12 +17,20 @@
  */
 public class AttributeDecoratorPart implements IDecoratorPart {
 	Variable variable;
+	String parameters = "";
 	
 	public AttributeDecoratorPart(Variable variable) {
 		this.variable = variable;
 	}
+	
+	public void setParameters(String params) {
+		parameters = params;
+	}
 
 	public String getLabelPart(XModelObject object) {
+		if(variable.custom != null) {
+			return variable.custom.getLabelPart(object, parameters);
+		}
 		String v = object.getAttributeValue(variable.getName());
 		return v == null ? "{" + variable.getName() + "}" : v; 
 	}

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -29,6 +29,8 @@
 	
 	public String ATTR_VALUE = "value";
 	
+	public String ATTR_CLASS = "class";
+
 	public String NODE_VARIABLE = "variable";
 	
 	public String NODE_EXAMPLE = "example";

Added: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/ICustomVariable.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/ICustomVariable.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/ICustomVariable.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -0,0 +1,22 @@
+/******************************************************************************* 
+ * Copyright (c) 2007 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import org.jboss.tools.common.model.XModelObject;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public interface ICustomVariable {
+
+	public String getLabelPart(XModelObject object, String parameters);
+
+}

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -16,6 +16,7 @@
  * @author Viacheslav Kabanovich
  */
 public class NameDecoratorPart implements IDecoratorPart {
+	static NameDecoratorPart INSTANCE = new NameDecoratorPart();
 	
 	public NameDecoratorPart() {
 	}

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -10,7 +10,9 @@
  ******************************************************************************/ 
 package org.jboss.tools.common.model.ui.navigator.decorator;
 
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
 
 /**
  * @author Viacheslav Kabanovich
@@ -19,7 +21,9 @@
 	public static Variable NAME = new Variable("name", "default label");
 
 	String name;
+	String parameters = "";
 	String description;
+	ICustomVariable custom;
 	
 	public Variable() {}
 	
@@ -37,19 +41,34 @@
 	}
 	
 	public String getRuleText() {
-		return RULE_OPENING + name + RULE_CLOSING;
+		return RULE_OPENING + name + parameters + RULE_CLOSING;
 	}
 	
 	public String toString() {
 		if(description == null || description.length() == 0) {
 			return name;
 		}
-		return name + " - " + description;
+		return name + parameters + " - " + description;
 	}
 	
 	public void load(IConfigurationElement element) {
 		name = element.getAttribute(ATTR_NAME);
+		int i = name.indexOf('(');
+		if(i >= 0) {
+			parameters = name.substring(i);
+			name = name.substring(0, i);
+		}
 		description = element.getAttribute(ATTR_DESCRIPTION);
+		String cls = element.getAttribute(ATTR_CLASS);
+		if(cls != null && cls.length() > 0) {
+			try {
+				custom = (ICustomVariable)element.createExecutableExtension(ATTR_CLASS);
+			} catch (CoreException e) {
+				ModelUIPlugin.getPluginLog().logError(e);
+			} catch (ClassCastException e1) {
+				ModelUIPlugin.getPluginLog().logError("Attribute " + ATTR_CLASS + " must be instanceof ICustomVariable", e1);
+			}
+		}
 	}
 
 }

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -133,11 +133,21 @@
 			} else if(t.equals(RULE_CLOSING)) {
 				inVariable = false;				
 			} else if(inVariable) {
-				Variable variable = getVariableByName(t);
+				String n = t;
+				String p = "";
+				int i = t.indexOf('(');
+				int j = t.indexOf(')');
+				if(i >= 0 && j > i) {
+					n = t.substring(0, i);
+					p = t.substring(i + 1, j);
+				}
+				Variable variable = getVariableByName(n);
 				if(variable == Variable.NAME) {
-					parts.add(new NameDecoratorPart());
+					parts.add(NameDecoratorPart.INSTANCE);
 				} else if(variable != null){
-					parts.add(new AttributeDecoratorPart(variable));
+					AttributeDecoratorPart part = new AttributeDecoratorPart(variable);
+					part.setParameters(p);
+					parts.add(part);
 				} else {
 					parts.add(new DecoratorPart(RULE_OPENING + t + RULE_CLOSING));
 				}
@@ -145,6 +155,15 @@
 				parts.add(new DecoratorPart(t));
 			}
 		}
+		boolean hasSignificantPart = false;
+		for (IDecoratorPart p: parts) {
+			if(p != NameDecoratorPart.INSTANCE && !(p instanceof AttributeDecoratorPart)) continue;
+			hasSignificantPart = true;
+			break;
+		}
+		if(!hasSignificantPart) {
+			parts.add(NameDecoratorPart.INSTANCE);
+		}
 		return this.parts = parts;
 	}
 	
@@ -154,7 +173,9 @@
 		for (IDecoratorPart d: parts) {
 			sb.append(d.getLabelPart(object));
 		}
-		return sb.toString();
+		String s = sb.toString().trim();
+		if(s.length() == 0) s = object.getPresentationString();
+		return s;
 	}
 	
 	/**

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -33,11 +33,14 @@
 		this.noDefaultAndApplyButton();
 		TabFolder tabbedComposite = new TabFolder(parent,SWT.NULL);
 		tabbedComposite.setBackground(parent.getBackground());
-		TabItem newTab = new TabItem(tabbedComposite,SWT.NULL);
+		
+		TabItem newTab = null;
 
-		general.createControl(tabbedComposite);
-		newTab.setControl(general.getControl());
-		newTab.setText(general.getTitle());
+//TODO  remove comments when we find some preferences to put here
+//		newTab = new TabItem(tabbedComposite,SWT.NULL);
+//		general.createControl(tabbedComposite);
+//		newTab.setControl(general.getControl());
+//		newTab.setText(general.getTitle());
 
 		newTab = new TabItem(tabbedComposite,SWT.NULL);
 

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java	2008-03-03 16:37:48 UTC (rev 6671)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java	2008-03-03 16:38:11 UTC (rev 6672)
@@ -383,6 +383,7 @@
 		currentValues.put(selection, text);
 		setText(text);
 		formatField.setSelection(cn);
+		examples.refresh(true);
 	}
 
 }




More information about the jbosstools-commits mailing list