You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2015/01/22 16:19:03 UTC

svn commit: r1653905 - in /ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin: ManageResourceProcessorWindow.java VaadinClient.java

Author: jawi
Date: Thu Jan 22 15:19:03 2015
New Revision: 1653905

URL: http://svn.apache.org/r1653905
Log:
ACE-224 - Make RPs manageable in web UI:

- added simple dialog to list the available RPs and allow them
  to be deleted from the artifact repository (not the OBR).


Added:
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ManageResourceProcessorWindow.java   (with props)
Modified:
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java

Added: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ManageResourceProcessorWindow.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ManageResourceProcessorWindow.java?rev=1653905&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ManageResourceProcessorWindow.java (added)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ManageResourceProcessorWindow.java Thu Jan 22 15:19:03 2015
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.webui.vaadin;
+
+import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.client.repository.repository.ArtifactRepository;
+import org.osgi.framework.Constants;
+
+import com.vaadin.data.Item;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.themes.Reindeer;
+
+/**
+ * Provides a dialog for managing resource processors.
+ */
+abstract class ManageResourceProcessorWindow extends Window {
+    private static final String PROPERTY_SYMBOLIC_NAME = "symbolic name";
+    private static final String PROPERTY_VERSION = "version";
+    private static final String PROPERTY_REMOVE = "remove";
+
+    private final Table m_artifactsTable;
+
+    /**
+     * Creates a new ManageResourceProcessorWindow instance.
+     */
+    public ManageResourceProcessorWindow() {
+        super("Resource Processors");
+
+        setModal(true);
+        setWidth("50em");
+        setCloseShortcut(KeyCode.ESCAPE);
+
+        m_artifactsTable = new Table("Available resource processors");
+        m_artifactsTable.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null);
+        m_artifactsTable.addContainerProperty(PROPERTY_VERSION, String.class, null);
+        m_artifactsTable.addContainerProperty(PROPERTY_REMOVE, Button.class, null);
+        m_artifactsTable.setSizeFull();
+        m_artifactsTable.setSelectable(true);
+        m_artifactsTable.setMultiSelect(true);
+        m_artifactsTable.setImmediate(true);
+        m_artifactsTable.setHeight("15em");
+
+        VerticalLayout layout = (VerticalLayout) getContent();
+        layout.setMargin(true);
+        layout.setSpacing(true);
+
+        layout.addComponent(m_artifactsTable);
+    }
+
+    /**
+     * @param parent
+     *            the parent window to show this dialog on top of.
+     */
+    public void showWindow(Window parent) {
+        try {
+            // Fill the artifacts table with the data from the OBR...
+            populateArtifactTable(m_artifactsTable);
+
+            parent.addWindow(this);
+        }
+        catch (Exception e) {
+            // We've not yet added this window to the given parent, so we cannot use #showErrorNotification here...
+            parent.showNotification("Failed to retrieve OBR repository!", "Reason: <br/>" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
+        }
+    }
+
+    private Button createRemoveButton(final ArtifactObject rp) {
+        Button button = new Button("x");
+        button.setStyleName(Reindeer.BUTTON_SMALL);
+        button.setDescription("Remove " + rp.getAttribute(Constants.BUNDLE_SYMBOLICNAME));
+        button.addListener(new ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                event.getButton().setEnabled(false);
+
+                try {
+                    getArtifactRepository().remove(rp);
+                    m_artifactsTable.removeItem(rp.getDefinition());
+                }
+                catch (Exception e) {
+                    getParent().showNotification("Failed to delete resource", "Reason: <br/>" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
+                }
+            }
+        });
+        return button;
+    }
+
+    private void populateArtifactTable(Table artifactsTable) {
+        for (ArtifactObject rp : getArtifactRepository().getResourceProcessors()) {
+            String bsn = rp.getAttribute(Constants.BUNDLE_SYMBOLICNAME);
+
+            Item item = artifactsTable.addItem(rp.getDefinition());
+            item.getItemProperty(PROPERTY_SYMBOLIC_NAME).setValue(bsn);
+            item.getItemProperty(PROPERTY_VERSION).setValue(rp.getAttribute(Constants.BUNDLE_VERSION));
+            item.getItemProperty(PROPERTY_REMOVE).setValue(createRemoveButton(rp));
+        }
+    }
+
+    /**
+     * @return the artifact repository.
+     */
+    protected abstract ArtifactRepository getArtifactRepository();
+}

Propchange: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ManageResourceProcessorWindow.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java?rev=1653905&r1=1653904&r2=1653905&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java (original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java Thu Jan 22 15:19:03 2015
@@ -109,17 +109,6 @@ import com.vaadin.ui.Window.Notification
 @SuppressWarnings("serial")
 public class VaadinClient extends com.vaadin.Application implements AssociationManager, LoginFunction {
 
-    private static final long serialVersionUID = 1L;
-
-    private static final AtomicLong SESSION_ID = new AtomicLong(1L);
-
-    private static final String targetRepo = "target";
-    private static final String shopRepo = "shop";
-    private static final String deployRepo = "deployment";
-    private static final String customerName = "apache";
-
-    private static final String endpoint = "/repository";
-
     // basic session ID generator
     private static long generateSessionID() {
         return SESSION_ID.getAndIncrement();
@@ -147,6 +136,17 @@ public class VaadinClient extends com.va
         directory.delete();
     }
 
+    private static final long serialVersionUID = 1L;
+    private static final AtomicLong SESSION_ID = new AtomicLong(1L);
+    private static final String targetRepo = "target";
+    private static final String shopRepo = "shop";
+
+    private static final String deployRepo = "deployment";
+
+    private static final String customerName = "apache";
+
+    private static final String endpoint = "/repository";
+
     private volatile AuthenticationService m_authenticationService;
     private volatile BundleContext m_context;
     private volatile SessionFactory m_sessionFactory;
@@ -435,6 +435,39 @@ public class VaadinClient extends com.va
         }
     }
 
+    final void showAddArtifactDialog() {
+        final AddArtifactWindow window = new AddArtifactWindow(m_sessionDir, m_obrUrl, m_repositoryXML) {
+            @Override
+            protected ArtifactRepository getArtifactRepository() {
+                return m_artifactRepository;
+            }
+
+            @Override
+            protected ConnectionFactory getConnectionFactory() {
+                return m_connectionFactory;
+            }
+
+            @Override
+            protected LogService getLogger() {
+                return m_log;
+            }
+        };
+
+        // Open the subwindow by adding it to the parent window
+        window.showWindow(getMainWindow());
+    }
+
+    final void showManageResourceProcessorsDialog() {
+        ManageResourceProcessorWindow window = new ManageResourceProcessorWindow() {
+            @Override
+            protected ArtifactRepository getArtifactRepository() {
+                return m_artifactRepository;
+            }
+        };
+        // Open the subwindow by adding it to the parent window
+        window.showWindow(getMainWindow());
+    }
+
     /**
      * Create a new distribution in the distribution repository
      * 
@@ -724,6 +757,7 @@ public class VaadinClient extends com.va
         HorizontalLayout result = new HorizontalLayout();
         result.setSpacing(true);
         result.addComponent(createAddArtifactButton());
+        result.addComponent(createManageResourceProcessorsButton());
         return result;
     }
 
@@ -801,6 +835,18 @@ public class VaadinClient extends com.va
         return result;
     }
 
+    private Button createManageResourceProcessorsButton() {
+        // Solves ACE-224
+        Button button = new Button("RP");
+        button.addListener(new Button.ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                showManageResourceProcessorsDialog();
+            }
+        });
+        return button;
+    }
+
     private Button createRegisterTargetsButton() {
         final Button button = new Button("R");
         button.setDisableOnClick(true);
@@ -1200,28 +1246,6 @@ public class VaadinClient extends com.va
         return doLogin();
     }
 
-    private void showAddArtifactDialog() {
-        final AddArtifactWindow window = new AddArtifactWindow(m_sessionDir, m_obrUrl, m_repositoryXML) {
-            @Override
-            protected ArtifactRepository getArtifactRepository() {
-                return m_artifactRepository;
-            }
-
-            @Override
-            protected ConnectionFactory getConnectionFactory() {
-                return m_connectionFactory;
-            }
-
-            @Override
-            protected LogService getLogger() {
-                return m_log;
-            }
-        };
-
-        // Open the subwindow by adding it to the parent window
-        window.showWindow(getMainWindow());
-    }
-
     /**
      * Shows the login window on the center of the main window.
      */