diff --git a/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CacheStoreContext.java b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CacheStoreContext.java new file mode 100644 index 000000000..f4d704bb2 --- /dev/null +++ b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CacheStoreContext.java @@ -0,0 +1,31 @@ +package org.jboss.as.console.client.shared.subsys.infinispan.v3; + +import org.jboss.as.console.mbui.widgets.ModelNodeFormBuilder; + +public class CacheStoreContext { + private String storeName; + private ModelNodeFormBuilder.FormAssets formAssets; + + public static enum State { + TYPE, ATTRIBUTES + } + + public CacheStoreContext() { + } + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public ModelNodeFormBuilder.FormAssets getFormAssets() { + return formAssets; + } + + public void setFormAssets(ModelNodeFormBuilder.FormAssets formAssets) { + this.formAssets = formAssets; + } +} diff --git a/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CachesPresenter.java b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CachesPresenter.java index f4d418d1c..1b2d2944d 100644 --- a/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CachesPresenter.java +++ b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CachesPresenter.java @@ -20,7 +20,6 @@ */ import com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.core.client.GWT; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.inject.Inject; @@ -34,7 +33,6 @@ import com.gwtplatform.mvp.shared.proxy.PlaceRequest; import org.jboss.as.console.client.Console; import org.jboss.as.console.client.core.NameTokens; -import org.jboss.as.console.client.core.UIMessages; import org.jboss.as.console.client.domain.model.SimpleCallback; import org.jboss.as.console.client.rbac.SecurityFramework; import org.jboss.as.console.client.shared.subsys.Baseadress; @@ -256,13 +254,19 @@ public SecurityFramework getSecurityFramework() { return securityFramework; } - public void onCreate(AddressTemplate address, String name, ModelNode entity) { + onCreate(address, name, entity, false); + } + + public void onCreate(AddressTemplate address, String name, ModelNode entity, boolean allowRestart) { ResourceAddress fqAddress = address.resolve(statementContext, container,name); entity.get(OP).set(ADD); entity.get(ADDRESS).set(fqAddress); + if (allowRestart) { + entity.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); + } dispatcher.execute(new DMRAction(entity), new SimpleCallback() { @@ -363,7 +367,11 @@ public void onCancel() { dialog.center(); } - public void onRemoveCache(AddressTemplate cacheType, String name) { + public void onLaunchAddStoreWizard(AddressTemplate storeType, String name) { + new NewCacheStoreWizard(this, storeType, name).open(Console.MESSAGES.createTitle("Store")); + } + + public void onRemoveResource(AddressTemplate cacheType, String name) { ResourceAddress fqAddress = cacheType.resolve(statementContext, container, name); diff --git a/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CommonCacheAttributes.java b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CommonCacheAttributes.java index 3425ae623..46f2261d7 100644 --- a/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CommonCacheAttributes.java +++ b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/CommonCacheAttributes.java @@ -9,6 +9,7 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.cellview.client.TextColumn; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.view.client.ListDataProvider; @@ -59,6 +60,7 @@ public class CommonCacheAttributes { private SingleSelectionModel selectionModel; private Map formMapping = new HashMap<>(); + private StoreFormWrapper storeForm; public CommonCacheAttributes(CachesPresenter presenter, String title, AddressTemplate cacheType) { this.presenter = presenter; @@ -147,7 +149,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onConfirmation(boolean isConfirmed) { if (isConfirmed) { - presenter.onRemoveCache(cacheType, selectedObject.getName()); + presenter.onRemoveResource(cacheType, selectedObject.getName()); } } }); @@ -179,6 +181,8 @@ public void onConfirmation(boolean isConfirmed) { formMapping.put(address,new FormContainer(formAssets)); } + storeForm = new StoreFormWrapper(); + MultipleToOneLayout layout = new MultipleToOneLayout() .setPlain(true) .setHeadline(title) @@ -190,9 +194,7 @@ public void onConfirmation(boolean isConfirmed) { .addDetail("Eviction", formMapping.get(EVICTION).asWidget()) .addDetail("Expiration", formMapping.get(EXPIRATION).asWidget()) .addDetail("Transaction", formMapping.get(TRANSACTION).asWidget()) - .addDetail("Store", formMapping.get(STORE).asWidget()) - .addDetail("File Store", formMapping.get(FILE_STORE).asWidget()) - .addDetail("Remote Store", formMapping.get(REMOTE_STORE).asWidget()); + .addDetail("Store", storeForm.asWidget()); return layout.build(); @@ -228,18 +230,12 @@ private void updateForms(Property selection) { formMapping.get(EXPIRATION).getForm().edit(payload.get("component").get("expiration")); if (hasDefined(payload, "component", "transaction")) formMapping.get(TRANSACTION).getForm().edit(payload.get("component").get("transaction")); - if (hasDefined(payload, "store", "custom")) - formMapping.get(STORE).getForm().edit(payload.get("store").get("custom")); - if (hasDefined(payload, "store", "file")) - formMapping.get(FILE_STORE).getForm().edit(payload.get("store").get("file")); - if (hasDefined(payload, "store", "string-jdbc")) - formMapping.get(STRING_STORE).getForm().edit(payload.get("store").get("string-jdbc")); - if (hasDefined(payload, "store", "mixed-jdbc")) - formMapping.get(MIXED_STORE).getForm().edit(payload.get("store").get("mixed-jdbc")); - if (hasDefined(payload, "store", "binary-jdbc")) - formMapping.get(BINARY_STORE).getForm().edit(payload.get("store").get("binary-jdbc")); - if (hasDefined(payload, "store", "remote")) - formMapping.get(REMOTE_STORE).getForm().edit(payload.get("store").get("remote")); + + if (payload.hasDefined("store")) { + storeForm.edit(payload.get("store")); + } else { + storeForm.edit(null); + } } } @@ -307,5 +303,102 @@ Widget asWidget() { } } + class StoreFormWrapper { + private VerticalPanel formPanel; + private HTML heading; + private ToolButton addButton; + private ToolButton removeButton; + + private String currentStore = null; + + public StoreFormWrapper() { + } + Widget asWidget() { + VerticalPanel mainPanel = new VerticalPanel(); + mainPanel.setStyleName("fill-layout-width"); + ToolStrip tools = new ToolStrip(); + heading = new HTML("

Store: none

"); + addButton = new ToolButton(Console.CONSTANTS.common_label_add(), new ClickHandler() { + @Override + public void onClick(ClickEvent clickEvent) { + presenter.onLaunchAddStoreWizard(cacheType, selectionModel.getSelectedObject().getName()); + } + }); + removeButton = new ToolButton(Console.CONSTANTS.common_label_delete(), new ClickHandler() { + @Override + public void onClick(ClickEvent clickEvent) { + Property selectedObject = selectionModel.getSelectedObject(); + String storeName = selectedObject.getValue().get("store").asProperty().getName(); + + if(selectedObject!=null) { + Feedback.confirm(Console.MESSAGES.deleteTitle("Cache Store"), + Console.MESSAGES.deleteConfirm(storeName + " store"), + new Feedback.ConfirmationHandler() { + @Override + public void onConfirmation(boolean isConfirmed) { + if (isConfirmed) { + presenter.onRemoveResource(cacheType.append("store=" + storeName), selectedObject.getName()); + heading.setText("Store: none"); + } + } + }); + } + } + }); + + addButton.setEnabled(false); + removeButton.setEnabled(false); + + tools.addToolButtonRight(addButton); + tools.addToolButtonRight(removeButton); + tools.addToolWidget(heading); + mainPanel.add(tools); + formPanel = new VerticalPanel(); + formPanel.setStyleName("fill-layout-width"); + mainPanel.add(formPanel); + return mainPanel; + } + + public void edit(ModelNode payload) { + String storeName = payload != null ? payload.asProperty().getName() : "none"; + boolean isNone = storeName.equals("none"); + + addButton.setEnabled(isNone); + removeButton.setEnabled(!isNone); + AddressTemplate address = null; + switch (storeName) { + case "binary-jdbc": + address = BINARY_STORE; + break; + case "custom": + address = STORE; + break; + case "file": + address = FILE_STORE; + break; + case "mixed-jdbc": + address = MIXED_STORE; + break; + case "string-jdbc": + address = STRING_STORE; + break; + case "remote": + address = REMOTE_STORE; + break; + } + + if (!storeName.equals(currentStore)) { + heading.setHTML("

Store: " + storeName + "

"); + formPanel.clear(); + if (!isNone) { + formPanel.add(formMapping.get(address).assets.getHelp().asWidget()); + formPanel.add(formMapping.get(address).assets.getForm()); + } + currentStore = storeName; + } + if (!isNone) + formMapping.get(address).getForm().edit(payload.get(storeName)); + } + } } diff --git a/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/NewCacheStoreWizard.java b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/NewCacheStoreWizard.java new file mode 100644 index 000000000..a72888afd --- /dev/null +++ b/gui/src/main/java/org/jboss/as/console/client/shared/subsys/infinispan/v3/NewCacheStoreWizard.java @@ -0,0 +1,94 @@ +package org.jboss.as.console.client.shared.subsys.infinispan.v3; + +import org.jboss.as.console.client.shared.subsys.infinispan.v3.CacheStoreContext.State; +import org.jboss.as.console.client.v3.dmr.AddressTemplate; +import org.jboss.as.console.client.v3.widgets.wizard.Wizard; +import org.jboss.as.console.client.v3.widgets.wizard.WizardStep; +import org.jboss.as.console.mbui.widgets.ModelNodeFormBuilder; +import org.jboss.ballroom.client.rbac.SecurityContext; + +import com.google.gwt.user.client.ui.RadioButton; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + +public class NewCacheStoreWizard extends Wizard { + private CachesPresenter presenter; + private AddressTemplate address; + private String name; + + public NewCacheStoreWizard(CachesPresenter presenter, AddressTemplate address, String name) { + super("cache-store", new CacheStoreContext()); + this.presenter = presenter; + this.address = address; + this.name = name; + + final SecurityContext securityContext = presenter.getSecurityFramework() + .getSecurityContext(presenter.getProxy().getNameToken()); + + addStep(State.TYPE, new WizardStep(this, "Choose store type:") { + + @Override + protected Widget asWidget(CacheStoreContext context) { + String[] storeNames = new String[]{"binary-jdbc","custom","file","mixed-jdbc","remote","string-jdbc"}; + VerticalPanel panel = new VerticalPanel(); + for (String name : storeNames) { + RadioButton radioButton = new RadioButton("type", name); + radioButton.getElement().setId(name); + radioButton.setStyleName("choose_template"); + radioButton.addClickHandler(event -> { + RadioButton button = (RadioButton) event.getSource(); + context.setStoreName(button.getElement().getId()); + }); + panel.add(radioButton); + } + + return panel; + } + }); + + addStep(State.ATTRIBUTES, new WizardStep(this, "Store attributes") { + + private VerticalPanel panel; + + @Override + protected Widget asWidget(CacheStoreContext context) { + // only create the wrapper panel, the form depends on step one + panel = new VerticalPanel(); + panel.setStyleName("fill-layout-width"); + return panel; + } + + @Override + protected void onShow(CacheStoreContext context) { + panel.clear(); + ModelNodeFormBuilder.FormAssets formAssets = new ModelNodeFormBuilder() + .setAddress(address.getTemplate()) + .setConfigOnly() + .setSecurityContext(securityContext) + .setResourceDescription(presenter.getDescriptionRegistry().lookup(address.append("store=" + context.getStoreName()))) + .build(); + + panel.add(formAssets.getHelp().asWidget()); + panel.add(formAssets.getForm().asWidget()); + formAssets.getForm().setEnabled(true); + context.setFormAssets(formAssets); + } + }); + } + + @Override + protected State back(State state) { + return state == State.ATTRIBUTES ? State.TYPE : null; + } + + @Override + protected State next(State state) { + return state == State.TYPE ? State.ATTRIBUTES : null; + } + + @Override + protected void finish() { + super.finish(); + presenter.onCreate(address.append("store=" + context.getStoreName()), name, context.getFormAssets().getForm().getUpdatedEntity(), true); + } +}