ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1310283 - in /ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor: ACETagEditorExtension.java TagTableEntry.java
Date Fri, 06 Apr 2012 11:32:58 GMT
Author: jawi
Date: Fri Apr  6 11:32:58 2012
New Revision: 1310283

URL: http://svn.apache.org/viewvc?rev=1310283&view=rev
Log:
ACE-253: tag editor does not appear for other entities than targets.

Modified:
    ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/ACETagEditorExtension.java
    ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/TagTableEntry.java

Modified: ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/ACETagEditorExtension.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/ACETagEditorExtension.java?rev=1310283&r1=1310282&r2=1310283&view=diff
==============================================================================
--- ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/ACETagEditorExtension.java
(original)
+++ ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/ACETagEditorExtension.java
Fri Apr  6 11:32:58 2012
@@ -29,80 +29,115 @@ import org.apache.ace.webui.UIExtensionF
 
 import com.vaadin.event.Action;
 import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.Table;
 import com.vaadin.ui.TextField;
 import com.vaadin.ui.VerticalLayout;
 
+/**
+ * Provides a generic tag-editor for artifacts, features, distributions and targets.
+ */
 public class ACETagEditorExtension implements UIExtensionFactory {
 
+    /**
+     * {@inheritDoc}
+     */
     public Component create(Map<String, Object> context) {
         final RepositoryObject sgo = getRepositoryObjectFromContext(context);
-        VerticalLayout result = new VerticalLayout();
-        result.setCaption("Tag Editor");
+
+        Component editor;
         if (sgo instanceof StatefulTargetObject) {
             StatefulTargetObject statefulTarget = (StatefulTargetObject) sgo;
             if (statefulTarget.isRegistered()) {
-                final Table table = new Table();
-                table.setWidth("100%");
-                table.addContainerProperty("Tag", TextField.class, null);
-                table.addContainerProperty("Value", TextField.class, null);
-                table.setEditable(false);
-                result.addComponent(table);
-                result.setComponentAlignment(table, Alignment.MIDDLE_CENTER);
-                final Map<Object, TagTableEntry> idToKey = new HashMap<Object, TagTableEntry>();
-                Enumeration<String> keys = sgo.getTagKeys();
-                while (keys.hasMoreElements()) {
-                    String keyString = keys.nextElement();
-                    String valueString = sgo.getTag(keyString);
-                    if ((valueString != null) && (valueString.trim().length() !=
0)) {
-                        TagTableEntry tte = new TagTableEntry(sgo, keyString,
-                                valueString);
-                        idToKey.put(tte.addTo(table), tte);
-                    }
-                }
-                final TagTableEntry tte = new TagTableEntry(sgo);
-                idToKey.put(tte.addTo(table), tte);
-                tte.setListener(new TagTableEntry.ChangeListener() {
-                    private volatile TagTableEntry m_lastEntry = tte;
-                    public void changed(TagTableEntry entry) {
-                        TagTableEntry ntte = new TagTableEntry(sgo);
-                        idToKey.put(ntte.addTo(table), ntte);
-                        m_lastEntry.setListener(null);
-                        m_lastEntry = ntte;
-                        ntte.setListener(this);
-                    }
-                });
-                table.addActionHandler(new Action.Handler() {
-                    final Action[] delete = new Action[] { new Action("delete") };
-                    public void handleAction(Action action, Object sender, Object target)
{
-                        idToKey.remove(target).removeFrom(table);
-                    }
-                    public Action[] getActions(Object target, Object sender) {
-                        return delete;
-                    }
-                });
+                editor = createTagEditor(sgo);
             }
             else {
-                result.addComponent(new Label("This target is not yet registered, so you
cannot add tags."));
+                editor = new Label("This target is not yet registered, so you cannot add
tags.");
             }
         }
+        else {
+            editor = createTagEditor(sgo);
+        }
+
+        VerticalLayout result = new VerticalLayout();
+        result.setCaption("Tag Editor");
+
+        result.addComponent(editor);
+
+        result.setComponentAlignment(editor, Alignment.MIDDLE_CENTER);
+
         return result;
     }
 
-    private RepositoryObject getRepositoryObjectFromContext(
-            @SuppressWarnings("rawtypes") Map context) {
+    /**
+     * Creates a tag editor component for the given repository object.
+     * 
+     * @param object the repository object to create the tag editor for, cannot be <code>null</code>.
+     * @return a tag editor component, never <code>null</code>.
+     */
+    private Component createTagEditor(final RepositoryObject object) {
+        final Table table = new Table();
+        table.setWidth("100%");
+
+        table.addContainerProperty("Tag", TextField.class, null);
+        table.addContainerProperty("Value", TextField.class, null);
+        table.addContainerProperty("Remove", Button.class, null, "", null, Table.ALIGN_CENTER);
+        table.setEditable(false);
+        
+        table.setColumnExpandRatio("Tag", 1.0f);
+        table.setColumnExpandRatio("Value", 1.0f);
+        table.setColumnExpandRatio("Remove", 0.2f);
+        
+        final Map<Object, TagTableEntry> idToKey = new HashMap<Object, TagTableEntry>();
+        Enumeration<String> keys = object.getTagKeys();
+        while (keys.hasMoreElements()) {
+            String keyString = keys.nextElement();
+            String valueString = object.getTag(keyString);
+            if ((valueString != null) && (valueString.trim().length() != 0)) {
+                TagTableEntry tte = new TagTableEntry(object, keyString, valueString);
+                idToKey.put(tte.addTo(table), tte);
+            }
+        }
+        
+        final TagTableEntry tte = new TagTableEntry(object);
+        idToKey.put(tte.addTo(table), tte);
+        
+        tte.setListener(new TagTableEntry.ChangeListener() {
+            private volatile TagTableEntry m_lastEntry = tte;
+
+            public void changed(TagTableEntry entry) {
+                TagTableEntry ntte = new TagTableEntry(object);
+                idToKey.put(ntte.addTo(table), ntte);
+                m_lastEntry.setListener(null);
+                m_lastEntry = ntte;
+                ntte.setListener(this);
+            }
+        });
+        
+        table.addActionHandler(new Action.Handler() {
+            final Action[] delete = new Action[] { new Action("delete") };
+
+            public void handleAction(Action action, Object sender, Object target) {
+                idToKey.remove(target).removeFrom(table);
+            }
+
+            public Action[] getActions(Object target, Object sender) {
+                return delete;
+            }
+        });
+
+        return table;
+    }
+
+    private RepositoryObject getRepositoryObjectFromContext(Map<String, Object> context)
{
         Object contextObject = context.get("object");
         if (contextObject == null) {
             throw new IllegalStateException("No context object found");
         }
-        // It looks like there is some bug (or some other reason that escapes
-        // me)
-        // why ace is using either the object directly or wraps it in a
-        // NamedObject first.
-        // Its unclear when it does which so for now we cater for both.
-        return ((RepositoryObject) (contextObject instanceof NamedObject ? ((NamedObject)
contextObject)
-                .getObject() : contextObject));
+
+        return (contextObject instanceof NamedObject ? ((NamedObject) contextObject).getObject()
+            : (RepositoryObject) contextObject);
     }
 }

Modified: ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/TagTableEntry.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/TagTableEntry.java?rev=1310283&r1=1310282&r2=1310283&view=diff
==============================================================================
--- ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/TagTableEntry.java (original)
+++ ace/trunk/ace-tageditor/src/main/java/org/apache/ace/tageditor/TagTableEntry.java Fri
Apr  6 11:32:58 2012
@@ -22,10 +22,13 @@ import org.apache.ace.client.repository.
 
 import com.vaadin.data.Property.ValueChangeEvent;
 import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.ui.Button;
 import com.vaadin.ui.Table;
 import com.vaadin.ui.TextField;
+import com.vaadin.ui.Button.ClickEvent;
 
 public class TagTableEntry {
+
     public interface ChangeListener {
         public void changed(TagTableEntry entry);
     }
@@ -33,6 +36,7 @@ public class TagTableEntry {
     private final TextField m_keyField = new TextField(null, "");
     private final TextField m_valueField = new TextField(null, "");
     private final RepositoryObject m_repoObject;
+
     private volatile String m_lastKey = null;
     private volatile Object m_id = null;
     private volatile ChangeListener m_listener = null;
@@ -40,15 +44,15 @@ public class TagTableEntry {
     public TagTableEntry(RepositoryObject repoObject) {
         m_repoObject = repoObject;
         m_keyField.setImmediate(true);
+        m_keyField.setWidth("100%");
         m_keyField.addListener(new ValueChangeListener() {
-
             public void valueChange(ValueChangeEvent event) {
                 keyChanged();
             }
         });
         m_valueField.setImmediate(true);
+        m_valueField.setWidth("100%");
         m_valueField.addListener(new ValueChangeListener() {
-
             public void valueChange(ValueChangeEvent event) {
                 valueChanged();
             }
@@ -57,13 +61,28 @@ public class TagTableEntry {
 
     public TagTableEntry(RepositoryObject repoObject, String key, String value) {
         this(repoObject);
+
         m_keyField.setValue(key);
         m_valueField.setValue(value);
         m_lastKey = key;
     }
 
-    public Object addTo(Table table) {
-        m_id = table.addItem(new Object[] { m_keyField, m_valueField }, null);
+    public Object addTo(final Table table) {
+        Button deleteButton = new Button() {
+            @Override
+            public boolean isEnabled() {
+                return super.isEnabled() && m_id != null;
+            }
+        };
+        deleteButton.setCaption("x");
+        deleteButton.setStyleName("small");
+        deleteButton.addListener(new Button.ClickListener() {
+            public void buttonClick(ClickEvent event) {
+                removeFrom(table);
+            }
+        });
+
+        m_id = table.addItem(new Object[] { m_keyField, m_valueField, deleteButton }, null);
         return m_id;
     }
 



Mime
View raw message