() {
+ public void onSuccess(final Void result) {
+ Commands.showPopup("Empty cache", "The remote cache has been cleaned");
+ }
+ public void onFailure(final Throwable caught) {
+ Commands.showPopup("Empty cache error", "The remote cache has not been cleaned");
+ }
+ });
+ };
+ };
+ emptyCache.setIconStyle("clear-icon");
+ toolsMenu.add(emptyCache);
+
+
+ /***********************************************************
+ * MENU - ABOUT
+ **********************************************************/
+ Menu helpMenu = new Menu();
+ MenuItem aboutMnuItem = new MenuItem("About") {
+ @Override
+ protected void onClick(final ComponentEvent be) {
+ super.onClick(be);
+ Dialog dlg = new Dialog();
+ dlg.setHeading("About - Resource Management");
+ dlg.addText("
This software is part of the gCube Project.
" +
+ "Site: http://www.gcube-system.org/" +
+ "The gCube/gCore software is licensed as Free Open Source software " +
+ "conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
" +
+ "The software and documentation is provided by its authors/distributors " +
+ "\"as is\" and no expressed or " +
+ "implied warranty is given for its use, quality or fitness for a " +
+ "particular case.
" +
+ "" +
+ "Bugs can be submitted here.
" +
+ "Notice: specify this Component:
portlets/admin/ResourceManagementPortlet
" +
+ "
");
+
+ dlg.setClosable(true);
+ dlg.setModal(true);
+ dlg.setHideOnButtonClick(true);
+ dlg.show();
+ }
+ };
+ aboutMnuItem.setIconStyle("about-icon");
+ helpMenu.add(aboutMnuItem);
+
+ MenuBar mb = new MenuBar();
+ mb.add(new MenuBarItem("Tools", toolsMenu));
+ mb.add(new MenuBarItem("Options", optionsMenu));
+ mb.add(new MenuBarItem("Search", searchMenu));
+ mb.add(new MenuBarItem("Help", helpMenu));
+
+
+ MainPanel menuPanel = WidgetsRegistry.getPanel(UIIdentifiers.GLOBAL_MENU_CONTAINER_PANEL);
+ WidgetsRegistry.registerWidget(UIIdentifiers.GLOBAL_MENUBAR_ID, mb);
+ menuPanel.add(mb, true);
+ }
+
+ private void buildStatusBar() {
+ MainPanel menuPanel = WidgetsRegistry.getPanel(UIIdentifiers.GLOBAL_MENU_CONTAINER_PANEL);
+ ToolBar statusbar = new ToolBar();
+ statusbar.add(new SeparatorToolItem());
+
+ if (StatusHandler.getStatus().getRunningMode() != RunningMode.PORTAL) {
+ Button btnScope = new Button("Available Scopes");
+ btnScope.setMenu(new Menu());
+ WidgetsRegistry.registerWidget(UIIdentifiers.BUTTON_AVAILABLE_SCOPES_ID, btnScope);
+ // Checks that this menu item is permitted to the current user
+ statusbar.add(btnScope);
+ } else {
+ statusbar.add(new Label("Current role: " + StatusHandler.getStatus().getCredentials()));
+ }
+
+ //statusbar.add(new FillToolItem());
+ statusbar.add(new Label(" "));
+ ProgressBar progressStatus = new ProgressBar();
+ progressStatus.setWidth(200);
+ progressStatus.updateText("Updating Infrastructure...");
+ statusbar.add(progressStatus);
+ progressStatus.hide();
+ WidgetsRegistry.registerWidget(UIIdentifiers.STATUS_PROGRESS_BAR_ID, progressStatus);
+
+ statusbar.add(new FillToolItem());
+ statusbar.add(new Label("Current Scope: "));
+ Status scopeInfo = new Status();
+ scopeInfo.setWidth(350);
+ scopeInfo.setText(Messages.NO_SCOPE_SELECTED);
+ scopeInfo.setBox(true);
+ statusbar.add(scopeInfo);
+ WidgetsRegistry.registerWidget(UIIdentifiers.STATUS_SCOPE_INFO_ID, scopeInfo);
+
+ statusbar.add(new Label(" Loaded Resources: "));
+ Status loadedResources = new Status();
+ loadedResources.setWidth(35);
+ loadedResources.setText("0");
+ loadedResources.setBox(true);
+ statusbar.add(loadedResources);
+ WidgetsRegistry.registerWidget(UIIdentifiers.STATUS_LOADED_RESOURCES_ID, loadedResources);
+
+ menuPanel.add(statusbar, false);
+
+ menuPanel.getContainer().setBorders(false);
+ menuPanel.getContainer().setShadow(true);
+ WidgetsRegistry.registerWidget(UIIdentifiers.GLOBAL_STATUS_BAR_ID, statusbar);
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/DeployServicesForm.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/DeployServicesForm.java
new file mode 100644
index 0000000..b8a5227
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/DeployServicesForm.java
@@ -0,0 +1,346 @@
+/****************************************************************************
+ * This software is part of the gCube Project.
+ * Site: http://www.gcube-system.org/
+ ****************************************************************************
+ * The gCube/gCore software is licensed as Free Open Source software
+ * conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
+ * The software and documentation is provided by its authors/distributors
+ * "as is" and no expressed or
+ * implied warranty is given for its use, quality or fitness for a
+ * particular case.
+ ****************************************************************************
+ * Filename: DeployServicesForm.java
+ ****************************************************************************
+ * @author Daniele Strollo
+ ***************************************************************************/
+
+package org.gcube.portlets.admin.resourcemanagement.client.forms;
+
+import java.util.List;
+import java.util.Vector;
+import org.gcube.portlets.admin.resourcemanagement.client.remote.ProxyRegistry;
+import org.gcube.portlets.admin.resourcemanagement.client.utils.Callbacks;
+import org.gcube.portlets.admin.resourcemanagement.client.utils.Commands;
+import org.gcube.portlets.admin.resourcemanagement.client.views.resourcedetails.ResourceGridFactory;
+import org.gcube.portlets.admin.resourcemanagement.client.widgets.console.ConsoleMessageBroker;
+import org.gcube.portlets.admin.resourcemanagement.client.widgets.registry.UIIdentifiers;
+import org.gcube.resourcemanagement.support.client.utils.StatusHandler;
+import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
+import org.gcube.resourcemanagement.support.shared.operations.SupportedOperations;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDetailModel;
+
+import com.extjs.gxt.ui.client.Style.Orientation;
+import com.extjs.gxt.ui.client.data.ModelData;
+import com.extjs.gxt.ui.client.event.ComponentEvent;
+import com.extjs.gxt.ui.client.event.Listener;
+import com.extjs.gxt.ui.client.event.MessageBoxEvent;
+import com.extjs.gxt.ui.client.store.ListStore;
+import com.extjs.gxt.ui.client.store.StoreSorter;
+import com.extjs.gxt.ui.client.util.Margins;
+import com.extjs.gxt.ui.client.widget.Component;
+import com.extjs.gxt.ui.client.widget.ContentPanel;
+import com.extjs.gxt.ui.client.widget.MessageBox;
+import com.extjs.gxt.ui.client.widget.Text;
+import com.extjs.gxt.ui.client.widget.Window;
+import com.extjs.gxt.ui.client.widget.button.Button;
+import com.extjs.gxt.ui.client.widget.form.DualListField;
+import com.extjs.gxt.ui.client.widget.form.FormPanel;
+import com.extjs.gxt.ui.client.widget.form.ListField;
+import com.extjs.gxt.ui.client.widget.grid.Grid;
+import com.extjs.gxt.ui.client.widget.layout.FitLayout;
+import com.extjs.gxt.ui.client.widget.layout.FormData;
+import com.extjs.gxt.ui.client.widget.layout.RowData;
+import com.extjs.gxt.ui.client.widget.layout.RowLayout;
+import com.extjs.gxt.ui.client.widget.menu.Menu;
+import com.extjs.gxt.ui.client.widget.menu.MenuItem;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+
+/**
+ * @author Daniele Strollo
+ * @author Massimiliano Assante (ISTI-CNR)
+ * @version 2.1 APR 2012
+ */
+public class DeployServicesForm {
+ private ContentPanel rootPanel = null;
+ private ContentPanel ghnContainer = null;
+ private ContentPanel serviceContainer = null;
+ private final ListStore GHNstore = new ListStore();
+ private final ListStore selectedGHNs = new ListStore();
+ private final Window window = new Window();
+ private int resourceLoaded = 0;
+
+
+ public DeployServicesForm() {
+ this.ghnContainer = new ContentPanel(new FitLayout());
+ this.serviceContainer = new ContentPanel(new FitLayout());
+
+ this.ghnContainer.getHeader().setStyleName("x-hide-panel-header");
+ this.ghnContainer.setHeaderVisible(false);
+ this.serviceContainer.getHeader().setStyleName("x-hide-panel-header");
+ this.serviceContainer.setHeaderVisible(false);
+
+ this.ghnContainer.add(new Text());
+ this.serviceContainer.add(new Text());
+ this.init();
+ }
+
+ private void markResourceLoaded() {
+ this.resourceLoaded++;
+ if (this.resourceLoaded >= 2) {
+ Commands.unmask(Commands.getViewport());
+ Commands.unmask(this.rootPanel);
+ }
+ }
+
+ private void loadGHNs(final String scope) {
+ ProxyRegistry.getProxyInstance().getResourcesModel(scope,
+ ResourceTypeDecorator.GHN.name(),
+ null,
+ null,
+ new AsyncCallback>() {
+
+ public void onSuccess(final List result) {
+ ghnContainer.removeAll();
+ ghnContainer.add(createGHNForm());
+ GHNstore.add(result);
+ ghnContainer.layout(true);
+ Commands.showPopup("GHN load", "Loaded " + result.size() + " GHNs");
+ markResourceLoaded();
+ }
+ public void onFailure(final Throwable caught) {
+ markResourceLoaded();
+ }
+ });
+ }
+
+ private void closeDialog() {
+ this.window.hide();
+ }
+
+ private Component createGHNForm() {
+ FormPanel panel = new FormPanel();
+ panel.setFrame(true);
+ panel.getHeader().setStyleName("x-hide-panel-header");
+
+ DualListField lists = new DualListField();
+ lists.setFieldLabel("GHNs");
+
+ ListField from = lists.getFromList();
+ from.setDisplayField("name");
+ GHNstore.setStoreSorter(new StoreSorter());
+ GHNstore.setSortField("name");
+ from.setStore(GHNstore);
+ ListField to = lists.getToList();
+ to.setDisplayField("name");
+ to.setStore(this.selectedGHNs);
+
+ panel.addButton(new Button("Cancel") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ super.onClick(ce);
+ closeDialog();
+ }
+ });
+ panel.addButton(new Button("Apply Deploy") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ super.onClick(ce);
+ MessageBox.confirm("Software Deployment",
+ "Are you sure you want to apply the deployment plan?",
+ new Listener() {
+ public void handleEvent(final MessageBoxEvent be) {
+ if (be.getButtonClicked().getItemId().equalsIgnoreCase("yes")) {
+ // - THE OPERATION IS CONFIRMED
+ List ghns = getSelectedGHNs();
+ List sw = getSelectedSoftwares();
+
+ if (ghns == null || ghns.size() == 0) {
+ MessageBox.alert("Service Deployment", "No GHNs have been selected", null);
+ return;
+ }
+ if (sw == null || sw.size() == 0) {
+ MessageBox.alert("Service Deployment", "No softwares have been selected", null);
+ return;
+ }
+
+ List ghnNames = new Vector();
+ for (ModelData m : ghns) {
+ String name = m.get("name").toString();
+ ghnNames.add(name);
+ }
+ List swIDs = new Vector();
+ for (ModelData m : sw) {
+ swIDs.add(((Object) m.get("ID")).toString());
+ }
+ ConsoleMessageBroker.info(this, "Applying deployment of " + swIDs.size() + " softwares on " + ghnNames.size() + " gHNs");
+ Commands.mask("Waiting the deployment report", UIIdentifiers.GLOBAL_STATUS_BAR_ID);
+ ProxyRegistry.getProxyInstance().deploy(
+ ghnNames,
+ swIDs,
+ new AsyncCallback() {
+ public void onSuccess(final String result) {
+ if (result != null) {
+ MessageBox.info("Service Deployment",
+ "The required deployment has been applied.
" +
+ "The generated report ID is:
" +
+ "" + result + "",
+ null);
+ ProxyRegistry.getProxyInstance().checkDeployStatus(
+ StatusHandler.getStatus().getCurrentScope(),
+ result.trim(),
+ Callbacks.handleGetDeploymentReport);
+ } else {
+ MessageBox.alert("Service Deployment",
+ "The required deployment has been applied.
" +
+ "But the resulting report ID is null or invalid.",
+ null);
+ Commands.unmask(UIIdentifiers.GLOBAL_STATUS_BAR_ID);
+ }
+ }
+ public void onFailure(final Throwable caught) {
+ Commands.unmask(UIIdentifiers.GLOBAL_STATUS_BAR_ID);
+ MessageBox.alert("Service Deployment error",
+ "The required deployment has not been applied. " +
+ "Received exception:
" + caught.getMessage(),
+ null);
+ }
+ });
+
+ closeDialog();
+ }
+ }
+ });
+
+ }
+ });
+
+ panel.add(lists, new FormData("100%"));
+ return panel;
+ }
+
+ private List getSelectedGHNs() {
+ return this.selectedGHNs.getModels();
+ }
+
+ private List getSelectedSoftwares() {
+ List retval = new Vector();
+ if (serviceContainer.getWidget(0) == null ||
+ !(serviceContainer.getWidget(0) instanceof Grid)) {
+ return null;
+ }
+ @SuppressWarnings("unchecked")
+ Grid grid = (Grid) serviceContainer.getWidget(0);
+ if (grid.getSelectionModel().getSelectedItems() == null) {
+ return null;
+ }
+ Object toDeploy = null;
+ for (ModelData m : grid.getStore().getModels()) {
+ toDeploy = m.get(ResourceDetailModel.SERVICE_INSTALL_KEY);
+ if (toDeploy != null && Boolean.parseBoolean(toDeploy.toString())) {
+ retval.add(m);
+ }
+ }
+ return retval;
+ }
+
+ private void loadSoftwares(final String scope) {
+
+ ProxyRegistry.getProxyInstance().getResourcesByType(
+ scope,
+ ResourceTypeDecorator.Service.name(),
+ new AsyncCallback>() {
+
+ public void onSuccess(final List result) {
+ Grid grid =
+ ResourceGridFactory.createGrid(ResourceTypeDecorator.InstallableSoftware.name(),
+ result,
+ null,
+ false);
+
+ /******************************************
+ * ADD TO INSTALL FEATURE
+ *****************************************/
+ // 0 - INSTALL button
+ MenuItem toInstall = new MenuItem("Mark for install") {
+ @Override
+ protected void onClick(final ComponentEvent be) {
+ super.onClick(be);
+
+ if (serviceContainer.getWidget(0) == null ||
+ !(serviceContainer.getWidget(0) instanceof Grid)) {
+ return;
+ }
+ @SuppressWarnings("unchecked")
+ Grid grid = (Grid) serviceContainer.getWidget(0);
+ if (grid.getSelectionModel().getSelectedItems() == null) {
+ return;
+ }
+
+ for (ModelData e : grid.getSelectionModel().getSelectedItems()) {
+ ConsoleMessageBroker.info(this, "Required install for: " + e.get("ServiceName") + " " + e.get("ID"));
+ if (e.getProperties().containsKey(ResourceDetailModel.SERVICE_INSTALL_KEY) &&
+ Boolean.parseBoolean(((Object) e.get(ResourceDetailModel.SERVICE_INSTALL_KEY)).toString()))
+ {
+ e.set(ResourceDetailModel.SERVICE_INSTALL_KEY, false);
+ } else {
+ e.set(ResourceDetailModel.SERVICE_INSTALL_KEY, true);
+ }
+ grid.getStore().update(e);
+ }
+ }
+ };
+ Commands.evaluateCredentials(
+ toInstall,
+ SupportedOperations.SERVICE_DEPLOY.getPermissions());
+
+ Menu menu = new Menu();
+ menu.add(toInstall);
+ grid.setContextMenu(menu);
+ /******************************************
+ * ENDOF ADD TO INSTALL FEATURE
+ *****************************************/
+
+ serviceContainer.removeAll();
+ serviceContainer.add(grid);
+ serviceContainer.layout(true);
+ Commands.showPopup("Service load", "Loaded " + result.size() + " services");
+ markResourceLoaded();
+ }
+
+ public void onFailure(final Throwable caught) {
+ markResourceLoaded();
+ }
+ });
+ }
+
+ private void init() {
+ this.rootPanel = new ContentPanel();
+ this.rootPanel.getHeader().setStyleName("x-hide-panel-header");
+ this.rootPanel.setHeaderVisible(false);
+ this.rootPanel.setLayout(new RowLayout(Orientation.VERTICAL));
+
+ this.rootPanel.add(this.ghnContainer, new RowData(1, .4, new Margins(4)));
+ this.rootPanel.add(this.serviceContainer, new RowData(1, .6, new Margins(0, 4, 0, 4)));
+
+ String scope = StatusHandler.getStatus().getCurrentScope();
+
+ Commands.mask("Loading Deployment Resources in scope: " + scope, Commands.getViewport());
+ Commands.mask("Loading Deployment Resources in scope: " + scope, this.rootPanel);
+
+ this.loadGHNs(scope);
+ this.loadSoftwares(scope);
+ }
+
+ public final void show() {
+ window.setPlain(true);
+ window.setSize(800, 600);
+ window.setHeading("Software Deployment");
+ window.setLayout(new FitLayout());
+ window.add(this.rootPanel);
+ window.show();
+ window.layout(true);
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/ActivationRecordVMForm.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/ActivationRecordVMForm.java
new file mode 100644
index 0000000..7c3d086
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/ActivationRecordVMForm.java
@@ -0,0 +1,420 @@
+/****************************************************************************
+= * This software is part of the gCube Project.
+ * Site: http://www.gcube-system.org/
+ ****************************************************************************
+ * The gCube/gCore software is licensed as Free Open Source software
+ * conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
+ * The software and documentation is provided by its authors/distributors
+ * "as is" and no expressed or
+ * implied warranty is given for its use, quality or fitness for a
+ * particular case.
+ ****************************************************************************
+ * Filename: ActivationRecordVMForm.java
+ ****************************************************************************
+ * @author Daniele Strollo
+ ***************************************************************************/
+
+package org.gcube.portlets.admin.resourcemanagement.client.forms.genericresources;
+
+import java.util.List;
+import java.util.Vector;
+import org.gcube.portlets.admin.resourcemanagement.client.remote.ProxyRegistry;
+import org.gcube.portlets.admin.resourcemanagement.client.utils.Commands;
+import org.gcube.portlets.admin.resourcemanagement.client.utils.OpCommands;
+
+
+import org.gcube.resourcemanagement.support.client.utils.StatusHandler;
+import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
+import org.gcube.resourcemanagement.support.client.views.validators.SelectValidator;
+import org.gcube.resourcemanagement.support.shared.exceptions.InvalidParameterException;
+import org.gcube.resourcemanagement.support.shared.types.Tuple;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.AtomicTreeNode;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor;
+
+import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
+import com.extjs.gxt.ui.client.Style.Scroll;
+import com.extjs.gxt.ui.client.data.ModelData;
+import com.extjs.gxt.ui.client.event.ComponentEvent;
+import com.extjs.gxt.ui.client.store.ListStore;
+import com.extjs.gxt.ui.client.widget.Dialog;
+import com.extjs.gxt.ui.client.widget.HorizontalPanel;
+import com.extjs.gxt.ui.client.widget.MessageBox;
+import com.extjs.gxt.ui.client.widget.button.Button;
+import com.extjs.gxt.ui.client.widget.form.ComboBox;
+import com.extjs.gxt.ui.client.widget.form.Field;
+import com.extjs.gxt.ui.client.widget.form.FieldSet;
+import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
+import com.extjs.gxt.ui.client.widget.form.FormPanel;
+import com.extjs.gxt.ui.client.widget.form.TextArea;
+import com.extjs.gxt.ui.client.widget.form.TextField;
+import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
+import com.extjs.gxt.ui.client.widget.layout.FitLayout;
+import com.extjs.gxt.ui.client.widget.layout.FormData;
+import com.extjs.gxt.ui.client.widget.layout.FormLayout;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+enum StaticFields {
+ VIEW_NAME("name", "e.g.: the name of the property", "e.g.: put here the name"),
+ METADATA_NAME("schemaName", "e.g.: metadata prefix", "e.g.: FARM_dc"),
+ METADATA_LANG("language", "e.g.: metadata language", "e.g.: en"),
+ METADATA_SCHEMA("schemaURI", "e.g.: metadata schema", "e.g.: http://193.43.36.238:8282/fi/figis/devcon/schema/dc/qualifieddc.xsd"),
+ IS_EDITABLE("isEditable", "e.g.: editable", "e.g.: true"),
+ IS_INDEXABLE("isIndexable", "e.g.: indexable", "e.g.: true"),
+ IS_USER_COLLECTION("isUserCollection", "e.g.: user collection", "e.g.: true");
+
+ private String name = null;
+ private String description = null;
+ private String value = null;
+
+
+ private StaticFields(final String name, final String description, final String value) {
+ this.name = name;
+ this.description = description;
+ this.value = value;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
+
+public class ActivationRecordVMForm extends Dialog {
+ private FormData formData = null;
+ private FormPanel form = null;
+
+ public ActivationRecordVMForm() {
+ this.setLayout(new FitLayout());
+ this.setHeading("Activation Record for VM");
+ this.setModal(true);
+ this.setWidth(700);
+ this.setHeight(500);
+ this.setResizable(false);
+ this.getButtonBar().removeAll();
+ this.setHideOnButtonClick(true);
+ }
+
+ @Override
+ protected final void onRender(final Element parent, final int index) {
+ super.onRender(parent, index);
+ formData = new FormData("-20");
+ createForm();
+ }
+
+ public final void closeDialog() {
+ this.hide();
+ }
+
+ private void addStaticProperty(final String pfield, final String pdescription, final String pvalue) {
+ final FieldSet fieldSet = new FieldSet();
+ fieldSet.setLayout(new FormLayout());
+
+ fieldSet.setHeading("Property");
+ fieldSet.setCollapsible(false);
+
+ TextField name = new TextField();
+ name.setFieldLabel("Name");
+ name.setValue(pfield);
+ name.setEnabled(false);
+ name.setAllowBlank(false);
+ fieldSet.add(name, formData);
+
+ TextField description = new TextField();
+ description.setFieldLabel("Description");
+ description.setEmptyText(pdescription);
+ description.setAllowBlank(true);
+ fieldSet.add(description, formData);
+
+ TextField value = new TextField();
+ value.setFieldLabel("Value");
+ value.setEmptyText(pvalue);
+ value.setAllowBlank(false);
+ fieldSet.add(value, formData);
+
+ form.add(fieldSet, formData);
+ fieldSet.recalculate();
+ this.doLayout(true);
+ }
+
+ private void addProperty() {
+ final FieldSet fieldSet = new FieldSet();
+ fieldSet.setLayout(new FormLayout());
+
+ fieldSet.setHeading("Property");
+ fieldSet.setCollapsible(false);
+
+ TextField name = new TextField();
+ name.setFieldLabel("Name");
+ name.setAllowBlank(false);
+ fieldSet.add(name, formData);
+
+ TextField description = new TextField();
+ description.setFieldLabel("Description");
+ description.setAllowBlank(true);
+ fieldSet.add(description, formData);
+
+ TextField value = new TextField();
+ value.setFieldLabel("Value");
+ value.setAllowBlank(false);
+ fieldSet.add(value, formData);
+
+ final HorizontalPanel buttonPanel = new HorizontalPanel();
+ Button addButton = new Button("Add New Property") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ addProperty();
+ }
+ };
+ addButton.setIconStyle("new-icon");
+ buttonPanel.add(addButton);
+
+ Button delButton = new Button("Remove This Property") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ form.remove(fieldSet);
+ }
+ };
+ delButton.setIconStyle("delete-icon");
+ buttonPanel.add(delButton);
+ fieldSet.add(buttonPanel, formData);
+
+ form.add(fieldSet, formData);
+ fieldSet.recalculate();
+ this.doLayout(true);
+ }
+
+ private void createForm() {
+ form = new FormPanel();
+ form.setFrame(true);
+ form.setAutoWidth(true);
+
+ //form.setLayout(new FlowLayout());
+ form.setScrollMode(Scroll.AUTO);
+
+ form.setHeaderVisible(false);
+ form.getHeader().setStyleName("x-hide-panel-header");
+
+ TextField resID = new TextField();
+ resID.setFieldLabel("Resource ID");
+ resID.setEnabled(false);
+ resID.setAllowBlank(true); // is required
+
+ resID.setEmptyText("");
+
+ form.add(resID, formData);
+
+ TextField resName = new TextField();
+ resName.setFieldLabel("Resource Name");
+ resName.setValue("VMRecord");
+ resName.setEnabled(false);
+ //resName.setValidator(new StringValidator(20, false));
+ resName.setAllowBlank(false); // is required
+ form.add(resName, formData);
+
+ TextField resType = new TextField();
+ resType.setFieldLabel("Secondary type");
+ resType.setValue("ActivationRecord");
+ resType.setEnabled(false);
+ // resType.setValidator(new StringValidator(20, false));
+ resType.setAllowBlank(false); // is required
+ form.add(resType, formData);
+
+ TextArea description = new TextArea();
+ description.setFieldLabel("Description");
+ form.add(description, formData);
+
+ ComboBox pluginSelect = new ComboBox();
+ ListStore storePlugin = new ListStore();
+ storePlugin.add(new AtomicTreeNode("Metadata"));
+ storePlugin.add(new AtomicTreeNode("Annotation"));
+ pluginSelect.setStore(storePlugin);
+ pluginSelect.setFieldLabel("Plugin Kind:");
+ pluginSelect.setEmptyText("Select a plugin...");
+ pluginSelect.setTypeAhead(true);
+ pluginSelect.setTriggerAction(TriggerAction.ALL);
+ pluginSelect.setDisplayField("name");
+ pluginSelect.setForceSelection(true);
+ form.add(pluginSelect, formData);
+
+ // The select for collections
+ ComboBox collectionSelect = new ComboBox();
+ ListStore store = new ListStore();
+ try {
+ store.add(new ResourceDescriptor("type", "subtype", "ID", "the name"));
+ } catch (InvalidParameterException e) {
+ e.printStackTrace();
+ }
+ collectionSelect.setStore(store);
+ collectionSelect.setFieldLabel("Collection");
+ collectionSelect.setEmptyText("Select a collection...");
+ collectionSelect.setDisplayField("name");
+ collectionSelect.setTypeAhead(true);
+ collectionSelect.setTriggerAction(TriggerAction.ALL);
+ collectionSelect.setForceSelection(true);
+ collectionSelect.setData("text", "Select a collection");
+
+ form.add(collectionSelect, formData);
+
+ loadCollections(StatusHandler.getStatus().getCurrentScope(), collectionSelect);
+ // -- ENDOF The select for collections
+
+ // Inserts the static fields
+ for (StaticFields entry : StaticFields.values()) {
+ this.addStaticProperty(entry.getName(), entry.getDescription(), entry.getValue());
+ }
+
+ HorizontalPanel buttonPanel = new HorizontalPanel();
+ Button addButton = new Button("Add New Property") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ addProperty();
+ }
+ };
+ addButton.setIconStyle("new-icon");
+ buttonPanel.add(addButton);
+
+ form.add(buttonPanel, formData);
+
+ Button submitBtn = new Button("Submit") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ super.onClick(ce);
+ if (!form.isValid()) {
+ return;
+ }
+
+ List> fields = form.getFields();
+
+ // Creation mode
+ // the parameter in position 0 is the
+ // auto-generated ID.
+ String resName = fields.get(1).getRawValue();
+ String resType = fields.get(2).getRawValue();
+ String description = fields.get(3).getRawValue();
+ String plugin = fields.get(4).getRawValue() + "Plugin";
+ String viewType = fields.get(4).getRawValue() + "View";
+ String viewID = generateID();
+
+ String collectionID = ((ResourceDescriptor) fields.get(5).getValue()).getID();
+
+ // builds a list of tuples each one representing a single property
+ // properties are supposed to be represented by three fields each one.
+ List> properties = new Vector>();
+ if (fields.size() > StaticFields.values().length - 1) {
+ for (int i = StaticFields.values().length - 1; i < fields.size(); i = i + 3) {
+ properties.add(new Tuple(
+ fields.get(i).getRawValue().trim(),
+ (fields.get(i + 1).getRawValue() != null) ? fields.get(i + 1).getRawValue().trim() : "", // description can be null
+ fields.get(i + 2).getRawValue().trim()));
+ }
+ } else {
+ MessageBox.alert("Create Activation Form for VM", "No properties defined", null);
+ return;
+ }
+
+ StringBuilder body = new StringBuilder();
+
+ body.append("");
+ body.append("ResourceManagementPortlet");
+ body.append("" + plugin + "");
+
+ body.append("");
+
+ body.append("" + viewID + "");
+ body.append("" + collectionID + "");
+ body.append("" + viewType + "");
+ body.append("");
+ body.append("" + fields.get(4).getRawValue() + " view for collection " + collectionID + "");
+ body.append("0");
+ body.append("" + "2010-10-25T14:01:55.948+00:00" + "");
+
+ for (Tuple prop : properties) {
+ body.append("");
+
+ body.append("" + prop.get(0) + "");
+ body.append("" + prop.get(1) + "");
+ body.append("" + prop.get(2) + "");
+
+ body.append("");
+ }
+
+ body.append("");
+ body.append("");
+
+ OpCommands.doCreateGenericResource(viewID, resName, description, body.toString(), resType);
+ closeDialog();
+ }
+ };
+ form.addButton(submitBtn);
+ form.addButton(new Button("Cancel") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ super.onClick(ce);
+ closeDialog();
+ }
+ });
+
+ form.setButtonAlign(HorizontalAlignment.CENTER);
+
+ FormButtonBinding binding = new FormButtonBinding(form);
+ binding.addButton(submitBtn);
+
+ this.add(form);
+ }
+
+ private String generateID() {
+ char[] s = new char[36];
+ String itoh = "0123456789abcdef";
+
+ // Make array of random hex digits. The UUID only has 32 digits in it, but we
+ // allocate an extra items to make room for the '-'s we'll be inserting.
+ for (int i = 0; i < 36; i++) {
+ s[i] = (char) Math.floor(Math.random() * 0x10);
+ }
+
+ // Conform to RFC-4122, section 4.4
+ s[14] = 4; // Set 4 high bits of time_high field to version
+ s[19] = (char) ((s[19] & 0x3) | 0x8); // Specify 2 high bits of clock sequence
+
+ // Convert to hex chars
+ for (int i = 0; i < 36; i++) {
+ s[i] = itoh.charAt((int) s[i]);
+ }
+
+ // Insert '-'s
+ s[8] = s[13] = s[18] = s[23] = '-';
+ return new String(s);
+ }
+
+ private void loadCollections(final String scope, final ComboBox combo) {
+ ProxyRegistry.getProxyInstance().getResourcesModel(scope,
+ ResourceTypeDecorator.GenericResource.name(),
+ "GCUBECollection",
+ null,
+ new AsyncCallback>() {
+
+ public void onSuccess(final List result) {
+ combo.getStore().removeAll();
+ combo.getStore().add(result);
+
+ combo.setValidator(new SelectValidator(false));
+ combo.setAllowBlank(false);
+ combo.setTriggerAction(TriggerAction.ALL);
+ combo.recalculate();
+ Commands.showPopup("Collection load", "Loaded (" + result.size() + ") Collections");
+ }
+ public void onFailure(final Throwable e) {
+ MessageBox.alert("Error getting collections", e.getMessage(), null);
+ }
+ });
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/DeployVirtualCollection.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/DeployVirtualCollection.java
new file mode 100644
index 0000000..16ec8b1
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/DeployVirtualCollection.java
@@ -0,0 +1,173 @@
+/****************************************************************************
+ * This software is part of the gCube Project.
+ * Site: http://www.gcube-system.org/
+ ****************************************************************************
+ * The gCube/gCore software is licensed as Free Open Source software
+ * conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
+ * The software and documentation is provided by its authors/distributors
+ * "as is" and no expressed or
+ * implied warranty is given for its use, quality or fitness for a
+ * particular case.
+ ****************************************************************************
+ * Filename: DeployVirtualCollection.java
+ ****************************************************************************
+ * @author Daniele Strollo
+ ***************************************************************************/
+
+package org.gcube.portlets.admin.resourcemanagement.client.forms.genericresources;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+import org.gcube.portlets.admin.resourcemanagement.client.remote.ProxyRegistry;
+import org.gcube.portlets.admin.resourcemanagement.client.utils.Commands;
+import org.gcube.portlets.admin.resourcemanagement.client.widgets.console.ConsoleMessageBroker;
+
+import org.gcube.resourcemanagement.support.client.utils.StatusHandler;
+import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
+import org.gcube.resourcemanagement.support.shared.exceptions.InvalidParameterException;
+import org.gcube.resourcemanagement.support.shared.types.Tuple;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.AtomicTreeNode;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor;
+import com.extjs.gxt.ui.client.data.ModelData;
+import com.extjs.gxt.ui.client.event.ComponentEvent;
+import com.extjs.gxt.ui.client.store.ListStore;
+import com.extjs.gxt.ui.client.widget.Dialog;
+import com.extjs.gxt.ui.client.widget.MessageBox;
+import com.extjs.gxt.ui.client.widget.button.Button;
+import com.extjs.gxt.ui.client.widget.form.FormPanel;
+import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
+import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
+import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
+import com.extjs.gxt.ui.client.widget.grid.Grid;
+import com.extjs.gxt.ui.client.widget.layout.FitLayout;
+import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+/**
+ * @author Daniele Strollo (ISTI-CNR)
+ *
+ */
+public class DeployVirtualCollection extends Dialog {
+ private Grid grid = null;
+
+ public DeployVirtualCollection() {
+ this.setLayout(new FitLayout());
+ this.setHeading("Deploy Virtual Collections");
+ this.setModal(true);
+ this.setWidth(700);
+ this.setHeight(500);
+ this.setResizable(false);
+ //this.getButtonBar().removeAll();
+ this.setHideOnButtonClick(true);
+ }
+
+ protected final void onRender(final Element parent, final int index) {
+ super.onRender(parent, index);
+ initForm();
+ }
+
+ private void closeDialog() {
+ this.hide();
+ }
+
+ private void initForm() {
+ String scope = StatusHandler.getStatus().getCurrentScope();
+ FormPanel form = new FormPanel();
+ form.setFrame(true);
+ form.setAutoWidth(true);
+
+ initModel(scope);
+ this.add(grid);
+
+ this.getButtonBar().removeAll();
+ this.getButtonBar().add(new FillToolItem());
+ this.getButtonBar().add(new Button("Cancel") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ super.onClick(ce);
+ closeDialog();
+ }
+ });
+ this.getButtonBar().add(new Button("Submit") {
+ @Override
+ protected void onClick(final ComponentEvent ce) {
+ super.onClick(ce);
+ for (ResourceDescriptor elem : grid.getSelectionModel().getSelectedItems()) {
+ ConsoleMessageBroker.info(this, "Selected: " + elem.getID());
+
+ String body = "";
+ if (elem.getProperty("body") != null) {
+ body = ((Object) elem.getProperty("body")).toString().trim();
+ if (body.startsWith("")) {
+ body = body.replace("", "").trim();
+ body = body.substring(0, body.lastIndexOf("")).trim();
+ }
+ }
+
+ ProxyRegistry.getProxyInstance().createGenericResource(
+ null, // id auto-provided
+ "CMSRecord", // name fixed
+ "Activation Record for collection " + elem.getName(), // description
+ body, // the body
+ "ActivationRecord", // the subtype
+ new AsyncCallback() {
+ public void onSuccess(final String result) {
+ Commands.showPopup("Deploy Virtual Collection", "Deployed virtual collection with id " + result);
+ }
+ public void onFailure(final Throwable caught) {
+ Commands.showPopup("Deploy Virtual Collection", "Creation failed " + caught.getMessage());
+ }
+ });
+ }
+ closeDialog();
+ }
+ });
+
+ updateGrid(scope);
+ }
+
+ private void initModel(final String scope) {
+ // loads the model of generic resources
+ final List modelColumns = new ArrayList();
+ modelColumns.add(new ColumnConfig("name", "Name", 300));
+ //modelColumns.add(new ColumnConfig("subtype", "Secondary Type", 170));
+ modelColumns.add(new ColumnConfig("ID", "ID", 300));
+ modelColumns.add(new ColumnConfig("description", "Description", 300));
+ final ColumnModel cm = new ColumnModel(modelColumns);
+
+ final CheckBoxSelectionModel sm = new CheckBoxSelectionModel();
+ // adds the checkbox at the beginning
+ modelColumns.add(0, sm.getColumn());
+ ListStore store = new ListStore();
+ this.grid = new Grid(store, cm);
+ }
+
+ private void updateGrid(final String scope) {
+ final List> additionalFields = new Vector>();
+ additionalFields.add(new Tuple("description", "//Profile/Description/text()"));
+ additionalFields.add(new Tuple("body", "//Profile/Body"));
+
+ ProxyRegistry.getProxyInstance().getResourcesModel(scope,
+ ResourceTypeDecorator.GenericResource.name(),
+ "VirtualCollection",
+ additionalFields,
+ new AsyncCallback>() {
+ public void onSuccess(final List result) {
+ if (result == null || result.size() == 0) {
+ MessageBox.alert("Deploy Virtual Collections", "No deployable resources found in the current scope",
+ null);
+ closeDialog();
+ } else {
+ grid.getStore().removeAll();
+ grid.getStore().add(result);
+ }
+ }
+ public void onFailure(final Throwable caught) {
+ ConsoleMessageBroker.error(this, caught.getMessage());
+ }
+ });
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/GenericResourceCMForm.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/GenericResourceCMForm.java
new file mode 100644
index 0000000..d2355bf
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/forms/genericresources/GenericResourceCMForm.java
@@ -0,0 +1,329 @@
+/****************************************************************************
+ * This software is part of the gCube Project.
+ * Site: http://www.gcube-system.org/
+ ****************************************************************************
+ * The gCube/gCore software is licensed as Free Open Source software
+ * conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
+ * The software and documentation is provided by its authors/distributors
+ * "as is" and no expressed or
+ * implied warranty is given for its use, quality or fitness for a
+ * particular case.
+ ****************************************************************************
+ * Filename: GenericResourcePluginForm.java
+ ****************************************************************************
+ * @author Daniele Strollo
+ ***************************************************************************/
+
+package org.gcube.portlets.admin.resourcemanagement.client.forms.genericresources;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.gcube.portlets.admin.resourcemanagement.client.remote.ProxyRegistry;
+import org.gcube.portlets.admin.resourcemanagement.client.utils.OpCommands;
+import org.gcube.resourcemanagement.support.client.views.validators.SelectValidator;
+import org.gcube.resourcemanagement.support.shared.plugins.GenericResourcePlugin;
+import org.gcube.resourcemanagement.support.shared.types.Tuple;
+import org.gcube.resourcemanagement.support.shared.types.datamodel.AtomicTreeNode;
+
+import com.extjs.gxt.ui.client.Style.Scroll;
+import com.extjs.gxt.ui.client.data.ModelData;
+import com.extjs.gxt.ui.client.event.ComponentEvent;
+import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
+import com.extjs.gxt.ui.client.event.SelectionChangedListener;
+import com.extjs.gxt.ui.client.store.ListStore;
+import com.extjs.gxt.ui.client.widget.Component;
+import com.extjs.gxt.ui.client.widget.Dialog;
+import com.extjs.gxt.ui.client.widget.MessageBox;
+import com.extjs.gxt.ui.client.widget.button.Button;
+import com.extjs.gxt.ui.client.widget.form.ComboBox;
+import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
+import com.extjs.gxt.ui.client.widget.form.Field;
+import com.extjs.gxt.ui.client.widget.form.FieldSet;
+import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
+import com.extjs.gxt.ui.client.widget.form.FormPanel;
+import com.extjs.gxt.ui.client.widget.form.TextArea;
+import com.extjs.gxt.ui.client.widget.form.TextField;
+import com.extjs.gxt.ui.client.widget.layout.FitLayout;
+import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
+import com.extjs.gxt.ui.client.widget.layout.FormData;
+import com.extjs.gxt.ui.client.widget.layout.FormLayout;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+public class GenericResourceCMForm extends Dialog {
+ private FormData formData = null;
+ private FormPanel form = null;
+ private FieldSet pluginFieldSet = null;
+ private String selectedPlugin = null;
+ private Map loadedPlugins = null;
+ private TextField resName = null;
+
+ public GenericResourceCMForm() {
+ this.setLayout(new FitLayout());
+ this.setHeading("Generic Resource Creation (Plugin)");
+ this.setModal(true);
+ this.setWidth(700);
+ this.setHeight(500);
+ this.setResizable(false);
+ this.getButtonBar().removeAll();
+ this.setHideOnButtonClick(true);
+ }
+
+ @Override
+ protected final void onRender(final Element parent, final int index) {
+ super.onRender(parent, index);
+ formData = new FormData("-20");
+ createForm();
+ createPluginForm();
+ this.add(form);
+
+ this.initButtons();
+
+ this.recalculate();
+ this.doLayout(true);
+
+ this.form.mask("Loading plugins...");
+ // Gets the plugins
+ ProxyRegistry.getProxyInstance().getGenericResourcePlugins(new AsyncCallback