Commit 9fe2f1b5 authored by Christophe Demarey's avatar Christophe Demarey

Explorer is now able to dynamically add & remove intents.

parent 92e263a6
......@@ -51,13 +51,23 @@ public abstract class AbstractAlwaysEnabledMenuItem<T> implements MenuItem {
/**
* @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
*/
@SuppressWarnings("unchecked")
public void actionPerformed (final MenuItemTreeView e) {
// Obtains the selected object.
T selected = (T) e.getSelectedObject();
// Execute something on the selected object.
execute(selected);
execute(selected, e);
}
/**
* Execute something on the selected object.
*
* Can be override in sub-classes.
*/
protected void execute(T selected, final MenuItemTreeView e) {
execute(selected);
}
// --------------------------------------------------------------------------
// Abstract methods implemented into concrete subclasses.
// --------------------------------------------------------------------------
......
......@@ -37,15 +37,14 @@ import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper;
import org.objectweb.fractal.util.Fractal;
import org.objectweb.util.explorer.api.DropAction;
import org.objectweb.util.explorer.api.DropTreeView;
import org.objectweb.util.explorer.api.MenuItem;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.ow2.frascati.tinfi.control.intent.SCABasicIntentController;
/**
* This class provides the ability dynamically add an intent
* on an SCA service (or an SCA reference) via the "Add intent"
* Menu item {@link MenuItem}.
* on an SCA service (or an SCA reference) via a DropAction
* {@link DropAction}.
*
* @author Christophe Demarey
*/
......@@ -135,8 +134,6 @@ public class AddIntentOnDropAction implements DropAction
}
try {
// Stop intent component
Fractal.getLifeCycleController(intent).stopFc();
// Stop owner component
Fractal.getLifeCycleController(owner).stopFc();
// Get intent handler
......@@ -148,8 +145,6 @@ public class AddIntentOnDropAction implements DropAction
} else {
ic.addFcIntentHandler(h);
}
// Start intent component
Fractal.getLifeCycleController(intent).startFc();
// Start owner component
Fractal.getLifeCycleController(owner).startFc();
} catch (Exception e1) {
......
/***
* OW2 FraSCAti Explorer
* Copyright (C) 2008-2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Demarey
*
* Contributor(s):
*/
package org.ow2.frascati.explorer.action;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper;
import org.objectweb.fractal.util.Fractal;
import org.objectweb.util.explorer.api.MenuItem;
import org.objectweb.util.explorer.api.MenuItemTreeView;
import org.ow2.frascati.explorer.context.IntentWrapper;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.ow2.frascati.tinfi.control.intent.SCABasicIntentController;
/**
* This class provides the ability dynamically remove an intent
* from an SCA service (or an SCA reference) via the "Remove intent"
* Menu item {@link MenuItem}.
*
* @author Christophe Demarey
*/
public class RemoveIntentMenuItem extends AbstractAlwaysEnabledMenuItem<IntentWrapper>
{
// --------------------------------------------------------------------------
// Internal state
// --------------------------------------------------------------------------
public static final Logger log = Logger.getLogger("org.ow2.frascati.explorer.action.RemoveIntentMenuItem");
// --------------------------------------------------------------------------
// Internal methods
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Constructor
// --------------------------------------------------------------------------
/**
* The default constructor.
*/
public RemoveIntentMenuItem () { }
// --------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Implementation of the MenuItem interface
// --------------------------------------------------------------------------
/**
* @see org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem#execute(Object, MenuItemTreeView)
*/
@Override
protected void execute(IntentWrapper selected) {
// Need to implement this method but useless!
}
/**
* @see org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem#execute(Object, MenuItemTreeView)
*/
@Override
protected void execute(IntentWrapper selected, final MenuItemTreeView tree) {
Component intent = selected.getIntent(),
itfOwner = null;
Object parent = tree.getParentEntry().getValue();
Interface itf = null;
SCABasicIntentController ic = null;
// Get intent interface
try {
itf = (Interface) parent;
} catch (ClassCastException cce) {
try {
itf = ((ClientInterfaceWrapper) parent).getItf();
} catch (ClassCastException cce2) {
cce2.printStackTrace();
}
}
itfOwner = itf.getFcItfOwner();
// Get intent controller
try {
ic = (SCABasicIntentController) itf.getFcItfOwner().getFcInterface(SCABasicIntentController.NAME);
} catch (NoSuchInterfaceException nsie) {
JOptionPane.showMessageDialog(null, "Cannot access to intent controller");
log.log(Level.SEVERE, "Cannot access to intent controller", nsie);
}
// Remove intent
try {
// Stop owner component
Fractal.getLifeCycleController(itfOwner).stopFc();
// Get intent handler
IntentHandler h = TinfiDomain.getService(intent, IntentHandler.class, "intent");
// remove intent
ic.removeFcIntentHandler(h, itf.getFcItfName());
// Start owner component
Fractal.getLifeCycleController(itfOwner).startFc();
} catch (NoSuchInterfaceException nsie) {
JOptionPane.showMessageDialog(null, "Cannot retrieve the interface name!");
log.log(Level.SEVERE, "Cannot retrieve the interface name!", nsie);
} catch (IllegalLifeCycleException ilce) {
JOptionPane.showMessageDialog(null, "Illegal life cycle Exception!");
log.log(Level.SEVERE, "Illegal life cycle Exception!", ilce);
}
}
/*
public void actionPerformed (final MenuItemTreeView e) {
Interface selected = (Interface) e.getSelectedObject();
Component itfOwner = selected.getFcItfOwner();
Component intent = loadIntent();
String intentName = null;
SCABasicIntentController ic = null;
// Get intent controller
try {
ic = (SCABasicIntentController) itfOwner.getFcInterface(SCABasicIntentController.NAME);
} catch (NoSuchInterfaceException nsie) {
JOptionPane.showMessageDialog(null, "Cannot access to intent controller");
log.log(Level.SEVERE, "Cannot access to intent controller", nsie);
}
if (intent != null) {
try {
intentName = Fractal.getNameController(intent).getFcName();
} catch (NoSuchInterfaceException nsie) {
log.log(Level.SEVERE, "Cannot find the Name Controller!", nsie);
}
String itfName = selected.getFcItfName();
try {
// Stop intent component
Fractal.getLifeCycleController(intent).stopFc();
// Stop owner component
Fractal.getLifeCycleController(itfOwner).stopFc();
// Get intent handler
IntentHandler h = TinfiDomain.getService(intent, IntentHandler.class, "intent");
// Add intent
ic.addFcIntentHandler(h, itfName);
// Start intent component
Fractal.getLifeCycleController(intent).startFc();
// Start owner component
Fractal.getLifeCycleController(itfOwner).startFc();
} catch (Exception e1) {
JOptionPane.showMessageDialog(null,"Intent '" + intentName
+ "' cannot be added to interface " + itfName);
log.log(Level.SEVERE, "Intent '" + intentName
+ "' cannot be added to interface " + itfName, e1);
}
}
}*/
}
......@@ -49,7 +49,7 @@ public class IntentWrapper {
*
* @return the wrapped intent.
*/
Component getIntent() {
public Component getIntent() {
return intent;
}
}
......@@ -177,6 +177,11 @@
<wrapper>
<code>org.ow2.frascati.explorer.context.IntentContext</code>
</wrapper>
<menu>
<item label="Remove intent">
<code>org.ow2.frascati.explorer.action.RemoveIntentMenuItem</code>
</item>
</menu>
</node>
<!-- ================================================================= -->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment