{
public void execute(Event<UIGadgetManagement> event) throws Exception
{
UIGadgetManagement uiManagement = event.getSource();
WebuiRequestContext ctx = event.getRequestContext();
String name = ctx.getRequestParameter(OBJECTID);
GadgetRegistryService service = uiManagement.getApplicationComponent(GadgetRegistryService.class);
if (service.getGadget(name) == null)
{
uiManagement.reload();
ctx.addUIComponentToUpdateByAjax(uiManagement);
return;
}
UIGadgetEditor uiEditor = uiManagement.getChild(UIGadgetEditor.class);
if (uiEditor != null)
{
Source source = uiEditor.getSource();
if (source != null && name.equals(uiEditor.getSourceName()))
{
UIApplication uiApp = ctx.getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIGadgetManagement.msg.deleteGadgetInUse", null));
return;
}
}
service.removeGadget(name);
WebAppController webController = uiManagement.getApplicationComponent(WebAppController.class);
webController.removeApplication(GadgetApplication.EXO_GADGET_GROUP + "/" + name);
Gadget gadget = uiManagement.getGadget(name);
if (gadget.isLocal())
{
// get dir path of gadget
String gadgetUrl = gadget.getUrl();
String[] gaggetUrlPart = gadgetUrl.split("/");
String dirPath = gaggetUrlPart[gaggetUrlPart.length - 2];
SourceStorage sourceStorage = uiManagement.getApplicationComponent(SourceStorage.class);
sourceStorage.removeSource(dirPath + "/" + name + ".xml");
}
uiManagement.reload();
// update to ApplicationOrganizer
removeFromApplicationRegistry(name);
UIApplicationOrganizer uiOrganizer =
uiManagement.getParent().findFirstComponentOfType(UIApplicationOrganizer.class);
ApplicationCategory selectedCate = uiOrganizer.getSelectedCategory();
uiOrganizer.reload();
uiOrganizer.setSelectedCategory(selectedCate);
ctx.addUIComponentToUpdateByAjax(uiManagement);
}