This is a common graphical component of the console. That traps remotelogs notifications.



git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@424270 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.mosgi.console.component/pom.xml b/org.apache.felix.mosgi.console.component/pom.xml
new file mode 100644
index 0000000..63c5813
--- /dev/null
+++ b/org.apache.felix.mosgi.console.component/pom.xml
@@ -0,0 +1,53 @@
+<project>
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>0.8.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>osgi-bundle</packaging>
+  <name>MOSGi JMX Console GUI component</name>
+  <artifactId>org.apache.felix.mosgi.console.component</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.mosgi.console.ifc</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix.plugins</groupId>
+        <artifactId>maven-osgi-plugin</artifactId>
+        <version>${pom.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <osgiManifest>
+            <bundleName>MOSGi JMX Console main GUI component</bundleName>
+            <bundleDescription>MOSGi JMX Console main GUI component</bundleDescription>
+						<bundleActivator>auto-detect</bundleActivator>
+            <bundleDocUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/</bundleDocUrl>
+            <bundleUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</bundleUrl>
+            <bundleSource>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</bundleSource>
+            <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
+						<importPackage>
+						  org.apache.felix.mosgi.console.ifc;specification-version="1.0.0",
+						  javax.management;specification-version="1.0.0",
+						  javax.swing;specification-version="1.0.0",
+						  javax.swing.table;specification-version="1.0.0",
+						  org.osgi.framework;specification-version="1.0.0"
+						</importPackage>
+          </osgiManifest>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/org.apache.felix.mosgi.console.component/src/main/java/org/apache/felix/mosgi/console/component/Activator.java b/org.apache.felix.mosgi.console.component/src/main/java/org/apache/felix/mosgi/console/component/Activator.java
new file mode 100644
index 0000000..054c948
--- /dev/null
+++ b/org.apache.felix.mosgi.console.component/src/main/java/org/apache/felix/mosgi/console/component/Activator.java
@@ -0,0 +1,43 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.felix.mosgi.console.component;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.apache.felix.mosgi.console.ifc.CommonPlugin;
+
+public class Activator implements BundleActivator
+{
+    private BundleContext m_context = null;
+
+    public void start(BundleContext context) throws Exception
+    {
+        m_context = context;
+        m_context.registerService( CommonPlugin.class.getName(), new RemoteLogger(), null);
+//        m_context.registerService( Plugin.class.getName(), new NodeDetails(), null);
+//        m_context.registerService( Plugin.class.getName(), new BundleListPanel(), null);
+
+//        m_context.registerService( CommonPlugin.class.getName(), new OBRPlugin(context), null);
+
+        //        m_context.registerService( Plugin.class.getName(), new MemoryLauncher(context), null);
+//        m_context.registerService( Plugin.class.getName(), new LinuxDetails(), null);
+    }
+
+    public void stop(BundleContext context)
+    {
+    }
+}
diff --git a/org.apache.felix.mosgi.console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger.java b/org.apache.felix.mosgi.console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger.java
new file mode 100644
index 0000000..5e80bcc
--- /dev/null
+++ b/org.apache.felix.mosgi.console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger.java
@@ -0,0 +1,102 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.felix.mosgi.console.component;
+
+import org.apache.felix.mosgi.console.ifc.CommonPlugin;
+import org.apache.felix.mosgi.console.ifc.Plugin;
+
+import javax.swing.table.DefaultTableModel;
+import javax.swing.JTable;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import java.awt.Component;
+
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.MBeanServerConnection;
+import javax.swing.ListSelectionModel;
+
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+
+import java.beans.PropertyChangeEvent;
+
+public class RemoteLogger extends DefaultTableModel implements CommonPlugin, NotificationListener{
+  private JTable logList;
+  private JPanel jp;
+  private Hashtable nodes=new Hashtable();
+
+  public RemoteLogger (){
+    super(new String[]{"Src", "Level", "Id", "Text"},1);
+System.out.println("Remote logger v1");
+    this.jp=new JPanel();
+    
+    logList = new JTable(this);
+    logList.setPreferredScrollableViewportSize(new java.awt.Dimension(600, 70));
+    
+    logList.getColumnModel().getColumn(0).setPreferredWidth(130);
+    logList.getColumnModel().getColumn(1).setPreferredWidth(50);
+    logList.getColumnModel().getColumn(2).setPreferredWidth(10);
+    logList.getColumnModel().getColumn(3).setPreferredWidth(300);
+    
+
+    logList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+    logList.getTableHeader().setReorderingAllowed(false);
+    jp.add(new JScrollPane(logList));
+    
+  }
+
+  /////////////////////////////////////
+  //  Plugin Interface ////////////////
+  /////////////////////////////////////
+  public String getName(){ return "Remote Logger";}
+  public Component getGUI(){return this.jp;}
+
+/* a supprimer si on enleve l'heritage CommonPlugin -> Plugin */
+  public String pluginLocation(){
+    return null;
+  }
+  public void registerServicePlugin(){}
+  public void unregisterServicePlugin(){}
+/* fin a supprimer */
+
+  
+  public void propertyChange(PropertyChangeEvent e){
+    if (e.getPropertyName().equals(Plugin.NEW_NODE_CONNECTION)){
+      try{
+        MBeanServerConnection mbs=(MBeanServerConnection)e.getNewValue();
+        if (nodes.get(mbs)==null){
+System.out.println("Ajout d'un listener " +mbs);
+          ((MBeanServerConnection)e.getNewValue()).addNotificationListener(new ObjectName("OSGI:name=Remote Logger"), this, null, e.getOldValue());
+          nodes.put(mbs, "ok");
+        }
+      }catch(Exception ex){
+        ex.printStackTrace();
+      }
+    }
+  }
+
+  public void handleNotification(Notification notification, Object handback) {
+    //int row=this.getRowCount();
+    StringTokenizer st=new StringTokenizer(notification.getMessage(), ":");
+    Object [] event=new Object []{handback, st.nextToken(), st.nextToken(), st.nextToken()};
+    this.insertRow(0,event);
+    this.fireTableRowsInserted(0, 0);
+  }
+  
+}