You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/06/13 17:19:51 UTC
[2/3] ISIS-807: Removed wizard stuff from EntityPropertiesPanel,
and entity stuff from WizardPropertiesPanel.
http://git-wip-us.apache.org/repos/asf/isis/blob/8f71fa76/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesForm.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesForm.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesForm.java
deleted file mode 100644
index 93f17bb..0000000
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesForm.java
+++ /dev/null
@@ -1,875 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.viewer.wicket.ui.components.wizard.properties.properties;
-
-import java.util.List;
-import java.util.Map;
-import org.apache.wicket.Component;
-import org.apache.wicket.MarkupContainer;
-import org.apache.wicket.Session;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.event.IEvent;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.Button;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.FormComponent;
-import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
-import org.apache.wicket.markup.html.panel.FeedbackPanel;
-import org.apache.wicket.markup.repeater.RepeatingView;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.util.visit.IVisit;
-import org.apache.wicket.util.visit.IVisitor;
-import org.apache.isis.applib.annotation.MemberGroupLayout.ColumnSpans;
-import org.apache.isis.applib.annotation.Where;
-import org.apache.isis.applib.filter.Filter;
-import org.apache.isis.applib.filter.Filters;
-import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
-import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerComposite;
-import org.apache.isis.core.commons.authentication.MessageBroker;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking;
-import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
-import org.apache.isis.core.metamodel.facets.object.membergroups.MemberGroupLayoutFacet;
-import org.apache.isis.core.metamodel.facets.object.wizard.viewmodel.WizardFacet;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.ObjectSpecifications;
-import org.apache.isis.core.metamodel.spec.ObjectSpecifications.MemberGroupLayoutHint;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.core.runtime.memento.Memento;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
-import org.apache.isis.viewer.wicket.model.hints.IsisActionCompletedEvent;
-import org.apache.isis.viewer.wicket.model.hints.IsisEnvelopeEvent;
-import org.apache.isis.viewer.wicket.model.mementos.PropertyMemento;
-import org.apache.isis.viewer.wicket.model.models.EntityModel;
-import org.apache.isis.viewer.wicket.model.models.ScalarModel;
-import org.apache.isis.viewer.wicket.ui.ComponentType;
-import org.apache.isis.viewer.wicket.ui.components.widgets.breadcrumbs.BreadcrumbModel;
-import org.apache.isis.viewer.wicket.ui.components.widgets.breadcrumbs.BreadcrumbModelProvider;
-import org.apache.isis.viewer.wicket.ui.components.widgets.containers.UiHintPathSignificantWebMarkupContainer;
-import org.apache.isis.viewer.wicket.ui.components.widgets.formcomponent.CancelHintRequired;
-import org.apache.isis.viewer.wicket.ui.errors.JGrowlBehaviour;
-import org.apache.isis.viewer.wicket.ui.pages.PageAbstract;
-import org.apache.isis.viewer.wicket.ui.pages.entity.EntityPage;
-import org.apache.isis.viewer.wicket.ui.pages.home.HomePage;
-import org.apache.isis.viewer.wicket.ui.panels.FormAbstract;
-import org.apache.isis.viewer.wicket.ui.panels.IFormSubmitterWithPreValidateHook;
-import org.apache.isis.viewer.wicket.ui.util.Components;
-import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
-
-public class WizardPropertiesForm extends FormAbstract<ObjectAdapter> {
-
- private static final long serialVersionUID = 1L;
-
- private static final String ID_MEMBER_GROUP = "memberGroup";
- private static final String ID_MEMBER_GROUP_NAME = "memberGroupName";
-
- private static final String ID_LEFT_COLUMN = "leftColumn";
- private static final String ID_MIDDLE_COLUMN = "middleColumn";
- private static final String ID_RIGHT_COLUMN = "rightColumn";
-
- private static final String ID_ENTITY_COLLECTIONS = "entityCollections";
- private static final String ID_ENTITY_COLLECTIONS_OVERFLOW = "entityCollectionsOverflow";
-
- private static final String ID_PROPERTIES = "properties";
- private static final String ID_PROPERTY = "property";
-
- private static final String ID_EDIT_BUTTON = "edit";
- private static final String ID_OK_BUTTON = "ok";
- private static final String ID_CANCEL_BUTTON = "cancel";
-
- private static final String ID_WIZARD_NEXT_BUTTON = "wizardNext";
- private static final String ID_WIZARD_PREVIOUS_BUTTON = "wizardPrevious";
- private static final String ID_WIZARD_FINISH_BUTTON = "wizardFinish";
- private static final String ID_WIZARD_CANCEL_BUTTON = "wizardCancel";
-
- private static final String ID_FEEDBACK = "feedback";
-
- private final Component owningPanel;
-
- private Button editButton;
- private Button okButton;
- private Button cancelButton;
-
- private Button wizardNextButton;
- private Button wizardPreviousButton;
- private Button wizardFinishButton;
- private Button wizardCancelButton;
-
- private FeedbackPanel feedback;
-
- private boolean renderedFirstField;
-
- public WizardPropertiesForm(final String id, final EntityModel entityModel, final Component owningPanel) {
- super(id, entityModel);
- this.owningPanel = owningPanel; // for repainting
-
- buildGui();
-
- // add any concurrency exception that might have been propagated into the entity model
- // as a result of a previous action invocation
- final String concurrencyExceptionIfAny = entityModel.getAndClearConcurrencyExceptionIfAny();
- if(concurrencyExceptionIfAny != null) {
- error(concurrencyExceptionIfAny);
- }
- }
-
- private void buildGui() {
-
- final EntityModel entityModel = (EntityModel) getModel();
- final ColumnSpans columnSpans = entityModel.getObject().getSpecification().getFacet(MemberGroupLayoutFacet.class).getColumnSpans();
-
- renderedFirstField = false;
-
- // left column
- MarkupContainer leftColumn = new WebMarkupContainer(ID_LEFT_COLUMN);
- add(leftColumn);
-
- boolean addedProperties;
- if(columnSpans.getLeft() > 0) {
- addedProperties = addPropertiesInColumn(leftColumn, MemberGroupLayoutHint.LEFT, columnSpans);
- addButtons(leftColumn);
- addWizardButtons(leftColumn);
- addFeedbackGui(leftColumn);
- } else {
- Components.permanentlyHide(this, ID_LEFT_COLUMN);
- addedProperties = false;
- }
- if(!addedProperties) {
- // a bit hacky...
- Components.permanentlyHide(this,
- ID_EDIT_BUTTON, ID_OK_BUTTON, ID_CANCEL_BUTTON,
- ID_WIZARD_NEXT_BUTTON, ID_WIZARD_PREVIOUS_BUTTON, ID_WIZARD_FINISH_BUTTON, ID_WIZARD_CANCEL_BUTTON,
- ID_FEEDBACK);
- }
-
- // middle column
- if(columnSpans.getMiddle() > 0) {
- MarkupContainer middleColumn = new WebMarkupContainer(ID_MIDDLE_COLUMN);
- add(middleColumn);
- addPropertiesInColumn(middleColumn, MemberGroupLayoutHint.MIDDLE, columnSpans);
- } else {
- Components.permanentlyHide(this, ID_MIDDLE_COLUMN);
- }
-
- // right column
- if(columnSpans.getRight() > 0) {
- MarkupContainer rightColumn = new WebMarkupContainer(ID_RIGHT_COLUMN);
- add(rightColumn);
- addPropertiesInColumn(rightColumn, MemberGroupLayoutHint.RIGHT, columnSpans);
- } else {
- Components.permanentlyHide(this, ID_RIGHT_COLUMN);
- }
-
- // collections
- if(columnSpans.getCollections() > 0) {
- final String idCollectionsToShow;
- final String idCollectionsToHide;
- int collectionSpan;
- if (columnSpans.exceedsRow()) {
- idCollectionsToShow = ID_ENTITY_COLLECTIONS_OVERFLOW;
- idCollectionsToHide = ID_ENTITY_COLLECTIONS;
- collectionSpan = 12;
- } else {
- idCollectionsToShow = ID_ENTITY_COLLECTIONS;
- idCollectionsToHide = ID_ENTITY_COLLECTIONS_OVERFLOW;
- collectionSpan = columnSpans.getCollections();
- }
-
- final Component collectionsColumn = getComponentFactoryRegistry().addOrReplaceComponent(this, idCollectionsToShow, ComponentType.ENTITY_COLLECTIONS, entityModel);
- addClassForSpan(collectionsColumn, collectionSpan);
-
- Components.permanentlyHide(this, idCollectionsToHide);
- } else {
- Components.permanentlyHide(this, ID_ENTITY_COLLECTIONS);
- Components.permanentlyHide(this, ID_ENTITY_COLLECTIONS_OVERFLOW);
- }
-
- }
-
- private boolean isWizard() {
- final ObjectSpecification specification = getEntityModel().getObject().getSpecification();
- return specification.containsFacet(WizardFacet.class);
- }
-
- private boolean addPropertiesInColumn(MarkupContainer markupContainer, MemberGroupLayoutHint hint, ColumnSpans columnSpans) {
- final int span = hint.from(columnSpans);
-
- final EntityModel entityModel = (EntityModel) getModel();
- final ObjectAdapter adapter = entityModel.getObject();
- final ObjectSpecification objSpec = adapter.getSpecification();
-
- final List<ObjectAssociation> associations = visibleProperties(adapter, objSpec, Where.OBJECT_FORMS);
-
- final RepeatingView memberGroupRv = new RepeatingView(ID_MEMBER_GROUP);
- markupContainer.add(memberGroupRv);
-
- Map<String, List<ObjectAssociation>> associationsByGroup = ObjectAssociation.Util.groupByMemberOrderName(associations);
-
- final List<String> groupNames = ObjectSpecifications.orderByMemberGroups(objSpec, associationsByGroup.keySet(), hint);
-
- for(String groupName: groupNames) {
- final List<ObjectAssociation> associationsInGroup = associationsByGroup.get(groupName);
- if(associationsInGroup==null) {
- continue;
- }
-
- final WebMarkupContainer memberGroupRvContainer = new WebMarkupContainer(memberGroupRv.newChildId());
- memberGroupRv.add(memberGroupRvContainer);
- memberGroupRvContainer.add(new Label(ID_MEMBER_GROUP_NAME, groupName));
-
- final RepeatingView propertyRv = new RepeatingView(ID_PROPERTIES);
- memberGroupRvContainer.add(propertyRv);
-
- @SuppressWarnings("unused")
- Component component;
- for (final ObjectAssociation association : associationsInGroup) {
- final WebMarkupContainer propertyRvContainer = new UiHintPathSignificantWebMarkupContainer(propertyRv.newChildId());
- propertyRv.add(propertyRvContainer);
- addPropertyToForm(entityModel, association, propertyRvContainer);
- }
- }
-
- addClassForSpan(markupContainer, span);
- return !groupNames.isEmpty();
- }
-
- private void addPropertyToForm(final EntityModel entityModel,
- final ObjectAssociation association,
- final WebMarkupContainer container) {
- final OneToOneAssociation otoa = (OneToOneAssociation) association;
- final PropertyMemento pm = new PropertyMemento(otoa);
-
- final ScalarModel scalarModel = entityModel.getPropertyModel(pm);
- final Component component = getComponentFactoryRegistry().addOrReplaceComponent(container, ID_PROPERTY, ComponentType.SCALAR_NAME_AND_VALUE, scalarModel);
-
- if(!renderedFirstField) {
- component.add(new CssClassAppender("first-field"));
- renderedFirstField = true;
- }
- }
-
- private List<ObjectAssociation> visibleProperties(final ObjectAdapter adapter, final ObjectSpecification objSpec, Where where) {
- return objSpec.getAssociations(Contributed.INCLUDED, visiblePropertyFilter(adapter, where));
- }
-
- @SuppressWarnings("unchecked")
- private Filter<ObjectAssociation> visiblePropertyFilter(final ObjectAdapter adapter, Where where) {
- return Filters.and(ObjectAssociation.Filters.PROPERTIES, ObjectAssociation.Filters.dynamicallyVisible(getAuthenticationSession(), adapter, where));
- }
-
-
- abstract class AjaxButtonWithOnError extends AjaxButton {
-
- public AjaxButtonWithOnError(String id, IModel<String> model) {
- super(id, model);
- }
-
- @Override
- protected void onError(AjaxRequestTarget target, Form<?> form) {
- super.onError(target, form);
- toEditMode(target);
- }
- }
-
- public class AjaxButtonForValidate extends AjaxButtonWithOnError implements IFormSubmitterWithPreValidateHook {
- private static final long serialVersionUID = 1L;
- public AjaxButtonForValidate(String id, IModel<String> model) {
- super(id, model);
- }
-
- @Override
- public String preValidate() {
- // attempt to load with concurrency checking, catching recognized exceptions
- try {
- getEntityModel().load(ConcurrencyChecking.CHECK); // could have also just called #getObject(), since CHECK is the default
-
- } catch(ConcurrencyException ex){
- String recognizedErrorMessage = recognizeException(ex);
- if(recognizedErrorMessage == null) {
- throw ex;
- }
-
- // reload
- getEntityModel().load(ConcurrencyChecking.NO_CHECK);
-
- getForm().clearInput();
- getEntityModel().resetPropertyModels();
-
- toViewMode(null);
- toEditMode(null);
-
- return recognizedErrorMessage;
- }
-
- return null;
- }
-
- @Override
- public void validate() {
- // add in any error message that we might have recognized from above
- WizardPropertiesForm form = WizardPropertiesForm.this;
- String preValidationErrorIfAny = form.getPreValidationErrorIfAny();
-
- if(preValidationErrorIfAny != null) {
- feedbackOrNotifyAnyRecognizedError(preValidationErrorIfAny, form);
- // skip validation, because would relate to old values
-
- final EntityPage entityPage = new EntityPage(WizardPropertiesForm.this.getModelObject(), null);
- WizardPropertiesForm.this.setResponsePage(entityPage);
- } else {
- // run Wicket's validation
- super.validate();
- }
- }
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
-
- if (getForm().hasError()) {
- // stay in edit mode
- return;
- }
-
- doPreApply();
- if (applyFormChangesElse()) return;
- final Object redirectIfAny = doPostApply();
-
- if (flushChangesElse(target)) return;
-
- getEntityModel().resetPropertyModels();
-
- toViewMode(null);
-
- // "redirect-after-post"
- //
- // RequestCycle.get().getActiveRequestHandler() indicates this is handled by the ListenerInterfaceRequestHandler
- // which renders page at end.
- //
- // it's necessary to zap the page parameters (so mapping is to just wicket/page?nn)
- // otherwise (what I think happens) is that the httpServletResponse.sendRedirect ends up being to the same URL,
- // and this is rejected as invalid either by the browser or by the servlet container (perhaps only if running remotely).
- //
-
- final ObjectAdapter objectAdapter;
- if(redirectIfAny != null) {
- objectAdapter = getPersistenceSession().getAdapterManager().adapterFor(redirectIfAny);
- } else {
- // we obtain the adapter from the entity model because (if a view model) then the entity model may contain
- // a different adapter (the cloned view model) to the one with which we started with.
- objectAdapter = getEntityModel().getObjectAdapterMemento().getObjectAdapter(ConcurrencyChecking.NO_CHECK);
- }
-
- final EntityPage entityPage = new EntityPage(objectAdapter, null);
- WizardPropertiesForm.this.setResponsePage(entityPage);
- }
-
- /**
- * Optional hook to override.
- *
- * <p>
- * If a non-null value is returned, then transition to it (ie eg the finish() transition for a wizard).
- * </p>
- */
- protected void doPreApply() {
- }
-
- /**
- * Optional hook to override.
- *
- * <p>
- * If a non-null value is returned, then transition to it (ie eg the finish() transition for a wizard).
- * </p>
- */
- protected Object doPostApply() {
- return null;
- }
-
- }
-
- abstract class AjaxButtonForCancel extends AjaxButtonWithOnError {
-
- public AjaxButtonForCancel(String id, IModel<String> model) {
- super(id, model);
- setDefaultFormProcessing(false);
- }
- }
-
-
- private void addButtons(MarkupContainer markupContainer) {
-
- // edit button
- editButton = new AjaxButtonWithOnError(ID_EDIT_BUTTON, Model.of("Edit")) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void validate() {
-
- // same logic as in cancelButton; should this be factored out?
- try {
- getEntityModel().load(ConcurrencyChecking.CHECK);
- } catch(ConcurrencyException ex) {
- getMessageBroker().addMessage("Object changed by " + ex.getOid().getVersion().getUser() + ", automatically reloading");
- getEntityModel().load(ConcurrencyChecking.NO_CHECK);
- }
-
- super.validate();
- }
-
- @Override
- public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
- getEntityModel().resetPropertyModels();
- toEditMode(target);
- }
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new org.apache.wicket.ajax.attributes.AjaxCallListener(){
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public CharSequence getSuccessHandler(Component component) {
- return "$('.first-field input').focus();";
- }
- });
- }
- };
- markupContainer.add(editButton);
-
-
- // ok button
- okButton = new AjaxButtonForValidate(ID_OK_BUTTON, Model.of("OK"));
- markupContainer.add(okButton);
-
-
- // cancel button
- cancelButton = new AjaxButtonForCancel(ID_CANCEL_BUTTON, Model.of("Cancel")) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void validate() {
-
- // same logic as in editButton; should this be factored out?
- try {
- getEntityModel().load(ConcurrencyChecking.CHECK);
- } catch(ConcurrencyException ex) {
- getMessageBroker().addMessage("Object changed by " + ex.getOid().getVersion().getUser() + ", automatically reloading");
- getEntityModel().load(ConcurrencyChecking.NO_CHECK);
- }
- super.validate();
- }
-
- @Override
- protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
- Session.get().getFeedbackMessages().clear();
- getForm().clearInput();
- getForm().visitFormComponentsPostOrder(new IVisitor<FormComponent<?>, Void>() {
-
- @Override
- public void component(FormComponent<?> formComponent, IVisit<Void> visit) {
- if (formComponent instanceof CancelHintRequired) {
- final CancelHintRequired cancelHintRequired = (CancelHintRequired) formComponent;
- cancelHintRequired.onCancel();
- }
- }
- });
-
- try {
- getEntityModel().resetPropertyModels();
- } catch(RuntimeException ex) {
- throw ex;
- }
- toViewMode(target);
- }
- };
-
- markupContainer.add(cancelButton);
-
- okButton.setOutputMarkupPlaceholderTag(true);
- editButton.setOutputMarkupPlaceholderTag(true);
- cancelButton.setOutputMarkupPlaceholderTag(true);
-
- // flush any JGrowl messages (typically concurrency exceptions) if they are added.
- okButton.add(new JGrowlBehaviour());
- editButton.add(new JGrowlBehaviour());
- cancelButton.add(new JGrowlBehaviour());
- }
-
- private void addWizardButtons(MarkupContainer markupContainer) {
-
- // next
- wizardNextButton = new AjaxButtonForValidate(ID_WIZARD_NEXT_BUTTON, Model.of("Next")) {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void doPreApply() {
- wizardNext();
- }
-
- };
- markupContainer.add(wizardNextButton);
-
- wizardPreviousButton = new AjaxButtonForValidate(ID_WIZARD_PREVIOUS_BUTTON, Model.of("Previous")) {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void doPreApply() {
- wizardPrevious();
- }
- };
- markupContainer.add(wizardPreviousButton);
-
-
- wizardFinishButton = new AjaxButtonForValidate(ID_WIZARD_FINISH_BUTTON, Model.of("Finish")) {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected Object doPostApply() {
- return wizardFinish();
- }
- };
- markupContainer.add(wizardFinishButton);
-
-
- wizardCancelButton = new Button(ID_WIZARD_CANCEL_BUTTON, Model.of("Cancel")) {
-
- private static final long serialVersionUID = 1L;
- {
- setDefaultFormProcessing(false);
- }
-
- public void onSubmit() {
- final PageAbstract page = determinePageToRedirectTo();
- WizardPropertiesForm.this.setResponsePage(page);
- }
-
- private PageAbstract determinePageToRedirectTo() {
-
- // go to the most recently viewed entity (if available) ...
- final List<EntityModel> list = getBreadcrumbs();
- for (EntityModel entityModel : list) {
- ObjectSpecification objectSpec = entityModel.getTypeOfSpecification();
- if(!objectSpec.isViewModel()) {
- ObjectAdapter objectAdapter = entityModel.getObjectAdapterMemento().getObjectAdapter(ConcurrencyChecking.NO_CHECK);
-
- return new EntityPage(objectAdapter, null);
- }
- }
-
- // ... else go to the home page
- return new HomePage();
- }
-
- private List<EntityModel> getBreadcrumbs() {
- final BreadcrumbModelProvider session = (BreadcrumbModelProvider) getSession();
- final BreadcrumbModel breadcrumbModel = session.getBreadcrumbModel();
- return breadcrumbModel.getList();
- }
- };
- markupContainer.add(wizardCancelButton);
-
-
- wizardNextButton.setOutputMarkupPlaceholderTag(true);
- wizardPreviousButton.setOutputMarkupPlaceholderTag(true);
- wizardFinishButton.setOutputMarkupPlaceholderTag(true);
- wizardCancelButton.setOutputMarkupPlaceholderTag(true);
-
- // flush any JGrowl messages if they are added.
- wizardNextButton.add(new JGrowlBehaviour());
- wizardPreviousButton.add(new JGrowlBehaviour());
- wizardFinishButton.add(new JGrowlBehaviour());
- wizardCancelButton.add(new JGrowlBehaviour());
- }
-
- private void wizardNext() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final WizardFacet wizardFacet = adapter.getSpecification().getFacet(WizardFacet.class);
- wizardFacet.next(adapter.getObject());
- }
-
- private String wizardDisableNext() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final WizardFacet wizardFacet = adapter.getSpecification().getFacet(WizardFacet.class);
- return wizardFacet.disableNext(adapter.getObject());
- }
-
- private void wizardPrevious() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final WizardFacet wizardFacet = adapter.getSpecification().getFacet(WizardFacet.class);
- wizardFacet.previous(adapter.getObject());
- }
-
- private String wizardDisablePrevious() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final WizardFacet wizardFacet = adapter.getSpecification().getFacet(WizardFacet.class);
- return wizardFacet.disablePrevious(adapter.getObject());
- }
-
- private Object wizardFinish() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final WizardFacet wizardFacet = adapter.getSpecification().getFacet(WizardFacet.class);
- return wizardFacet.finish(adapter.getObject());
- }
-
- private String wizardDisableFinish() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final WizardFacet wizardFacet = adapter.getSpecification().getFacet(WizardFacet.class);
- return wizardFacet.disableFinish(adapter.getObject());
- }
-
- // to perform object-level validation, we must apply the changes first
- // contrast this with ActionPanel (for validating actionarguments) where
- // we do the validation prior to the execution of the action
- private boolean applyFormChangesElse() {
- final ObjectAdapter adapter = getEntityModel().getObject();
- final Memento snapshotToRollbackToIfInvalid = new Memento(adapter);
-
- getEntityModel().apply();
- final String invalidReasonIfAny = getEntityModel().getReasonInvalidIfAny();
- if (invalidReasonIfAny != null) {
- error(invalidReasonIfAny);
- snapshotToRollbackToIfInvalid.recreateObject();
- toEditMode(null);
- return true;
- }
- return false;
- }
-
- private boolean flushChangesElse(AjaxRequestTarget target) {
- try {
- this.getTransactionManager().flushTransaction();
- } catch(RuntimeException ex) {
-
- // There's no need to abort the transaction here, as it will have already been done
- // (in IsisTransactionManager#executeWithinTransaction(...)).
-
- String message = recognizeExceptionAndNotify(ex, this);
- if(message == null) {
- throw ex;
- }
-
- toEditMode(target);
- return true;
- }
- return false;
- }
-
-
- private String recognizeExceptionAndNotify(RuntimeException ex, Component feedbackComponentIfAny) {
-
- // see if the exception is recognized as being a non-serious error
-
- String recognizedErrorMessageIfAny = recognizeException(ex);
- feedbackOrNotifyAnyRecognizedError(recognizedErrorMessageIfAny, feedbackComponentIfAny);
-
- return recognizedErrorMessageIfAny;
- }
-
- private void feedbackOrNotifyAnyRecognizedError(String recognizedErrorMessageIfAny, Component feedbackComponentIfAny) {
- if(recognizedErrorMessageIfAny == null) {
- return;
- }
-
- if(feedbackComponentIfAny != null) {
- feedbackComponentIfAny.error(recognizedErrorMessageIfAny);
- }
- getMessageBroker().addWarning(recognizedErrorMessageIfAny);
-
- // we clear the abort cause because we've handled rendering the exception
- getTransactionManager().getTransaction().clearAbortCause();
- }
-
- private String recognizeException(RuntimeException ex) {
-
- // REVIEW: this code is similar to stuff in EntityPropertiesForm, perhaps move up to superclass?
- // REVIEW: similar code also in WebRequestCycleForIsis; combine?
-
- final List<ExceptionRecognizer> exceptionRecognizers = getServicesInjector().lookupServices(ExceptionRecognizer.class);
- final String message = new ExceptionRecognizerComposite(exceptionRecognizers).recognize(ex);
- return message;
- }
-
- private void requestRepaintPanel(final AjaxRequestTarget target) {
- if (target != null) {
- target.add(owningPanel);
- // TODO: is it necessary to add these too?
- target.add(editButton, okButton, cancelButton, feedback);
- }
- }
-
- private EntityModel getEntityModel() {
- return (EntityModel) getModel();
- }
-
- void toViewMode(final AjaxRequestTarget target) {
-
- getEntityModel().toViewMode();
-
- if(isWizard()) {
- // just redirect
- toEditMode(target);
- return;
- }
-
- // not a wizard
- setVisible(editButton, isAnythingEditable());
- setVisible(okButton, false);
- setVisible(cancelButton, false);
-
- setVisible(wizardCancelButton, false);
- setVisible(wizardFinishButton, false);
- setVisible(wizardPreviousButton, false);
- setVisible(wizardNextButton, false);
-
- requestRepaintPanel(target);
- }
-
- private void setVisible(Button b, boolean editable) {
- if(b != null) {
- b.setVisible(editable);
- }
- }
-
- private boolean isAnythingEditable() {
- final EntityModel entityModel = (EntityModel) getModel();
- final ObjectAdapter adapter = entityModel.getObject();
-
- return !enabledAssociations(adapter, adapter.getSpecification()).isEmpty();
- }
-
- private List<ObjectAssociation> enabledAssociations(final ObjectAdapter adapter, final ObjectSpecification objSpec) {
- return objSpec.getAssociations(Contributed.EXCLUDED, enabledAssociationFilter(adapter));
- }
-
- @SuppressWarnings("unchecked")
- private Filter<ObjectAssociation> enabledAssociationFilter(final ObjectAdapter adapter) {
- return Filters.and(ObjectAssociation.Filters.PROPERTIES, ObjectAssociation.Filters.enabled(getAuthenticationSession(), adapter, Where.OBJECT_FORMS));
- }
-
- private void toEditMode(final AjaxRequestTarget target) {
- getEntityModel().toEditMode();
-
- // wizard handling.
- if(isWizard()) {
- disableIfRequired(wizardNextButton, wizardDisableNext());
- disableIfRequired(wizardPreviousButton, wizardDisablePrevious());
- disableIfRequired(wizardFinishButton, wizardDisableFinish());
-
- cancelButton.setVisible(false);
- okButton.setVisible(false);
- editButton.setVisible(false);
-
- } else {
- wizardCancelButton.setVisible(false);
- wizardFinishButton.setVisible(false);
- wizardPreviousButton.setVisible(false);
- wizardNextButton.setVisible(false);
-
- editButton.setVisible(false);
- okButton.setVisible(true);
- cancelButton.setVisible(true);
- }
- requestRepaintPanel(target);
- }
-
- private void disableIfRequired(Button button, String disabledReason) {
- if(disabledReason != null) {
- button.setEnabled(false);
- button.add(new AttributeAppender("title", disabledReason));
- }
- }
-
- private void addFeedbackGui(MarkupContainer markupContainer) {
- feedback = new ComponentFeedbackPanel(ID_FEEDBACK, this);
- feedback.setOutputMarkupPlaceholderTag(true);
- markupContainer.addOrReplace(feedback);
- feedback.setEscapeModelStrings(false);
-
- final ObjectAdapter adapter = getEntityModel().getObject();
- if (adapter == null) {
- feedback.error("cannot locate object:" + getEntityModel().getObjectAdapterMemento().toString());
- }
- }
-
-
- private static void addClassForSpan(final Component component, final int numGridCols) {
- component.add(new CssClassAppender("span"+numGridCols));
- }
-
-
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
- final IsisActionCompletedEvent ev = IsisEnvelopeEvent.openLetter(event, IsisActionCompletedEvent.class);
- if(ev == null) {
- return;
- }
-
- // hmm, it turns out that there is no need to do anything here;
- // was trying to force a redraw but the redraw was fine (just a bug in ValueChoicesSelect2Panel).
- // even though this callback is now redundant, gonna leave it in for future reference of how to
- // propogage and handle events
- return;
-
-// final AjaxRequestTarget target = ev.getTarget();
-// if(target == null) {
-// // just in case...
-// return;
-// }
-//
-// if(getEntityModel().isEditMode()) {
-// toEditMode(target);
-// } else {
-// toViewMode(target);
-// }
-//
-// // force a redraw...
-// onBeforeRender();
- }
-
-
- ///////////////////////////////////////////////////////
- // Dependencies (from context)
- ///////////////////////////////////////////////////////
-
- protected IsisTransactionManager getTransactionManager() {
- return IsisContext.getTransactionManager();
- }
-
- protected ServicesInjector getServicesInjector() {
- return IsisContext.getPersistenceSession().getServicesInjector();
- }
-
- protected MessageBroker getMessageBroker() {
- return getAuthenticationSession().getMessageBroker();
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/8f71fa76/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.css
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.css b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.css
deleted file mode 100644
index 5af51f7..0000000
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.css
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-.wizardPropertiesPanel fieldset {
- margin: 0px 0px 10px 0px;
- padding:10px 10px 0px 10px;
- border-radius: 4px;
-}
-
-.wizardPropertiesPanel fieldset legend {
-}
-
-
-.wizardNext:focus,
-.wizardPrevious:focus,
-.wizardFinish:focus,
-.edit:focus,
-.ok:focus,
-.okButton:focus {
- background-color: #40C0CB;
- font-style: italic;
-}
-
-.wizardButtons .next,
-.wizardButtons .previous,
-.wizardButtons .finish {
- display:inline-block;
- background-color:#20B5C2;
- color:#FFFFFF;
- text-transform:uppercase;
- font-size:0.9em;
- border:0px;
- padding:5px 10px;
- border-radius:4px;
- cursor:pointer;
-}
-
-
-.wizardButtons .next,
-.wizardButtons .previous,
-.wizardButtons .finish {
- height: 30px;
- min-width: 80px;
-}
-
-
-.wizardButtons input:disabled {
- background-color: lightgray;
- cursor: not-allowed;
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/8f71fa76/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.html
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.html b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.html
deleted file mode 100644
index 8d7d2d3..0000000
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.html
+++ /dev/null
@@ -1,80 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<html>
- <body>
- <wicket:panel>
- <div class="wizardPropertiesPanel entityPropertiesComponentType">
- <form wicket:id="entityProperties" class="inputForm">
- <div class="row-fluid">
- <div wicket:id="leftColumn">
- <div class="inputFormTable properties">
- <fieldset wicket:id="memberGroup" class="memberGroup myBlockContainer">
- <legend wicket:id="memberGroupName">[group name]</legend>
- <div wicket:id="properties">
- <div wicket:id="property" class="property">[property]</div>
- </div>
- </fieldset>
- </div>
- <div class="feedbackPanel">
- <span wicket:id="feedback"/>
- </div>
- <div class="buttons">
- <input type="submit" class="edit" wicket:id="edit"/>
- <input type="submit" class="ok" wicket:id="ok"/>
- <input type="submit" class="cancel" wicket:id="cancel"/>
- </div>
- <div class="wizardButtons">
- <input type="submit" class="previous" wicket:id="wizardPrevious"/>
- <input type="submit" class="next" wicket:id="wizardNext"/>
- <input type="submit" class="finish" wicket:id="wizardFinish"/>
- <input type="submit" class="cancel" wicket:id="wizardCancel"/>
- </div>
- </div>
- <div wicket:id="middleColumn">
- <div class="inputFormTable properties">
- <fieldset wicket:id="memberGroup" class="memberGroup myBlockContainer">
- <legend wicket:id="memberGroupName">[group name]</legend>
- <div wicket:id="properties">
- <div wicket:id="property" class="property">[property]</div>
- </div>
- </fieldset>
- </div>
- </div>
- <div wicket:id="rightColumn">
- <div class="inputFormTable properties">
- <fieldset wicket:id="memberGroup" class="memberGroup myBlockContainer">
- <legend wicket:id="memberGroupName">[group name]</legend>
- <div wicket:id="properties">
- <div wicket:id="property" class="property">[property]</div>
- </div>
- </fieldset>
- </div>
- </div>
- <div wicket:id="entityCollections"/>
- </div>
- <div class="row-fluid">
- <div wicket:id="entityCollectionsOverflow"/>
- </div>
-
- </form>
- </div>
- </wicket:panel>
- </body>
-</html>
http://git-wip-us.apache.org/repos/asf/isis/blob/8f71fa76/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.java
deleted file mode 100644
index 7553dc4..0000000
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanel.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.viewer.wicket.ui.components.wizard.properties.properties;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.viewer.wicket.model.models.EntityModel;
-import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
-
-/**
- * {@link org.apache.isis.viewer.wicket.ui.panels.PanelAbstract Panel} representing the properties of an entity, as per
- * the provided {@link org.apache.isis.viewer.wicket.model.models.EntityModel}.
- */
-public class WizardPropertiesPanel extends PanelAbstract<EntityModel> {
-
- private static final long serialVersionUID = 1L;
-
- private static final String ID_ENTITY_PROPERTIES = "entityProperties";
-
- private WizardPropertiesForm form;
-
- public WizardPropertiesPanel(final String id, final EntityModel entityModel) {
- super(id, entityModel);
- buildGui();
- form.toViewMode(null);
- }
-
- private void buildGui() {
- buildEntityPropertiesAndOrCollectionsGui();
- setOutputMarkupId(true); // so can repaint via ajax
- }
-
- private void buildEntityPropertiesAndOrCollectionsGui() {
- final EntityModel model = getModel();
- final ObjectAdapter adapter = model.getObject();
- if (adapter != null) {
- form = new WizardPropertiesForm(ID_ENTITY_PROPERTIES, model, this);
- addOrReplace(form);
- } else {
- permanentlyHide(ID_ENTITY_PROPERTIES);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/8f71fa76/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanelFactory.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanelFactory.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanelFactory.java
deleted file mode 100644
index 0297412..0000000
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/wizard/properties/properties/WizardPropertiesPanelFactory.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.viewer.wicket.ui.components.wizard.properties.properties;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.model.IModel;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.viewer.wicket.model.models.EntityModel;
-import org.apache.isis.viewer.wicket.ui.ComponentType;
-import org.apache.isis.viewer.wicket.ui.components.entity.EntityComponentFactoryAbstract;
-
-/**
- * {@link org.apache.isis.viewer.wicket.ui.ComponentFactory} for {@link WizardPropertiesPanel}.
- */
-public class WizardPropertiesPanelFactory extends EntityComponentFactoryAbstract {
-
- private static final long serialVersionUID = 1L;
-
- public WizardPropertiesPanelFactory() {
- super(ComponentType.ENTITY_PROPERTIES, WizardPropertiesPanel.class);
- }
-
- @Override
- public Component createComponent(final String id, final IModel<?> model) {
- final EntityModel entityModel = (EntityModel) model;
- return new WizardPropertiesPanel(id, entityModel);
- }
-
- @Override
- protected ApplicationAdvice appliesTo(IModel<?> model) {
- final ApplicationAdvice applicationAdvice = super.appliesTo(model);
- if(!applicationAdvice.applies()) {
- return applicationAdvice;
- }
- // applies and so therefore must be an EntityModel
- final EntityModel entityModel = (EntityModel) model;
- final ObjectSpecification specification = entityModel.getTypeOfSpecification();
- if(specification.isWizard()) {
- return ApplicationAdvice.APPLIES_EXCLUSIVELY;
- }
- return ApplicationAdvice.DOES_NOT_APPLY;
- }
-}