Search in sources :

Example 1 with CommonPlugin

use of org.apache.felix.mosgi.console.ifc.CommonPlugin in project felix by apache.

the class Activator method start.

// /////////////////////////////////////
// BundleActivator           //
// /////////////////////////////////////
public void start(BundleContext context) {
    m_context = context;
    // Listen for factory service events.
    ServiceListener sl = new ServiceListener() {

        public void serviceChanged(ServiceEvent event) {
            ServiceReference ref = event.getServiceReference();
            Object svcObj = m_context.getService(ref);
            if (event.getType() == ServiceEvent.REGISTERED) {
                synchronized (Activator.this) {
                    // !!!!!!!!!! ORDER MATTERS (Inheritance pb)
                    if (!m_pluginList.contains(svcObj)) {
                        if (svcObj instanceof CommonPlugin) {
                            m_commonpluginList.add(svcObj);
                            firePropertyChangedEvent(CommonPlugin.COMMON_PLUGIN_ADDED, null, svcObj);
                        } else if (svcObj instanceof Plugin) {
                            m_pluginList.add(svcObj);
                            firePropertyChangedEvent(Plugin.PLUGIN_ADDED, null, svcObj);
                        }
                    }
                }
            } else if (event.getType() == ServiceEvent.UNREGISTERING) {
                synchronized (Activator.this) {
                    removePropertyChangeListener((PropertyChangeListener) svcObj);
                    if (svcObj instanceof CommonPlugin) {
                        m_commonpluginList.remove(svcObj);
                        firePropertyChangedEvent(CommonPlugin.COMMON_PLUGIN_REMOVED, null, svcObj);
                    } else if (svcObj instanceof Plugin) {
                        m_pluginList.remove(svcObj);
                        firePropertyChangedEvent(Plugin.PLUGIN_REMOVED, null, svcObj);
                    }
                }
            } else {
                m_context.ungetService(ref);
            }
        }
    };
    try {
        m_context.addServiceListener(sl, "(|(objectClass=" + Plugin.class.getName() + ")(objectClass=" + CommonPlugin.class.getName() + "))");
    } catch (InvalidSyntaxException ex) {
        System.err.println("ShellGuiActivator: Cannot add service listener.");
        System.err.println("ShellGuiActivator: " + ex);
    }
    // Create and display the frame.
    if (m_frame == null) {
        m_frame = new JFrame("OSGi GUI Remote Manager");
        m_frame.setUndecorated(true);
        m_frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
        m_frame.setIconImage(Toolkit.getDefaultToolkit().getImage(m_context.getBundle().getResource("images/logo.gif")));
        // m_frame.setResizable(false);
        // m_frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        // TODO : add a windowListener and use a Preferences service to save screen size
        m_frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent we) {
                JFrame jf = (JFrame) we.getWindow();
                System.out.println(" Console.gui : window closing (" + jf.getSize().height + "*" + jf.getSize().width + ")");
            }

            public void windowClosed(WindowEvent we) {
                JFrame jf = (JFrame) we.getWindow();
                System.out.println(" Console.gui : window closed (" + jf.getSize().height + "*" + jf.getSize().width + ")");
            }
        });
        Dimension maxdim = m_frame.getToolkit().getScreenSize();
        int m_width = maxdim.width - 100;
        int m_height = maxdim.height - 100;
        m_frame.setBounds((int) ((maxdim.width - m_width) / 2), 20, m_width, m_height);
        // Right panel
        JSplitPane rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new NodePanel(this, context), new CommonPanel(this));
        rightSplitPane.setOneTouchExpandable(true);
        rightSplitPane.setDividerLocation((int) (m_height * 2 / 3));
        // General Panel
        this.nodesTree = new NodesTree(this, context);
        JSplitPane gSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.nodesTree, rightSplitPane);
        gSplitPane.setOneTouchExpandable(true);
        gSplitPane.setDividerLocation((int) (m_width / 4));
        m_frame.getContentPane().add(gSplitPane);
    }
    // Now try to manually initialize the plugin list
    // since some might already be available.
    // initializePlugins();
    m_frame.setVisible(true);
    this.nodesTree.runDiscovery();
}
Also used : ServiceListener(org.osgi.framework.ServiceListener) PropertyChangeListener(java.beans.PropertyChangeListener) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) ServiceReference(org.osgi.framework.ServiceReference) CommonPlugin(org.apache.felix.mosgi.console.ifc.CommonPlugin) JFrame(javax.swing.JFrame) ServiceEvent(org.osgi.framework.ServiceEvent) WindowEvent(java.awt.event.WindowEvent) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) JSplitPane(javax.swing.JSplitPane) Plugin(org.apache.felix.mosgi.console.ifc.Plugin) CommonPlugin(org.apache.felix.mosgi.console.ifc.CommonPlugin)

Example 2 with CommonPlugin

use of org.apache.felix.mosgi.console.ifc.CommonPlugin in project felix by apache.

the class CommonPanel method propertyChange.

public void propertyChange(PropertyChangeEvent event) {
    if (event.getPropertyName().equals(CommonPlugin.COMMON_PLUGIN_ADDED)) {
        CommonPlugin cp = (CommonPlugin) event.getNewValue();
        this.add(cp.getName(), cp.getGUI());
        this.beanEventBroadcaster.addPropertyChangeListener(cp);
    }
    if (event.getPropertyName().equals(CommonPlugin.COMMON_PLUGIN_REMOVED)) {
        CommonPlugin cp = (CommonPlugin) event.getNewValue();
        this.remove(cp.getGUI());
        this.beanEventBroadcaster.removePropertyChangeListener(cp);
    }
}
Also used : CommonPlugin(org.apache.felix.mosgi.console.ifc.CommonPlugin)

Aggregations

CommonPlugin (org.apache.felix.mosgi.console.ifc.CommonPlugin)2 Dimension (java.awt.Dimension)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 JFrame (javax.swing.JFrame)1 JSplitPane (javax.swing.JSplitPane)1 Plugin (org.apache.felix.mosgi.console.ifc.Plugin)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceEvent (org.osgi.framework.ServiceEvent)1 ServiceListener (org.osgi.framework.ServiceListener)1 ServiceReference (org.osgi.framework.ServiceReference)1