ISIS-537: starting work on moving bulk actions up to panel header (renders but looks nasty and the selector does nothing).
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/5022f856 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/5022f856 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/5022f856 Branch: refs/heads/master Commit: 5022f8563f2d72372ed9ba8b9e9924b481d2774c Parents: 92ffe2d Author: Dan Haywood <[email protected]> Authored: Mon Nov 10 10:19:23 2014 +0000 Committer: Dan Haywood <[email protected]> Committed: Mon Nov 10 10:21:51 2014 +0000 ---------------------------------------------------------------------- .../ajaxtable/BulkActionsHelper.java | 99 ++++++++++++++++++++ .../CollectionContentsAsAjaxTablePanel.java | 16 ++-- 2 files changed, 106 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/5022f856/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/BulkActionsHelper.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/BulkActionsHelper.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/BulkActionsHelper.java new file mode 100644 index 0000000..e7b1b66 --- /dev/null +++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/BulkActionsHelper.java @@ -0,0 +1,99 @@ +/* + * 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.collectioncontents.ajaxtable; + +import java.util.Collections; +import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.apache.isis.applib.filter.Filters; +import org.apache.isis.core.metamodel.spec.ActionType; +import org.apache.isis.core.metamodel.spec.ObjectSpecification; +import org.apache.isis.core.metamodel.spec.feature.Contributed; +import org.apache.isis.core.metamodel.spec.feature.ObjectAction; +import org.apache.isis.core.runtime.system.context.IsisContext; +import org.apache.isis.viewer.wicket.model.models.EntityCollectionModel; + +public class BulkActionsHelper { + + private final EntityCollectionModel model; + + public BulkActionsHelper(final EntityCollectionModel model) { + this.model = model; + } + + private EntityCollectionModel getModel() { + return model; + } + + public List<ObjectAction> getBulkActions() { + final EntityCollectionModel model = getModel(); + + if(model.isParented()) { + return Collections.emptyList(); + } + + final ObjectSpecification typeSpec = model.getTypeOfSpecification(); + + List<ObjectAction> objectActions = typeSpec.getObjectActions(ActionType.USER, Contributed.INCLUDED, Filters.<ObjectAction>any()); + + if ( isExploring() || isPrototyping()) { + List<ObjectAction> explorationActions = typeSpec.getObjectActions(ActionType.EXPLORATION, Contributed.INCLUDED, Filters.<ObjectAction>any()); + List<ObjectAction> prototypeActions = typeSpec.getObjectActions(ActionType.PROTOTYPE, Contributed.INCLUDED, Filters.<ObjectAction>any()); + objectActions.addAll(explorationActions); + objectActions.addAll(prototypeActions); + } + if (isDebugMode()) { + List<ObjectAction> debugActions = typeSpec.getObjectActions(ActionType.DEBUG, Contributed.INCLUDED, Filters.<ObjectAction>any()); + objectActions.addAll(debugActions); + } + + List<ObjectAction> flattenedActions = objectActions; + + return Lists.newArrayList(Iterables.filter(flattenedActions, BULK)); + } + + + @SuppressWarnings("deprecation") + private static final Predicate<ObjectAction> BULK = Filters.asPredicate(ObjectAction.Filters.bulk()); + + + //region > from context + + public boolean isExploring() { + return IsisContext.getDeploymentType().isExploring(); + } + public boolean isPrototyping() { + return IsisContext.getDeploymentType().isPrototyping(); + } + + /** + * Protected so can be overridden in testing if required. + */ + protected boolean isDebugMode() { + // TODO: need to figure out how to switch into debug mode; + // probably call a Debug toggle page, and stuff into + // Session.getMetaData() + return true; + } + + //endregion + +} http://git-wip-us.apache.org/repos/asf/isis/blob/5022f856/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java index 803a053..aca3535 100644 --- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java +++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java @@ -21,12 +21,10 @@ package org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable import java.util.Collections; import java.util.List; - import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.inject.Inject; - import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; @@ -34,7 +32,6 @@ import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; import org.apache.wicket.markup.head.IHeaderResponse; import org.apache.wicket.model.Model; - import org.apache.isis.applib.annotation.Where; import org.apache.isis.applib.filter.Filter; import org.apache.isis.applib.filter.Filters; @@ -76,9 +73,10 @@ public class CollectionContentsAsAjaxTablePanel extends PanelAbstract<EntityColl private static final long serialVersionUID = 1L; private static final String ID_TABLE = "table"; - private static final String ID_ENTITY_ACTIONS = "entityActions"; private static final String ID_ACTION_PROMPT_MODAL_WINDOW = "actionPromptModalWindow"; - + + private static final String ID_ENTITY_ACTIONS = "entityActions"; + @SuppressWarnings("deprecation") private static final Predicate<ObjectAction> BULK = Filters.asPredicate(ObjectAction.Filters.bulk()); @@ -106,7 +104,7 @@ public class CollectionContentsAsAjaxTablePanel extends PanelAbstract<EntityColl addPropertyColumnsIfRequired(columns); final SortableDataProvider<ObjectAdapter,String> dataProvider = new CollectionContentsSortableDataProvider(model); - dataTable = new IsisAjaxFallbackDataTable<ObjectAdapter,String>(ID_TABLE, columns, dataProvider, model.getPageSize()); + dataTable = new IsisAjaxFallbackDataTable<>(ID_TABLE, columns, dataProvider, model.getPageSize()); addActionPromptModalWindow(); buildEntityActionsGui(bulkActions, this, toggleboxColumn); @@ -152,16 +150,16 @@ public class CollectionContentsAsAjaxTablePanel extends PanelAbstract<EntityColl } private void buildEntityActionsGui( - final List<ObjectAction> bulkActions, + final List<ObjectAction> bulkActions, final ActionPromptProvider actionPromptProvider, final ObjectAdapterToggleboxColumn toggleboxColumn) { final EntityCollectionModel model = getModel(); - + if(bulkActions.isEmpty() || model.isParented()) { permanentlyHide(ID_ENTITY_ACTIONS); return; } - + if(!bulkActions.isEmpty()) { final ActionLinkFactory linkFactory = new BulkActionsLinkFactory(model, dataTable, toggleboxColumn);
