{
public void execute(Event<UIGadgetInfo> event) throws Exception
{
UIGadgetInfo uiInfo = event.getSource();
Gadget gadget = uiInfo.getGadget();
UIGadgetManagement uiManagement = uiInfo.getParent();
GadgetRegistryService service = uiInfo.getApplicationComponent(GadgetRegistryService.class);
if (service.getGadget(gadget.getName()) == null)
{
UIApplication uiApp = event.getRequestContext().getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIGadgetInfo.msg.gadgetNotExist", null));
uiManagement.reload();
return;
}
SourceStorage sourceStorage = uiManagement.getApplicationComponent(SourceStorage.class);
UIGadgetEditor uiEditor = uiManagement.createUIComponent(UIGadgetEditor.class, null, null);
String fileName = gadget.getName() + ".xml";
// get dir path of gadget
String gadgetUrl = gadget.getUrl();
String[] gaggetUrlPart = gadgetUrl.split("/");
String dirPath = gaggetUrlPart[gaggetUrlPart.length - 2];
//String dirPath = gaggetUrlPart[gaggetUrlPart.length - 9];
// get gadget's source: path = dir path + file name
Source source = sourceStorage.getSource(gadget);
uiEditor.setSource(source);
uiEditor.setGadgetName(gadget.getName());
uiEditor.setDirPath(dirPath);
uiManagement.getChildren().clear();
uiManagement.addChild(uiEditor);
event.getRequestContext().addUIComponentToUpdateByAjax(uiManagement);
}