diff --git a/jbpm-wb-common/jbpm-wb-common-api/src/main/java/org/jbpm/workbench/common/model/GenericSummary.java b/jbpm-wb-common/jbpm-wb-common-api/src/main/java/org/jbpm/workbench/common/model/GenericSummary.java index 351b6f53da..58d7b15f0c 100644 --- a/jbpm-wb-common/jbpm-wb-common-api/src/main/java/org/jbpm/workbench/common/model/GenericSummary.java +++ b/jbpm-wb-common/jbpm-wb-common-api/src/main/java/org/jbpm/workbench/common/model/GenericSummary.java @@ -26,7 +26,6 @@ public abstract class GenericSummary extends AbstractPageRow implements Seria protected T id; protected String name; - private boolean selected = false; public GenericSummary() { } @@ -53,14 +52,6 @@ public void setName(String name) { this.name = name; } - public boolean isSelected() { - return selected; - } - - public void setSelected(boolean selected) { - this.selected = selected; - } - @Override @SuppressWarnings("PMD.AvoidMultipleUnaryOperators") public int hashCode() { @@ -107,7 +98,6 @@ public String toString() { return "GenericSummary{" + "id=" + id + ", name='" + name + '\'' + - ", selected=" + selected + - '}'; + "} " + super.toString(); } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/pom.xml b/jbpm-wb-common/jbpm-wb-common-client/pom.xml index 72958c7fd7..109a4884fa 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/pom.xml +++ b/jbpm-wb-common/jbpm-wb-common-client/pom.xml @@ -50,6 +50,10 @@ org.gwtbootstrap3 gwtbootstrap3-extras + + com.google.elemental2 + elemental2-dom + com.google.guava guava @@ -167,10 +171,6 @@ gwt-user provided - - com.google.elemental2 - elemental2-dom - diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/CommonEntryPoint.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/CommonEntryPoint.java index 660f5013c9..f9adc2b0cc 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/CommonEntryPoint.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/CommonEntryPoint.java @@ -19,15 +19,15 @@ import javax.annotation.PostConstruct; import org.jboss.errai.ioc.client.api.EntryPoint; -import org.jbpm.workbench.common.client.resources.CommonResources; +import org.jboss.errai.ui.shared.api.annotations.Bundle; import org.uberfire.client.views.pfly.sys.PatternFlyBootstrapper; @EntryPoint +@Bundle("resources/i18n/Constants.properties") public class CommonEntryPoint { @PostConstruct public void init() { - CommonResources.INSTANCE.css().ensureInjected(); PatternFlyBootstrapper.ensureBootstrapSelectIsAvailable(); PatternFlyBootstrapper.ensureBootstrapDateRangePickerIsAvailable(); } diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/PerspectiveIds.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/PerspectiveIds.java index 76021ce36e..a0d15b8d9e 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/PerspectiveIds.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/PerspectiveIds.java @@ -39,4 +39,15 @@ public interface PerspectiveIds extends org.kie.workbench.common.workbench.clien String TASK_LIST_SCREEN = "TaskListScreen"; String TASK_DETAILS_SCREEN = "TaskDetailsScreen"; + String JOB_LIST_BASIC_FILTERS_SCREEN = "JobListBasicFiltersScreen"; + String EXECUTION_ERROR_LIST_BASIC_FILTERS_SCREEN = "ErrorListBasicFiltersScreen"; + String PROCESS_INSTANCE_LIST_BASIC_FILTERS_SCREEN = "ProcessInstanceListBasicFiltersScreen"; + String TASK_ADMIN_LIST_BASIC_FILTERS_SCREEN = "TaskAdminListBasicFiltersScreen"; + String TASK_LIST_BASIC_FILTERS_SCREEN = "TaskListBasicFiltersScreen"; + + String JOB_LIST_SAVED_FILTERS_SCREEN = "JobListSavedFiltersScreen"; + String EXECUTION_ERROR_LIST_SAVED_FILTERS_SCREEN = "ExecutionErrorListSavedFiltersScreen"; + String PROCESS_INSTANCE_LIST_SAVED_FILTERS_SCREEN = "ProcessInstanceListSavedFiltersScreen"; + String TASK_ADMIN_LIST_SAVED_FILTERS_SCREEN = "TaskAdminListSavedFiltersScreen"; + String TASK_LIST_SAVED_FILTERS_SCREEN = "TaskListSavedFiltersScreen"; } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/dataset/DataSetAwareSelect.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/dataset/DataSetAwareSelect.java index 5f80f8f323..2838d96c1f 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/dataset/DataSetAwareSelect.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/dataset/DataSetAwareSelect.java @@ -16,6 +16,7 @@ package org.jbpm.workbench.common.client.dataset; +import javax.annotation.PostConstruct; import javax.enterprise.context.Dependent; import javax.enterprise.event.Observes; import javax.inject.Inject; @@ -50,7 +51,11 @@ public class DataSetAwareSelect { private String valueColumnId; private String textColumnId; private DataSetLookup dataSetLookup; - private String tableKey; + + @PostConstruct + public void init(){ + select.disable(); + } public void setDataSetLookup(DataSetLookup dataSetLookup) { this.dataSetLookup = dataSetLookup; @@ -64,15 +69,8 @@ public void setValueColumnId(String valueColumnId) { this.valueColumnId = valueColumnId; } - public void setTableKey(String tableKey) { - this.tableKey = tableKey; - } - public void onDataSetReady(@Observes DataSetReadyEvent event) { final FilterSettings filterSettings = event.getFilterSettings(); - if (this.tableKey.equals(filterSettings.getKey()) == false) { - return; - } if (filterSettings.getServerTemplateId() == null || filterSettings.getServerTemplateId().isEmpty()) { removeOptions(); diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItem.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItem.java similarity index 77% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItem.java rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItem.java index 7a5da2fde7..76c6d40c64 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItem.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jbpm.workbench.common.client.list; +package org.jbpm.workbench.common.client.filters.active; import java.util.function.Consumer; @@ -23,7 +23,7 @@ @Bindable public class ActiveFilterItem { - private String labelKey; + private String key; private String labelValue; @@ -36,24 +36,24 @@ public class ActiveFilterItem { public ActiveFilterItem() { } - public ActiveFilterItem(final String labelKey, + public ActiveFilterItem(final String key, final String labelValue, final String hint, final T value, final Consumer callback) { - this.labelKey = labelKey; + this.key = key; this.labelValue = labelValue; this.hint = hint; this.value = value; this.callback = callback; } - public String getLabelKey() { - return labelKey; + public String getKey() { + return key; } - public void setLabelKey(String labelKey) { - this.labelKey = labelKey; + public void setKey(String key) { + this.key = key; } public String getLabelValue() { @@ -99,7 +99,7 @@ public boolean equals(Object o) { ActiveFilterItem that = (ActiveFilterItem) o; - if (!getLabelKey().equals(that.getLabelKey())) { + if (!getKey().equals(that.getKey())) { return false; } if (!getLabelValue().equals(that.getLabelValue())) { @@ -111,7 +111,7 @@ public boolean equals(Object o) { @Override @SuppressWarnings("PMD.AvoidMultipleUnaryOperators") public int hashCode() { - int result = getLabelKey().hashCode(); + int result = getKey().hashCode(); result = ~~result; result = 31 * result + getLabelValue().hashCode(); result = ~~result; @@ -119,4 +119,15 @@ public int hashCode() { result = ~~result; return result; } + + @Override + public String toString() { + return "ActiveFilterItem{" + + "key='" + key + '\'' + + ", labelValue='" + labelValue + '\'' + + ", hint='" + hint + '\'' + + ", value=" + value + + ", callback=" + callback + + '}'; + } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemRemovedEvent.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemRemovedEvent.java new file mode 100644 index 0000000000..357df94dc8 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemRemovedEvent.java @@ -0,0 +1,56 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.active; + +public class ActiveFilterItemRemovedEvent { + + private ActiveFilterItem activeFilterItem; + + public ActiveFilterItemRemovedEvent(final ActiveFilterItem activeFilterItem) { + this.activeFilterItem = activeFilterItem; + } + + public ActiveFilterItem getActiveFilterItem() { + return activeFilterItem; + } + + @Override + public String toString() { + return "ActiveFilterItemRemovedEvent{" + + "activeFilterItem=" + activeFilterItem + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ActiveFilterItemRemovedEvent)) { + return false; + } + + ActiveFilterItemRemovedEvent that = (ActiveFilterItemRemovedEvent) o; + + return getActiveFilterItem().equals(that.getActiveFilterItem()); + } + + @Override + public int hashCode() { + return getActiveFilterItem().hashCode(); + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemView.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemView.html similarity index 69% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemView.html rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemView.html index 1840ec745e..86013b9e52 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemView.html +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemView.html @@ -1,6 +1,6 @@
  • - : + -
  • \ No newline at end of file + diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemView.java similarity index 83% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemView.java rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemView.java index 7487698cc5..03360dcf68 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemView.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilterItemView.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,18 @@ * limitations under the License. */ -package org.jbpm.workbench.common.client.list; +package org.jbpm.workbench.common.client.filters.active; import javax.annotation.PreDestroy; import javax.enterprise.context.Dependent; +import javax.enterprise.event.Event; import javax.inject.Inject; +import javax.inject.Named; import com.google.gwt.user.client.TakesValue; import org.jboss.errai.common.client.api.IsElement; -import org.jboss.errai.common.client.dom.Event; import org.jboss.errai.common.client.dom.HTMLElement; import org.jboss.errai.common.client.dom.ListItem; -import org.jboss.errai.common.client.dom.Span; import org.jboss.errai.databinding.client.api.DataBinder; import org.jboss.errai.ui.shared.api.annotations.*; import org.uberfire.client.views.pfly.widgets.JQueryProducer; @@ -39,13 +39,9 @@ public class ActiveFilterItemView implements TakesValue, @Inject @DataField + @Named("span") @Bound - Span labelKey; - - @Inject - @DataField - @Bound - Span labelValue; + elemental2.dom.HTMLElement labelValue; @Inject @DataField @@ -59,7 +55,7 @@ public class ActiveFilterItemView implements TakesValue, private DataBinder dataBinder; @Inject - private javax.enterprise.event.Event event; + private Event event; @Override public ActiveFilterItem getValue() { @@ -86,8 +82,8 @@ public HTMLElement getElement() { } @EventHandler("remove") - public void onRemove(@ForEvent("click") Event e) { - event.fire(new ActiveFilterItemRemoved(getValue())); + public void onRemove(@ForEvent("click") elemental2.dom.Event e) { + event.fire(new ActiveFilterItemRemovedEvent(getValue())); } @PreDestroy diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/css/CommonCSS.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilters.java similarity index 53% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/css/CommonCSS.java rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilters.java index 77e7e55da1..a8b1b85458 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/css/CommonCSS.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFilters.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,18 @@ * limitations under the License. */ -package org.jbpm.workbench.common.client.resources.css; +package org.jbpm.workbench.common.client.filters.active; -import com.google.gwt.resources.client.CssResource; +import java.util.function.BiConsumer; +import java.util.function.Consumer; -public interface CommonCSS extends CssResource { +import org.jboss.errai.common.client.api.elemental2.IsElement; - @ClassName("selected") - String selected(); +public interface ActiveFilters extends IsElement { + + void addActiveFilter(ActiveFilterItem filter); + + void removeAllActiveFilters(); + + void setSaveFilterCallback(BiConsumer> filterNameCallback); } diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersImpl.java new file mode 100644 index 0000000000..ca438345ad --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.active; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import javax.annotation.PostConstruct; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import elemental2.dom.HTMLElement; + +@Dependent +public class ActiveFiltersImpl implements ActiveFilters { + + @Inject + ActiveFiltersView view; + + private BiConsumer> filterNameCallback; + + @PostConstruct + public void init() { + view.setSaveFilterCallback(name -> { + if (filterNameCallback != null) { + filterNameCallback.accept(name, + error -> { + if (error == null) { + view.closeSaveFilter(); + } else { + view.setSaveFilterErrorMessage(error); + } + }); + } + }); + } + + @Override + public void setSaveFilterCallback(final BiConsumer> filterNameCallback) { + this.filterNameCallback = filterNameCallback; + } + + @Override + public HTMLElement getElement() { + return view.getElement(); + } + + @Override + public void addActiveFilter(final ActiveFilterItem filter) { + view.addActiveFilter(filter); + } + + @Override + public void removeAllActiveFilters() { + view.removeAllActiveFilters(); + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/CommonResources.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersView.java similarity index 51% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/CommonResources.java rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersView.java index 2ee4f1486a..02daa92f7a 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/CommonResources.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersView.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,20 @@ * limitations under the License. */ -package org.jbpm.workbench.common.client.resources; +package org.jbpm.workbench.common.client.filters.active; -import com.google.gwt.core.client.GWT; -import com.google.gwt.resources.client.ClientBundle; -import org.jbpm.workbench.common.client.resources.css.CommonCSS; +import org.jboss.errai.common.client.api.elemental2.IsElement; +import org.uberfire.mvp.ParameterizedCommand; -public interface CommonResources extends ClientBundle { +public interface ActiveFiltersView extends IsElement { - CommonResources INSTANCE = GWT.create(CommonResources.class); + void addActiveFilter(ActiveFilterItem filter); - @Source("css/common.css") - CommonCSS css(); -} \ No newline at end of file + void removeAllActiveFilters(); + + void setSaveFilterCallback(ParameterizedCommand callback); + + void closeSaveFilter(); + + void setSaveFilterErrorMessage(String message); +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.css b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.css similarity index 63% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.css rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.css index 8b135d73b8..f971001f75 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.css +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.css @@ -1,7 +1,3 @@ -.select-filters > .bootstrap-select.form-control + .bootstrap-select.form-control { - margin-left: 15px; -} - .active-filters-label { float: left; padding-left: 20px; @@ -24,15 +20,6 @@ line-height: 20px; } -.filters-input { - display: flex; -} - -.filters-input span { - margin-left: 5px; - margin-top: 3px; -} - .active-filters-results { border-bottom: 1px solid #d1d1d1; } @@ -40,8 +27,4 @@ .active-filters-results div { height: auto; overflow: hidden; -} - -.form-group.toolbar-pf-filter { - padding-right: 30px; } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.html new file mode 100644 index 0000000000..9718c8688c --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.html @@ -0,0 +1,16 @@ +
    +
    +
    +
    + | + +
    +
    +

    :

    +
    +
    +
      +
      +
      +
      +
      \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.java new file mode 100644 index 0000000000..02e915bec9 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImpl.java @@ -0,0 +1,171 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.active; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.enterprise.context.Dependent; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import elemental2.dom.HTMLAnchorElement; +import elemental2.dom.HTMLDivElement; +import elemental2.dom.HTMLElement; +import org.jboss.errai.common.client.dom.Anchor; +import org.jboss.errai.common.client.dom.Event; +import org.jboss.errai.databinding.client.api.DataBinder; +import org.jboss.errai.databinding.client.components.ListComponent; +import org.jboss.errai.databinding.client.components.ListContainer; +import org.jboss.errai.ui.shared.api.annotations.AutoBound; +import org.jboss.errai.ui.shared.api.annotations.Bound; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.EventHandler; +import org.jboss.errai.ui.shared.api.annotations.ForEvent; +import org.jboss.errai.ui.shared.api.annotations.Templated; +import org.uberfire.client.views.pfly.widgets.JQueryProducer; +import org.uberfire.client.views.pfly.widgets.Popover; +import org.uberfire.client.views.pfly.widgets.PopoverOptions; +import org.uberfire.mvp.ParameterizedCommand; + +@Templated +@Dependent +public class ActiveFiltersViewImpl implements ActiveFiltersView { + + @Inject + @DataField("remove-all-filters") + HTMLAnchorElement removeAll; + + @Inject + @DataField("save-filter") + Anchor saveFilter; + + @Inject + @DataField("content") + HTMLDivElement content; + + @Inject + @DataField("actions") + HTMLDivElement actions; + + @Inject + @DataField("active-filters") + @ListContainer("ul") + @Bound + private ListComponent activeFilters; + + @Inject + @AutoBound + private DataBinder> activeFiltersList; + + @Inject + private JQueryProducer.JQuery jQueryPopover; + + @Inject + private SaveFilterPopoverView saveFilterPopoverView; + + private Popover saveFilterPopover; + + private ParameterizedCommand saveFilterCallback; + + @PostConstruct + public void init() { + activeFiltersList.setModel(new ArrayList<>()); + activeFilters.addComponentCreationHandler(v -> actions.classList.remove("hidden")); + activeFilters.addComponentDestructionHandler(v -> { + if (activeFiltersList.getModel().isEmpty()) { + actions.classList.add("hidden"); + } + final Consumer callback = v.getValue().getCallback(); + if (callback != null) { + callback.accept(v.getValue().getValue()); + } + }); + + saveFilterPopover = jQueryPopover.wrap(this.saveFilter); + setSaveFilterPopoverCallback(); + final PopoverOptions popoverOptions = new PopoverOptions(); + popoverOptions.setContent(e -> saveFilterPopoverView.getElement()); + saveFilterPopover.popover(popoverOptions); + saveFilterPopover.addShowListener(() -> saveFilterPopoverView.onOpen()); + saveFilterPopover.addShownListener(() -> saveFilterPopoverView.onShow()); + } + + protected void setSaveFilterPopoverCallback() { + saveFilterPopoverView.setCancelCallback(() -> closeSaveFilter()); + saveFilterPopoverView.setSaveCallback(name -> saveFilter(name)); + } + + @PreDestroy + public void destroy() { + saveFilterPopover.destroy(); + } + + @Override + public void setSaveFilterCallback(final ParameterizedCommand callback) { + saveFilterCallback = callback; + } + + @Override + public void closeSaveFilter() { + saveFilterPopover.hide(); + } + + @Override + public void setSaveFilterErrorMessage(final String message) { + saveFilterPopoverView.setError(message); + } + + protected void saveFilter(final String filterName) { + if (saveFilterCallback != null) { + saveFilterCallback.execute(filterName); + } + } + + @Override + public void addActiveFilter(final ActiveFilterItem filter) { + activeFiltersList.getModel().removeIf(f -> f.getKey().equals(filter.getKey())); + activeFiltersList.getModel().add(filter); + } + + public void onRemoveActiveFilter(@Observes final ActiveFilterItemRemovedEvent event) { + activeFiltersList.getModel().remove(event.getActiveFilterItem()); + } + + @EventHandler("remove-all-filters") + public void onRemoveAll(@ForEvent("click") Event e) { + activeFiltersList.getModel().clear(); + } + + @EventHandler("save-filter") + public void onSaveFilter(@ForEvent("click") Event e) { + saveFilterPopover.toggle(); + } + + @Override + public void removeAllActiveFilters() { + activeFiltersList.getModel().forEach(f -> f.setCallback(null)); + activeFiltersList.getModel().clear(); + } + + @Override + public HTMLElement getElement() { + return content; + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverView.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverView.html new file mode 100644 index 0000000000..e2305dca63 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverView.html @@ -0,0 +1,15 @@ +
      +
      +
      +
      + + +
      +
      +
      + +   + +
      +
      +
      \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverView.java new file mode 100644 index 0000000000..ab121adb2c --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverView.java @@ -0,0 +1,120 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.active; + +import javax.enterprise.context.Dependent; +import javax.inject.Inject; +import javax.inject.Named; + +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.dom.client.KeyDownEvent; +import elemental2.dom.Event; +import elemental2.dom.HTMLButtonElement; +import elemental2.dom.HTMLDivElement; +import elemental2.dom.HTMLElement; +import elemental2.dom.HTMLInputElement; +import org.jboss.errai.common.client.api.elemental2.IsElement; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.EventHandler; +import org.jboss.errai.ui.shared.api.annotations.ForEvent; +import org.jboss.errai.ui.shared.api.annotations.Templated; +import org.uberfire.mvp.Command; +import org.uberfire.mvp.ParameterizedCommand; + +@Templated +@Dependent +public class SaveFilterPopoverView implements IsElement { + + @Inject + @DataField("content") + HTMLDivElement content; + + @Inject + @DataField("input-group") + HTMLDivElement inputGroup; + + @Inject + @DataField("save") + HTMLButtonElement save; + + @Inject + @DataField("cancel") + HTMLButtonElement cancel; + + @Inject + @DataField("name") + HTMLInputElement filterName; + + @Inject + @DataField("error") + @Named("span") + HTMLElement error; + + private Command cancelCallback; + + private ParameterizedCommand saveCallback; + + public void setCancelCallback(final Command cancelCallback) { + this.cancelCallback = cancelCallback; + } + + public void setSaveCallback(final ParameterizedCommand saveCallback) { + this.saveCallback = saveCallback; + } + + @Override + public HTMLElement getElement() { + return content; + } + + @EventHandler("save") + public void onSave(@ForEvent("click") Event e) { + if (saveCallback != null) { + saveCallback.execute(filterName.value); + } + } + + @EventHandler("name") + public void onKeyPressEvent(final KeyDownEvent e) { + if (e.getNativeKeyCode() == KeyCodes.KEY_ENTER) { + e.preventDefault(); + onSave(null); + } + } + + public void onOpen() { + filterName.value = ""; + error.textContent = ""; + inputGroup.classList.remove("has-error"); + } + + public void onShow() { + filterName.focus(); + } + + public void setError(final String message) { + error.textContent = message; + inputGroup.classList.add("has-error"); + } + + @EventHandler("cancel") + public void onCancel(@ForEvent("click") Event e) { + if (cancelCallback != null) { + cancelCallback.execute(); + } + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFilterAddEvent.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFilterAddEvent.java new file mode 100644 index 0000000000..cd97bf4f77 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFilterAddEvent.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.basic; + +import org.dashbuilder.dataset.filter.ColumnFilter; +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; + +public class BasicFilterAddEvent { + + private ActiveFilterItem activeFilterItem; + + private ColumnFilter filter; + + public BasicFilterAddEvent(final ActiveFilterItem activeFilterItem, + final ColumnFilter filter) { + this.activeFilterItem = activeFilterItem; + this.filter = filter; + } + + public ActiveFilterItem getActiveFilterItem() { + return activeFilterItem; + } + + public ColumnFilter getFilter() { + return filter; + } + + @Override + public String toString() { + return "BasicFilterAddEvent{" + + "activeFilterItem=" + activeFilterItem + + ", filter=" + filter + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof BasicFilterAddEvent)) { + return false; + } + + BasicFilterAddEvent that = (BasicFilterAddEvent) o; + + if (!getActiveFilterItem().equals(that.getActiveFilterItem())) { + return false; + } + return getFilter().equals(that.getFilter()); + } + + @Override + public int hashCode() { + int result = getActiveFilterItem().hashCode(); + result = 31 * result + getFilter().hashCode(); + return result; + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersPresenter.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersPresenter.java new file mode 100644 index 0000000000..ae08396b39 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersPresenter.java @@ -0,0 +1,98 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.basic; + +import javax.annotation.PostConstruct; +import javax.enterprise.event.Event; +import javax.inject.Inject; + +import org.dashbuilder.dataset.filter.ColumnFilter; +import org.jboss.errai.common.client.api.IsElement; +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; +import org.jbpm.workbench.common.client.filters.saved.SavedFilterSelectedEvent; +import org.jbpm.workbench.common.client.resources.i18n.Constants; +import org.jbpm.workbench.df.client.filter.FilterEditorPopup; +import org.jbpm.workbench.df.client.filter.FilterSettingsManager; +import org.jbpm.workbench.df.client.filter.SavedFilter; +import org.uberfire.client.annotations.WorkbenchPartTitle; +import org.uberfire.client.annotations.WorkbenchPartView; + +public abstract class BasicFiltersPresenter { + + private final Constants constants = Constants.INSTANCE; + + @Inject + protected BasicFiltersView view; + + protected FilterSettingsManager filterSettingsManager; + + @Inject + protected Event activeFilters; + + @Inject + private FilterEditorPopup filterEditorPopup; + + @Inject + private Event savedFilterSelectedEvent; + + @WorkbenchPartView + public IsElement getView() { + return view; + } + + @WorkbenchPartTitle + public String getTitle() { + return constants.Filters(); + } + + @PostConstruct + public void init() { + view.setAdvancedFiltersCallback(() -> showAdvancedFilters()); + loadFilters(); + } + + public abstract void loadFilters(); + + public void setFilterSettingsManager(final FilterSettingsManager filterSettingsManager) { + this.filterSettingsManager = filterSettingsManager; + } + + protected void addSearchFilter(final ActiveFilterItem filter, + final ColumnFilter columnFilter) { + activeFilters.fire(new BasicFilterAddEvent(filter, + columnFilter)); + } + + protected void showAdvancedFilters() { + filterEditorPopup.setTitle(getAdvancedFilterPopupTitle()); + filterEditorPopup.show(filterSettingsManager.createFilterSettingsPrototype(), + filterSettings -> + filterSettingsManager.saveFilterIntoPreferences(filterSettings, + state -> { + if (state) { + filterEditorPopup.hide(); + savedFilterSelectedEvent.fire(new SavedFilterSelectedEvent(new SavedFilter(filterSettings.getKey(), + filterSettings.getTableName()))); + } else { + filterEditorPopup.setTableNameError(Constants.INSTANCE.FilterWithSameNameAlreadyExists()); + } + }) + ); + } + + protected abstract String getAdvancedFilterPopupTitle(); +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersView.java similarity index 56% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersView.java rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersView.java index 617e2555c1..d5dc2e3d13 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersView.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersView.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,50 +14,42 @@ * limitations under the License. */ -package org.jbpm.workbench.common.client.list; +package org.jbpm.workbench.common.client.filters.basic; import java.util.Map; import java.util.function.Consumer; import org.dashbuilder.dataset.DataSetLookup; +import org.jboss.errai.common.client.api.IsElement; +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; import org.jbpm.workbench.common.client.util.DateRange; +import org.uberfire.mvp.Command; -public interface AdvancedSearchFiltersView { +public interface BasicFiltersView extends IsElement { + + void setAdvancedFiltersCallback(Command callback); void addTextFilter(String label, String placeholder, - Consumer addCallback, - Consumer removeCallback); + Consumer> callback); void addNumericFilter(String label, String placeholder, - Consumer addCallback, - Consumer removeCallback); + Consumer> callback); void addDateRangeFilter(String label, String placeholder, Boolean useMaxDate, - Consumer addCallback, - Consumer removeCallback); + Consumer> callback); void addSelectFilter(String label, Map options, Boolean liveSearch, - Consumer addCallback, - Consumer removeCallback); + Consumer> callback); void addDataSetSelectFilter(String label, - String tableKey, DataSetLookup lookup, String textColumnId, String valueColumnId, - Consumer addCallback, - Consumer removeCallback); - - void addActiveFilter(String labelKey, - String labelValue, - T value, - Consumer removeCallback); - - void removeAllActiveFilters(); -} \ No newline at end of file + Consumer> callback); +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersViewImpl.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersViewImpl.html new file mode 100644 index 0000000000..c552a25e0b --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersViewImpl.html @@ -0,0 +1,23 @@ +
      +
      +
      +
      +
      + +
      +
      +
      + + + +
      +
      + +
      +
      + +
      +
      +
      \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersViewImpl.java similarity index 52% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.java rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersViewImpl.java index 7b8d18c7f0..bb8c26ccac 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/basic/BasicFiltersViewImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,28 +14,28 @@ * limitations under the License. */ -package org.jbpm.workbench.common.client.list; +package org.jbpm.workbench.common.client.filters.basic; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.Consumer; import javax.annotation.PostConstruct; import javax.enterprise.context.Dependent; -import javax.enterprise.event.Observes; import javax.inject.Inject; +import javax.inject.Named; import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.user.client.ui.Composite; import org.dashbuilder.dataset.DataSetLookup; +import org.jboss.errai.common.client.api.IsElement; import org.jboss.errai.common.client.dom.*; -import org.jboss.errai.databinding.client.api.DataBinder; -import org.jboss.errai.databinding.client.components.ListComponent; -import org.jboss.errai.databinding.client.components.ListContainer; import org.jboss.errai.ioc.client.api.ManagedInstance; -import org.jboss.errai.ui.shared.api.annotations.*; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.EventHandler; +import org.jboss.errai.ui.shared.api.annotations.ForEvent; +import org.jboss.errai.ui.shared.api.annotations.Templated; import org.jbpm.workbench.common.client.dataset.DataSetAwareSelect; +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; +import org.jbpm.workbench.common.client.list.DatePickerRange; import org.jbpm.workbench.common.client.resources.i18n.Constants; import org.jbpm.workbench.common.client.util.DateRange; import org.uberfire.client.views.pfly.widgets.DateRangePicker; @@ -44,6 +44,7 @@ import org.uberfire.client.views.pfly.widgets.Moment; import org.uberfire.client.views.pfly.widgets.Popover; import org.uberfire.client.views.pfly.widgets.Select; +import org.uberfire.mvp.Command; import static org.jboss.errai.common.client.dom.DOMUtil.*; import static org.jboss.errai.common.client.dom.Window.getDocument; @@ -51,22 +52,28 @@ import static org.uberfire.client.views.pfly.widgets.Moment.Builder.moment; @Dependent -@Templated -public class AdvancedSearchFiltersViewImpl extends Composite implements AdvancedSearchFiltersView { +@Templated(stylesheet = "/org/jbpm/workbench/common/client/resources/css/kie-manage.less") +public class BasicFiltersViewImpl implements BasicFiltersView, + IsElement { private final Constants constants = Constants.INSTANCE; @Inject - @DataField("dropdown-filter-text") - Span filterText; + @DataField("content") + Div content; @Inject - @DataField("date-dropdown-filter-text") - Span dateFilterText; + @DataField("filter-list") + Div filterList; @Inject - @DataField("active-filters-text") - Span activeFiltersText; + @DataField("refine") + @Named("h5") + Heading refine; + + @Inject + @DataField("refine-options") + Select refineSelect; @Inject @DataField("filters-input") @@ -74,77 +81,51 @@ public class AdvancedSearchFiltersViewImpl extends Composite implements Advanced @Inject @DataField("filters-input-help") - Anchor filtersInputHelp; + Button filtersInputHelp; @Inject - @DataField("date-filters-input") - Div dateFiltersInput; + @DataField("refine-apply") + Button refineApply; @Inject - @DataField("remove-all-filters") - Anchor removeAll; + @DataField("advanced-filters") + Button advancedFilters; - @Inject - @DataField("filters") - UnorderedList filters; - - @Inject - @DataField("date-filters") - UnorderedList dateFilters; - - @Inject - @DataField("active-filters") - @ListContainer("ul") - @Bound - private ListComponent activeFilters; - - @Inject - @AutoBound - private DataBinder> activeFiltersList; + private Command advancedFiltersCallback; @Inject - @DataField("select-filters") - private Div selectFilters; - - @Inject - @DataField("date-caret") - private Span dateCaret; - - @Inject - @DataField("date-button") - private Button dateButton; + private JQueryProducer.JQuery jQueryPopover; @Inject private ManagedInstance customizeCallback, - final Consumer addCallback, - final Consumer removeCallback) { + final Consumer> callback) { final Input input = (Input) getDocument().createElement("input"); customizeCallback.accept(input); input.setAttribute("placeholder", placeholder); input.setAttribute("data-filter", label); - input.getClassList().add("form-control"); - input.getClassList().add("filter-control"); - input.getClassList().add("hidden"); - input.addEventListener("keypress", - (KeyboardEvent e) -> { - if (e.getKeyCode() == KeyCodes.KEY_ENTER && input.getValue().isEmpty() == false) { - addActiveFilter(label, - input.getValue(), - input.getValue(), - removeCallback); - addCallback.accept(input.getValue()); - input.setValue(""); - } - }, - false); - filtersInput.appendChild(input); - if (filterText.getTextContent().isEmpty()) { - setInputCurrentFilter(label); + addCSSClass(input, + "form-control"); + addCSSClass(input, + "filter-control"); + if (hidden) { + addCSSClass(input, + "hidden"); } + input.setOnkeypress((KeyboardEvent e) -> { + if ((e == null || e.getKeyCode() == KeyCodes.KEY_ENTER) && input.getValue().isEmpty() == false) { + addActiveFilter(label, + input.getValue(), + null, + input.getValue(), + callback); + input.setValue(""); + } + }); + filtersInput.insertBefore(input, + filtersInput.getFirstChild()); } - private void createFilterOption(final String label, - final HTMLElement element, - final EventListener listener) { - final Anchor a = (Anchor) getDocument().createElement("a"); - a.setTextContent(label); - a.addEventListener("click", - listener, - false); - final ListItem li = (ListItem) getDocument().createElement("li"); - li.setAttribute("data-filter", - label); - li.appendChild(a); - element.appendChild(li); - } - - public void setInputCurrentFilter(final String label) { - setCurrentFilter(label, - filterText, - filters, - filtersInput); - } + private void createFilterOption(final String label) { - public void setDateCurrentFilter(final String label) { - setCurrentFilter(label, - dateFilterText, - dateFilters, - dateFiltersInput); + refineSelect.addOption(label); + refineSelect.refresh(); } - private void setCurrentFilter(final String label, - final HTMLElement text, - final HTMLElement optionsText, - final HTMLElement options) { - text.setTextContent(label); - for (Element child : elementIterable(optionsText.getChildNodes())) { - if (label.equals(child.getAttribute("data-filter"))) { - addCSSClass((HTMLElement) child, - "hidden"); - } else { - removeCSSClass((HTMLElement) child, - "hidden"); + private void setInputCurrentFilter(final String label) { + for (Element child : elementIterable(filtersInput.getChildNodes())) { + if (child.getTagName().equals("INPUT")) { + if (label.equals(child.getAttribute("data-filter"))) { + removeCSSClass((HTMLElement) child, + "hidden"); + } else { + addCSSClass((HTMLElement) child, + "hidden"); + } } } - for (Element child : elementIterable(options.getChildNodes())) { - if (label.equals(child.getAttribute("data-filter"))) { - removeCSSClass((HTMLElement) child, - "hidden"); - } else { - addCSSClass((HTMLElement) child, - "hidden"); + } + + @EventHandler("refine-apply") + public void onApplyClick(@ForEvent("click") Event e) { + for (Element child : elementIterable(filtersInput.getChildNodes())) { + if (child.getTagName().equals("INPUT")) { + Input input = (Input) child; + if (input.getClassList().contains("hidden") == false) { + input.getOnkeypress().call(null); + break; + } } } } - @Override - public void addActiveFilter(final String labelKey, - final String labelValue, - final T value, - final Consumer removeCallback) { - addActiveFilter(labelKey, - labelValue, - null, - value, - removeCallback); + @EventHandler("advanced-filters") + public void onAdvancedFiltersClick(@ForEvent("click") Event e) { + if (advancedFiltersCallback != null) { + advancedFiltersCallback.execute(); + } } protected void addActiveFilter(final String labelKey, final String labelValue, final String hint, final T value, - final Consumer removeCallback) { - activeFiltersList.getModel().removeIf(f -> f.getLabelKey().equals(labelKey)); - activeFiltersList.getModel().add(new ActiveFilterItem(labelKey, - labelValue, - hint, - value, - removeCallback)); - } - - public void onRemoveActiveFilter(@Observes final ActiveFilterItemRemoved event) { - activeFiltersList.getModel().remove(event.getActiveFilterItem()); - } - - @EventHandler("remove-all-filters") - public void onRemoveAll(@ForEvent("click") Event e) { - removeAllActiveFilters(); - } - - @Override - public void removeAllActiveFilters() { - activeFiltersList.getModel().clear(); + final Consumer> callback) { + if (callback != null) { + callback.accept(new ActiveFilterItem(labelKey, + labelKey + ": " + labelValue, + hint, + value, + null)); + } } - -} \ No newline at end of file +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterRemoveEvent.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterRemoveEvent.java new file mode 100644 index 0000000000..0d487ae86a --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterRemoveEvent.java @@ -0,0 +1,58 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.saved; + +import org.jbpm.workbench.df.client.filter.SavedFilter; + +public class SavedFilterRemoveEvent { + + private SavedFilter savedFilter; + + public SavedFilterRemoveEvent(final SavedFilter savedFilter) { + this.savedFilter = savedFilter; + } + + public SavedFilter getSavedFilter() { + return savedFilter; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof SavedFilterRemoveEvent)) { + return false; + } + + SavedFilterRemoveEvent that = (SavedFilterRemoveEvent) o; + + return getSavedFilter().equals(that.getSavedFilter()); + } + + @Override + public int hashCode() { + return getSavedFilter().hashCode(); + } + + @Override + public String toString() { + return "SavedFilterRemoveEvent{" + + "savedFilter=" + savedFilter + + '}'; + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterSelectedEvent.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterSelectedEvent.java new file mode 100644 index 0000000000..aefa28b416 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterSelectedEvent.java @@ -0,0 +1,58 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.saved; + +import org.jbpm.workbench.df.client.filter.SavedFilter; + +public class SavedFilterSelectedEvent { + + private SavedFilter savedFilter; + + public SavedFilterSelectedEvent(final SavedFilter savedFilter) { + this.savedFilter = savedFilter; + } + + public SavedFilter getSavedFilter() { + return savedFilter; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof SavedFilterSelectedEvent)) { + return false; + } + + SavedFilterSelectedEvent that = (SavedFilterSelectedEvent) o; + + return getSavedFilter().equals(that.getSavedFilter()); + } + + @Override + public int hashCode() { + return getSavedFilter().hashCode(); + } + + @Override + public String toString() { + return "SavedFilterRemoveEvent{" + + "savedFilter=" + savedFilter + + '}'; + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterView.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterView.html new file mode 100644 index 0000000000..ccd92f02ab --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterView.html @@ -0,0 +1,9 @@ +
    • +
      + +
      + + +
    • \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterView.java new file mode 100644 index 0000000000..23e37bf2ac --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFilterView.java @@ -0,0 +1,84 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.saved; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.Dependent; +import javax.enterprise.event.Event; +import javax.inject.Inject; + +import com.google.gwt.user.client.TakesValue; +import com.google.gwt.user.client.ui.Composite; +import elemental2.dom.HTMLButtonElement; +import org.jboss.errai.databinding.client.api.DataBinder; +import org.jboss.errai.ui.shared.api.annotations.AutoBound; +import org.jboss.errai.ui.shared.api.annotations.Bound; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.EventHandler; +import org.jboss.errai.ui.shared.api.annotations.ForEvent; +import org.jboss.errai.ui.shared.api.annotations.Templated; +import org.jbpm.workbench.common.client.resources.i18n.Constants; +import org.jbpm.workbench.df.client.filter.SavedFilter; + +@Dependent +@Templated +public class SavedFilterView extends Composite implements TakesValue { + + @Inject + @DataField("name") + @Bound + HTMLButtonElement name; + + @Inject + @DataField("remove") + HTMLButtonElement remove; + + @Inject + @AutoBound + private DataBinder dataBinder; + + @Inject + private Event savedFilterRemoveEvent; + + @Inject + private Event savedFilterSelectedEvent; + + @PostConstruct + public void init(){ + remove.title = Constants.INSTANCE.Remove(); + } + + @Override + public SavedFilter getValue() { + return dataBinder.getModel(); + } + + @Override + public void setValue(final SavedFilter savedFilter) { + dataBinder.setModel(savedFilter); + } + + @EventHandler("remove") + public void onRemove(@ForEvent("click") elemental2.dom.Event e) { + savedFilterRemoveEvent.fire(new SavedFilterRemoveEvent(getValue())); + } + + @EventHandler("name") + public void onFilterSelected(@ForEvent("click") elemental2.dom.Event e) { + savedFilterSelectedEvent.fire(new SavedFilterSelectedEvent(getValue())); + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersPresenter.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersPresenter.java new file mode 100644 index 0000000000..327b99e714 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersPresenter.java @@ -0,0 +1,108 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.saved; + +import javax.annotation.PostConstruct; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import org.jboss.errai.common.client.api.elemental2.IsElement; +import org.jbpm.workbench.df.client.events.SavedFilterAddedEvent; +import org.jbpm.workbench.df.client.filter.FilterSettingsManager; +import org.jbpm.workbench.common.client.menu.RestoreDefaultFiltersMenuBuilder; +import org.jbpm.workbench.common.client.resources.i18n.Constants; +import org.jbpm.workbench.df.client.filter.SavedFilter; +import org.uberfire.client.annotations.WorkbenchMenu; +import org.uberfire.client.annotations.WorkbenchPartTitle; +import org.uberfire.client.annotations.WorkbenchPartView; +import org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup; +import org.uberfire.mvp.Commands; +import org.uberfire.workbench.model.menu.MenuFactory; +import org.uberfire.workbench.model.menu.Menus; + +public class SavedFiltersPresenter implements RestoreDefaultFiltersMenuBuilder.SupportsRestoreDefaultFilters { + + private final Constants constants = Constants.INSTANCE; + + private FilterSettingsManager filterSettingsManager; + + @Inject + private SavedFiltersViewImpl view; + + @WorkbenchPartView + public IsElement getView() { + return view; + } + + @WorkbenchPartTitle + public String getTitle() { + return constants.SavedFilters(); + } + + @PostConstruct + public void init() { + loadSavedFilters(); + } + + @WorkbenchMenu + public Menus getMenus() { + return MenuFactory + .newTopLevelCustomMenu(new RestoreDefaultFiltersMenuBuilder(this)).endMenu() + .build(); + } + + public void setFilterSettingsManager(final FilterSettingsManager filterSettingsManager) { + this.filterSettingsManager = filterSettingsManager; + } + + protected void loadSavedFilters() { + filterSettingsManager.loadSavedFilters(filters -> filters.forEach(f -> view.addSavedFilter(f))); + } + + protected void removeSavedFilter(final SavedFilter savedFilter) { + filterSettingsManager.removeSavedFilterFromPreferences(savedFilter.getKey()); + view.removeSavedFilter(savedFilter); + } + + protected void onRestoreFilters() { + view.removeAllSavedFilters(); + filterSettingsManager.resetDefaultSavedFilters(filters -> filters.forEach(f -> view.addSavedFilter(f))); + } + + public void onSaveFilter(@Observes final SavedFilterAddedEvent event) { + view.addSavedFilter(event.getFilter()); + } + + public void onRemoveSavedFilter(@Observes final SavedFilterRemoveEvent event) { + YesNoCancelPopup yesNoCancelPopup = YesNoCancelPopup.newYesNoCancelPopup(constants.RemoveSavedFilterTitle(), + constants.RemoveSavedFilterMessage(event.getSavedFilter().getName()), + () -> removeSavedFilter(event.getSavedFilter()), + null, + Commands.DO_NOTHING); + yesNoCancelPopup.show(); + } + + @Override + public void onRestoreDefaultFilters() { + YesNoCancelPopup yesNoCancelPopup = YesNoCancelPopup.newYesNoCancelPopup(constants.RestoreDefaultFilters(), + constants.AreYouSureRestoreDefaultFilters(), + () -> onRestoreFilters(), + null, + Commands.DO_NOTHING); + yesNoCancelPopup.show(); + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersViewImpl.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersViewImpl.html new file mode 100644 index 0000000000..db8a757c86 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersViewImpl.html @@ -0,0 +1,5 @@ +
      +
      +
        +
        +
        diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersViewImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersViewImpl.java new file mode 100644 index 0000000000..ab36d5cedd --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/filters/saved/SavedFiltersViewImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.filters.saved; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import elemental2.dom.HTMLDivElement; +import elemental2.dom.HTMLElement; +import org.jboss.errai.common.client.api.elemental2.IsElement; +import org.jboss.errai.databinding.client.api.DataBinder; +import org.jboss.errai.databinding.client.components.ListComponent; +import org.jboss.errai.databinding.client.components.ListContainer; +import org.jboss.errai.ui.shared.api.annotations.AutoBound; +import org.jboss.errai.ui.shared.api.annotations.Bound; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.Templated; +import org.jbpm.workbench.df.client.filter.SavedFilter; + +@Dependent +@Templated +public class SavedFiltersViewImpl implements IsElement { + + @Inject + @DataField("filters") + HTMLDivElement filters; + + @Inject + @DataField("saved-filters") + @ListContainer("ul") + @Bound + @SuppressWarnings("unused") + private ListComponent savedFilters; + + @Inject + @AutoBound + private DataBinder> savedFilterDataBinder; + + @Override + public HTMLElement getElement() { + return filters; + } + + @PostConstruct + public void init() { + savedFilterDataBinder.setModel(new ArrayList<>()); + } + + public void addSavedFilter(final SavedFilter savedFilter) { + savedFilterDataBinder.getModel().add(savedFilter); + } + + public void removeSavedFilter(final SavedFilter savedFilter) { + savedFilterDataBinder.getModel().remove(savedFilter); + } + + public void removeAllSavedFilters() { + savedFilterDataBinder.getModel().clear(); + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListPresenter.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListPresenter.java index 1e2dddee3a..6cbc4662fa 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListPresenter.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListPresenter.java @@ -18,37 +18,23 @@ import java.util.List; import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.Timer; import com.google.gwt.view.client.AsyncDataProvider; import com.google.gwt.view.client.HasData; import com.google.gwt.view.client.Range; -import org.jbpm.workbench.common.client.menu.RestoreDefaultFiltersMenuBuilder; +import org.jbpm.workbench.common.client.menu.RefreshMenuBuilder; import org.jbpm.workbench.common.client.resources.i18n.Constants; import org.jbpm.workbench.common.model.QueryFilter; -import org.uberfire.ext.widgets.common.client.menu.RefreshMenuBuilder; -import org.uberfire.ext.widgets.common.client.menu.RefreshSelectorMenuBuilder; -import org.uberfire.lifecycle.OnClose; import org.uberfire.paging.PageResponse; /** * @param data type for the AsyncDataProvider */ -public abstract class AbstractListPresenter implements RefreshMenuBuilder.SupportsRefresh, - RefreshSelectorMenuBuilder.SupportsRefreshInterval, - RestoreDefaultFiltersMenuBuilder.SupportsRestoreDefaultFilters { +public abstract class AbstractListPresenter implements RefreshMenuBuilder.SupportsRefresh { protected AsyncDataProvider dataProvider; protected QueryFilter currentFilter; - protected boolean addingDefaultFilters = false; - - protected Timer refreshTimer = null; - - protected boolean autoRefreshEnabled = false; - - protected int autoRefreshSeconds = 0; // This should be loaded from the grid settings (probably the filters) - private Constants constants = GWT.create(Constants.class); public AbstractListPresenter() { @@ -57,50 +43,8 @@ public AbstractListPresenter() { protected abstract ListView getListView(); - public boolean isAddingDefaultFilters() { - return addingDefaultFilters; - } - - public void setAddingDefaultFilters(boolean addingDefaultFilters) { - this.addingDefaultFilters = addingDefaultFilters; - } - - public Timer getRefreshTimer() { - return refreshTimer; - } - - public void setRefreshTimer(Timer refreshTimer) { - this.refreshTimer = refreshTimer; - } - - public boolean isAutoRefreshEnabled() { - return autoRefreshEnabled; - } - - public void setAutoRefreshEnabled(boolean autoRefreshEnabled) { - this.autoRefreshEnabled = autoRefreshEnabled; - } - - protected void updateRefreshTimer() { - if (refreshTimer == null) { - refreshTimer = new Timer() { - public void run() { - getData(getListView().getListGrid().getVisibleRange()); - } - }; - } else { - refreshTimer.cancel(); - } - if (autoRefreshEnabled && autoRefreshSeconds > 10) { - refreshTimer.schedule(autoRefreshSeconds * 1000); - } - } - public abstract void getData(Range visibleRange); - public void onGridPreferencesStoreLoaded() { - } - protected void initDataProvider() { dataProvider = new AsyncDataProvider() { @Override @@ -123,18 +67,19 @@ public void updateDataOnCallback(List instanceSummaries, int startRange, int totalRowCount, boolean isExact) { - - getListView().hideBusyIndicator(); dataProvider.updateRowCount(totalRowCount, isExact); + dataProvider.updateRowData(startRange, instanceSummaries); - updateRefreshTimer(); - getListView().getListGrid().setVisibleSelectedItems(); + getListView().hideBusyIndicator(); } public void addDataDisplay(final HasData display) { + if(dataProvider.getDataDisplays().size() == 1){ + dataProvider.removeDataDisplay(dataProvider.getDataDisplays().iterator().next()); + } dataProvider.addDataDisplay(display); } @@ -157,33 +102,4 @@ public void refreshGrid() { true); } } - - @Override - public void onRestoreDefaultFilters() { - getListView().showRestoreDefaultFilterConfirmationPopup(); - } - - @Override - public void onUpdateRefreshInterval(boolean enableAutoRefresh, - int newInterval) { - this.autoRefreshEnabled = enableAutoRefresh; - setAutoRefreshSeconds(newInterval); - updateRefreshTimer(); - } - - protected int getAutoRefreshSeconds() { - return autoRefreshSeconds; - } - - protected void setAutoRefreshSeconds(int refreshSeconds) { - autoRefreshSeconds = refreshSeconds; - } - - @OnClose - public void onClose() { - if (refreshTimer != null) { - refreshTimer.cancel(); - } - } - } diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.html new file mode 100644 index 0000000000..42ffc2ee8c --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.html @@ -0,0 +1,5 @@ +
        +
        +
        +
        +
        \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.java index 0937f0f057..cabca710d2 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractListView.java @@ -15,15 +15,16 @@ */ package org.jbpm.workbench.common.client.list; -import com.google.gwt.user.cellview.client.RowStyles; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.RequiresResize; import com.google.gwt.view.client.DefaultSelectionEventManager; import com.google.gwt.view.client.NoSelectionModel; +import elemental2.dom.HTMLDivElement; import org.jboss.errai.common.client.api.Caller; import org.jboss.errai.common.client.api.RemoteCallback; +import org.jboss.errai.common.client.dom.elemental2.Elemental2DomUtil; import org.jboss.errai.security.shared.api.identity.User; -import org.jbpm.workbench.common.client.resources.CommonResources; +import org.jboss.errai.ui.shared.api.annotations.DataField; import org.jbpm.workbench.common.model.GenericSummary; import org.uberfire.client.mvp.PlaceManager; import org.uberfire.ext.services.shared.preferences.GridGlobalPreferences; @@ -60,22 +61,12 @@ public abstract class AbstractListView selectedStyles = new RowStyles() { - - @Override - public String getStyleNames(T row, - int rowIndex) { - if (rowIndex == selectedRow) { - return CommonResources.INSTANCE.css().selected(); - } - return null; - } - }; - protected DefaultSelectionEventManager noActionColumnManager; + @Inject + @DataField("column") + protected HTMLDivElement column; + @Inject private Caller preferencesService; @@ -83,11 +74,9 @@ public void init(final V presenter, final GridGlobalPreferences preferences) { this.presenter = presenter; - listGrid = new ExtendedPagedTable(preferences); + listGrid = createListGrid(preferences); listGrid.setShowLastPagerButton(true); listGrid.setShowFastFordwardPagerButton(true); - initWidget(listGrid); - presenter.addDataDisplay(listGrid); preferencesService.call(new RemoteCallback() { @Override @@ -98,14 +87,19 @@ public void callback(GridPreferencesStore preferencesStore) { } else { listGrid.setGridPreferencesStore(preferencesStore); } - presenter.onGridPreferencesStoreLoaded(); initColumns(listGrid); listGrid.loadPageSizePreferences(); + new Elemental2DomUtil().appendWidgetToElement(column, listGrid); + presenter.addDataDisplay(listGrid); } }).loadUserPreferences(preferences.getKey(), UserPreferencesType.GRIDPREFERENCES); } + protected ExtendedPagedTable createListGrid(final GridGlobalPreferences preferences) { + return new ExtendedPagedTable(preferences); + } + @Override public void onResize() { @@ -115,9 +109,6 @@ public void displayNotification(String text) { notification.fire(new NotificationEvent(text)); } - public void showRestoreDefaultFilterConfirmationPopup() { - } - public ExtendedPagedTable getListGrid() { return listGrid; } diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridPresenter.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridPresenter.java index 7995cdce24..93f715101d 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridPresenter.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridPresenter.java @@ -16,18 +16,31 @@ package org.jbpm.workbench.common.client.list; +import java.util.List; import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Predicate; - +import javax.annotation.PostConstruct; +import javax.enterprise.event.Observes; import javax.inject.Inject; +import com.google.gwt.user.cellview.client.ColumnSortList; +import com.google.gwt.view.client.Range; +import org.dashbuilder.dataset.client.DataSetReadyCallback; import org.dashbuilder.dataset.filter.ColumnFilter; +import org.dashbuilder.dataset.sort.SortOrder; +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; +import org.jbpm.workbench.common.client.filters.basic.BasicFilterAddEvent; +import org.jbpm.workbench.common.client.filters.saved.SavedFilterSelectedEvent; +import org.jbpm.workbench.common.client.resources.i18n.Constants; import org.jbpm.workbench.common.model.GenericSummary; import org.jbpm.workbench.df.client.filter.FilterSettings; +import org.jbpm.workbench.df.client.filter.FilterSettingsManager; import org.jbpm.workbench.df.client.list.DataSetQueryHelper; import org.uberfire.client.annotations.WorkbenchPartView; import org.uberfire.client.mvp.UberView; -import org.uberfire.ext.widgets.common.client.menu.RefreshSelectorMenuBuilder; +import org.uberfire.client.workbench.widgets.common.ErrorPopupPresenter; import org.uberfire.lifecycle.OnOpen; import org.uberfire.mvp.PlaceRequest; import org.uberfire.mvp.impl.DefaultPlaceRequest; @@ -35,18 +48,21 @@ import org.uberfire.security.authz.AuthorizationManager; import org.uberfire.workbench.model.ActivityResourceType; -public abstract class AbstractMultiGridPresenter extends AbstractScreenListPresenter implements RefreshSelectorMenuBuilder.SupportsRefreshInterval { +public abstract class AbstractMultiGridPresenter extends AbstractScreenListPresenter { protected DataSetQueryHelper dataSetQueryHelper; - protected RefreshSelectorMenuBuilder refreshSelectorMenuBuilder = new RefreshSelectorMenuBuilder(this); - protected V view; - private AuthorizationManager authorizationManager; + protected AuthorizationManager authorizationManager; + + protected FilterSettingsManager filterSettingsManager; @Inject - public void setAuthorizationManager(AuthorizationManager authorizationManager) { + protected ErrorPopupPresenter errorPopup; + + @Inject + public void setAuthorizationManager(final AuthorizationManager authorizationManager) { this.authorizationManager = authorizationManager; } @@ -55,32 +71,8 @@ public void setDataSetQueryHelper(final DataSetQueryHelper dataSetQueryHelper) { this.dataSetQueryHelper = dataSetQueryHelper; } - public void filterGrid(FilterSettings tableSettings) { - dataSetQueryHelper.setCurrentTableSettings(tableSettings); - refreshGrid(); - } - - @Override - public void onUpdateRefreshInterval(boolean enableAutoRefresh, - int newInterval) { - super.onUpdateRefreshInterval(enableAutoRefresh, - newInterval); - view.saveRefreshValue(newInterval); - } - - @Override - public void onGridPreferencesStoreLoaded() { - refreshSelectorMenuBuilder.loadOptions(view.getRefreshValue()); - clearActiveSearchFilters(); - setupActiveSearchFilters(); - view.selectFirstTabAndEnableQueries(); - } - - public void onRestoreTabs() { - view.restoreTabs(); - clearActiveSearchFilters(); - setupDefaultActiveSearchFilters(); - view.selectFirstTabAndEnableQueries(); + public void setFilterSettingsManager(final FilterSettingsManager filterSettingsManager) { + this.filterSettingsManager = filterSettingsManager; } @Override @@ -98,45 +90,127 @@ public void setView(V view) { this.view = view; } - public abstract FilterSettings createTableSettingsPrototype(); - - public abstract FilterSettings createSearchTabSettings(); - - public abstract void setupAdvancedSearchView(); - public void setupActiveSearchFilters() { setupDefaultActiveSearchFilters(); } public abstract void setupDefaultActiveSearchFilters(); + @PostConstruct + public void init() { + final BiConsumer> filterNameCallback = (name, callback) -> saveSearchFilterSettings(name, + callback); + view.setSaveFilterCallback(filterNameCallback); + } + @Override @OnOpen public void onOpen() { super.onOpen(); - setupAdvancedSearchView(); + setFilterSettings(filterSettingsManager.createDefaultFilterSettingsPrototype(), + table -> { + setupActiveSearchFilters(); + addDataDisplay(table); + }); + } + + protected void onBasicFilterAddEvent(@Observes final BasicFilterAddEvent event) { + addActiveFilter(event.getFilter(), + event.getActiveFilterItem()); + } + + protected void onSavedFilterSelectedEvent(@Observes final SavedFilterSelectedEvent event) { + filterSettingsManager.getFilterSettings(event.getSavedFilter().getKey(), + filter -> addActiverFilters(filter)); } - protected void clearActiveSearchFilters() { - final FilterSettings settings = view.getAdvancedSearchFilterSettings(); - settings.removeAllColumnFilters(); - view.saveAdvancedSearchFilterSettings(settings); + protected void setFilterSettings(final FilterSettings filter, + final Consumer> readyCallback) { + dataSetQueryHelper.setCurrentTableSettings(filter); + view.loadListTable(filter.getKey(), + readyCallback); + } + + protected void addActiverFilters(final FilterSettings filter) { view.removeAllActiveFilters(); + setFilterSettings(filter, + table -> { + if (filter.getDataSetLookup().getFirstFilterOp() != null) { + List filters = filter.getDataSetLookup().getFirstFilterOp().getColumnFilterList(); + filters.forEach(column -> { + final ActiveFilterItem activeFilter = new ActiveFilterItem<>(column.getColumnId(), + column.toString(), + null, + null, + v -> removeActiveFilter(column)); + view.addActiveFilter(activeFilter); + }); + } + addDataDisplay(table); + }); } - protected void addAdvancedSearchFilter(final ColumnFilter columnFilter) { - final FilterSettings settings = view.getAdvancedSearchFilterSettings(); + @Override + public void getData(final Range visibleRange) { + try { + final FilterSettings currentTableSettings = dataSetQueryHelper.getCurrentTableSettings(); + currentTableSettings.setServerTemplateId(getSelectedServerTemplate()); + currentTableSettings.setTablePageSize(view.getListGrid().getPageSize()); + ColumnSortList columnSortList = view.getListGrid().getColumnSortList(); + if (columnSortList != null && columnSortList.size() > 0) { + dataSetQueryHelper.setLastOrderedColumn(columnSortList.size() > 0 ? columnSortList.get(0).getColumn().getDataStoreName() : ""); + dataSetQueryHelper.setLastSortOrder(columnSortList.size() > 0 && columnSortList.get(0).isAscending() ? SortOrder.ASCENDING : SortOrder.DESCENDING); + } + + dataSetQueryHelper.setCurrentTableSettings(currentTableSettings); + dataSetQueryHelper.setDataSetHandler(currentTableSettings); + dataSetQueryHelper.lookupDataSet(visibleRange.getStart(), + getDataSetReadyCallback(visibleRange.getStart(), + currentTableSettings)); + } catch (Exception e) { + errorPopup.showMessage(Constants.INSTANCE.UnexpectedError(e.getMessage())); + view.hideBusyIndicator(); + } + } + + protected abstract DataSetReadyCallback getDataSetReadyCallback(final Integer startRange, + final FilterSettings tableSettings); + + protected void addActiveFilter(final ColumnFilter columnFilter, + final String labelKey, + final String labelValue, + final T value, + final Consumer removeCallback) { + addActiveFilter(columnFilter, + new ActiveFilterItem<>(labelKey, + labelKey + ": " + labelValue, + null, + value, + removeCallback)); + } + + protected void addActiveFilter(final ColumnFilter columnFilter, + final ActiveFilterItem filter) { + filter.setCallback(v -> removeActiveFilter(columnFilter)); + final FilterSettings settings = dataSetQueryHelper.getCurrentTableSettings(); settings.addColumnFilter(columnFilter); - view.saveAdvancedSearchFilterSettings(settings); - filterGrid(settings); + view.addActiveFilter(filter); + refreshGrid(); } - protected void removeAdvancedSearchFilter(final ColumnFilter columnFilter) { - final FilterSettings settings = view.getAdvancedSearchFilterSettings(); - if (settings.removeColumnFilter(columnFilter)) { - view.saveAdvancedSearchFilterSettings(settings); - filterGrid(settings); - } + protected void removeActiveFilter(final ColumnFilter columnFilter) { + final FilterSettings settings = dataSetQueryHelper.getCurrentTableSettings(); + settings.removeColumnFilter(columnFilter); + refreshGrid(); + } + + public void saveSearchFilterSettings(final String filterName, + final Consumer callback) { + final FilterSettings settings = dataSetQueryHelper.getCurrentTableSettings(); + settings.setTableName(filterName); + settings.setTableDescription(filterName); + filterSettingsManager.saveFilterIntoPreferences(settings, + state -> callback.accept(state ? null : Constants.INSTANCE.FilterWithSameNameAlreadyExists())); } protected Optional getSearchParameter(final String parameterId) { @@ -152,17 +226,18 @@ protected void navigateToPerspective(final String perspectiveId, parameterValue); placeManager.goTo(request); } - + public boolean isUserAuthorizedForPerspective(final String perspectiveId) { final ResourceRef resourceRef = new ResourceRef(perspectiveId, ActivityResourceType.PERSPECTIVE); return authorizationManager.authorize(resourceRef, identity); } - - public void openErrorView(final String parameterId) {} - - public Predicate getViewErrorsActionCondition(){ + + public void openErrorView(final String parameterId) { + } + + public Predicate getViewErrorsActionCondition() { return null; } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.html new file mode 100644 index 0000000000..3c2ad428c1 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.html @@ -0,0 +1,8 @@ +
        +
        +
        +
        +
        +
        +
        +
        \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.java index 46aa99051b..90f078c294 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.java @@ -15,10 +15,8 @@ */ package org.jbpm.workbench.common.client.list; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import javax.enterprise.event.Event; @@ -28,198 +26,77 @@ import com.google.gwt.cell.client.CheckboxCell; import com.google.gwt.cell.client.NumberCell; import com.google.gwt.cell.client.TextCell; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.dom.client.Style; -import com.google.gwt.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client.Header; +import com.google.gwt.user.cellview.client.TextHeader; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HasEnabled; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; -import org.dashbuilder.dataset.DataSetLookup; -import org.gwtbootstrap3.client.ui.Button; -import org.gwtbootstrap3.client.ui.constants.ButtonSize; -import org.gwtbootstrap3.client.ui.constants.IconType; +import elemental2.dom.HTMLDivElement; import org.jboss.errai.common.client.api.Caller; -import org.jboss.errai.security.shared.api.identity.User; +import org.jboss.errai.common.client.dom.elemental2.Elemental2DomUtil; +import org.jboss.errai.ioc.client.api.ManagedInstance; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; +import org.jbpm.workbench.common.client.filters.active.ActiveFilters; import org.jbpm.workbench.common.client.resources.i18n.Constants; -import org.jbpm.workbench.common.client.util.DateRange; +import org.jbpm.workbench.common.client.util.ConditionalAction; +import org.jbpm.workbench.common.client.util.ConditionalKebabActionCell; import org.jbpm.workbench.common.model.GenericSummary; -import org.jbpm.workbench.df.client.filter.FilterSettings; -import org.jbpm.workbench.df.client.list.DataSetEditorManager; import org.uberfire.client.mvp.PlaceManager; import org.uberfire.ext.services.shared.preferences.GridGlobalPreferences; import org.uberfire.ext.services.shared.preferences.GridPreferencesStore; -import org.uberfire.ext.services.shared.preferences.MultiGridPreferencesStore; import org.uberfire.ext.services.shared.preferences.UserPreferencesService; import org.uberfire.ext.services.shared.preferences.UserPreferencesType; import org.uberfire.ext.widgets.common.client.common.BusyPopup; -import org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup; -import org.uberfire.ext.widgets.common.client.tables.FilterPagedTable; -import org.uberfire.ext.widgets.common.client.tables.popup.NewTabFilterPopup; import org.uberfire.ext.widgets.table.client.ColumnMeta; -import org.uberfire.mvp.Command; import org.uberfire.workbench.events.NotificationEvent; public abstract class AbstractMultiGridView extends Composite implements MultiGridView { - public static final String TAB_SEARCH = "base"; - public static final String FILTER_TABLE_SETTINGS = "tableSettings"; - public static final String USER_DEFINED = "ud_"; public static final String COL_ID_SELECT = "Select"; public static final String COL_ID_ACTIONS = "Actions"; - private static Binder uiBinder = GWT.create(Binder.class); - - private final Constants constants = Constants.INSTANCE; - - @Inject - protected User identity; - - protected Button createTabButton = GWT.create(Button.class); + public static final int ACTIONS_COLUMN_WIDTH = 120; + public static final int CHECK_COLUMN_WIDTH = 38; + public static final int ERROR_COLUMN_WIDTH = 65; @Inject protected Event notification; - protected DataSetEditorManager dataSetEditorManager; - @Inject - protected PlaceManager placeManager; + protected ManagedInstance conditionalKebabActionCell; @Inject - protected AdvancedSearchFiltersViewImpl advancedSearchFiltersView; - - protected V presenter; - - protected FilterPagedTable filterPagedTable = GWT.create(FilterPagedTable.class); - - protected ExtendedPagedTable currentListGrid; - - @UiField - protected org.gwtbootstrap3.client.ui.Column column; - - private Caller userPreferencesService; - - public AbstractMultiGridView() { - initWidget(uiBinder.createAndBindUi(this)); - column.add(filterPagedTable.makeWidget()); - createTabButton.setIcon(IconType.PLUS); - createTabButton.setSize(ButtonSize.SMALL); - } - - public void init(final V presenter) { - this.presenter = presenter; - - createTabButton.addClickHandler(event -> createNewTab(presenter)); - - userPreferencesService.call((MultiGridPreferencesStore multiGridPreferencesStore) -> { - if (multiGridPreferencesStore == null) { - multiGridPreferencesStore = new MultiGridPreferencesStore(getGridGlobalPreferencesKey()); - } - loadTabsFromPreferences(multiGridPreferencesStore, - presenter); - }).loadUserPreferences(getGridGlobalPreferencesKey(), - UserPreferencesType.MULTIGRIDPREFERENCES); - } - - protected void createNewTab(final V presenter) { - final String key = getValidKeyForAdditionalListGrid(getGridGlobalPreferencesKey() + "_"); - - final Command addNewGrid = () -> { - - final ExtendedPagedTable extendedPagedTable = createGridInstance(key); - - extendedPagedTable.setDataProvider(presenter.getDataProvider()); + protected PlaceManager placeManager; - filterPagedTable.createNewTab(extendedPagedTable, - key, - createTabButton, - (() -> { - currentListGrid = extendedPagedTable; - applyFilterOnPresenter(key); - })); - applyFilterOnPresenter(key); - }; + protected Caller userPreferencesService; - final FilterSettings tableSettings = presenter.createTableSettingsPrototype(); - tableSettings.setKey(key); - dataSetEditorManager.showTableSettingsEditor(filterPagedTable, - getNewFilterPopupTitle(), - tableSettings, - addNewGrid); - } + protected ListTable listTable; - protected void loadTabsFromPreferences(final MultiGridPreferencesStore multiGridPreferencesStore, - final V presenter) { - filterPagedTable.setMultiGridPreferencesStore(multiGridPreferencesStore); - - presenter.setAddingDefaultFilters(true); + protected V presenter; - final ArrayList existingGrids = new ArrayList<>(multiGridPreferencesStore.getGridsId()); + @Inject + @DataField("column") + protected HTMLDivElement column; - if (existingGrids.isEmpty()) { - initDefaultFilters(); - } else { - //Special handling for the search tab when upgrading from previous versions - if (existingGrids.contains(TAB_SEARCH) == false) { - initSearchFilter(); - } - existingGrids.forEach(key -> { - final ExtendedPagedTable extendedPagedTable = loadGridInstance(key); - extendedPagedTable.setDataProvider(presenter.getDataProvider()); - filterPagedTable.addTab(extendedPagedTable, - key, - () -> { - currentListGrid = extendedPagedTable; - applyFilterOnPresenter(key); - }, - false); - }); - //Ensure Search tab is always the first one - if (multiGridPreferencesStore.getGridsId().indexOf(TAB_SEARCH) != 0) { - multiGridPreferencesStore.getGridsId().remove(TAB_SEARCH); - multiGridPreferencesStore.getGridsId().add(0, - TAB_SEARCH); - } - } - multiGridPreferencesStore.setSelectedGrid(TAB_SEARCH); - filterPagedTable.addAddTableButton(createTabButton); - presenter.onGridPreferencesStoreLoaded(); - } + @Inject + @DataField("active-filters") + protected ActiveFilters filters; public void displayNotification(String text) { notification.fire(new NotificationEvent(text)); } - public void showRestoreDefaultFilterConfirmationPopup() { - YesNoCancelPopup yesNoCancelPopup = YesNoCancelPopup.newYesNoCancelPopup(constants.RestoreDefaultFilters(), - constants.AreYouSureRestoreDefaultFilters(), - () -> { - showBusyIndicator(constants.Loading()); - presenter.onRestoreTabs(); - }, - null, - () -> { - }); - yesNoCancelPopup.show(); - } - - public void restoreTabs() { - presenter.setAddingDefaultFilters(true); - final List grids = new ArrayList<>(getMultiGridPreferencesStore().getGridsId()); - grids.forEach(key -> filterPagedTable.removeTab(key)); - filterPagedTable.removeTab(0); - initDefaultFilters(); - filterPagedTable.addAddTableButton(createTabButton); + public void init(final V presenter) { + this.presenter = presenter; } - protected void controlBulkOperations(final ExtendedPagedTable extendedPagedTable) { - Scheduler.get().scheduleDeferred(() -> enableWidgets(Iterables.getFirst(extendedPagedTable.getRightActionsToolbar(), - null), - extendedPagedTable.hasSelectedItems())); + protected void controlBulkOperations(final ListTable extendedPagedTable) { + enableWidgets(Iterables.getFirst(extendedPagedTable.getRightActionsToolbar(), + null), + extendedPagedTable.hasSelectedItems()); } protected void enableWidgets(final Widget widget, @@ -238,59 +115,20 @@ protected void enableWidgets(final Widget widget, } } - public String getValidKeyForAdditionalListGrid(String baseName) { - return filterPagedTable.getValidKeyForAdditionalListGrid(baseName + USER_DEFINED); - } - - public ExtendedPagedTable createGridInstance(final String key) { - final ExtendedPagedTable newListGrid = createExtendedPagedTable(key); + @Override + public void loadListTable(final String key, + final Consumer> readyCallback) { + final GridGlobalPreferences pref = new GridGlobalPreferences(key, + getInitColumns(), + getBannedColumns()); + final ListTable newListGrid = new ListTable(pref); newListGrid.setShowLastPagerButton(false); newListGrid.setShowFastFordwardPagerButton(false); newListGrid.setPreferencesService(userPreferencesService); - initColumns(newListGrid); - initSelectionModel(newListGrid); - newListGrid.loadPageSizePreferences(); - newListGrid.createPageSizesListBox(5, - 20, - 5); - - return newListGrid; - } - - protected ExtendedPagedTable createExtendedPagedTable(final String key) { - GridGlobalPreferences pref; - ExtendedPagedTable table; - if (TAB_SEARCH.equals(key)) { - pref = new GridGlobalPreferences(getGridGlobalPreferencesKey() + key, - getInitColumns(), - getBannedColumns()); - table = createAdvancedSearchTable(pref); - } else { - pref = new GridGlobalPreferences(key, - getInitColumns(), - getBannedColumns()); - table = new ExtendedPagedTable(pref); - } - table.setGridPreferencesStore(new GridPreferencesStore(pref)); - return table; - } - - protected ExtendedPagedTable createAdvancedSearchTable(final GridGlobalPreferences preferences) { - final ExtendedPagedTable advancedSearchTable = new ExtendedPagedTable(preferences); - advancedSearchTable.getElement().getStyle().setPaddingTop(0, - Style.Unit.PX); - advancedSearchTable.getTopToolbar().add(advancedSearchFiltersView); - return advancedSearchTable; - } - - public ExtendedPagedTable loadGridInstance(final String key) { - final ExtendedPagedTable newListGrid = createExtendedPagedTable(key); - newListGrid.setShowLastPagerButton(false); - newListGrid.setShowFastFordwardPagerButton(false); - newListGrid.dataGrid.addRedrawHandler(() -> controlBulkOperations(newListGrid)); userPreferencesService.call((GridPreferencesStore preferencesStore) -> { - newListGrid.setPreferencesService(userPreferencesService); - if(preferencesStore != null) { + if (preferencesStore == null) { + newListGrid.setGridPreferencesStore(new GridPreferencesStore(pref)); + } else { newListGrid.setGridPreferencesStore(preferencesStore); } initColumns(newListGrid); @@ -299,10 +137,15 @@ public ExtendedPagedTable loadGridInstance(final String key) { newListGrid.createPageSizesListBox(5, 20, 5); - }).loadUserPreferences(newListGrid.getGridPreferencesStore().getPreferenceKey(), + if (column.childNodes.length == 1) { + column.removeChild(column.firstChild); + } + new Elemental2DomUtil().appendWidgetToElement(column, + newListGrid); + listTable = newListGrid; + readyCallback.accept(listTable); + }).loadUserPreferences(key, UserPreferencesType.GRIDPREFERENCES); - - return newListGrid; } public void showBusyIndicator(final String message) { @@ -313,152 +156,25 @@ public void hideBusyIndicator() { BusyPopup.close(); } - public ExtendedPagedTable getListGrid() { - return currentListGrid; + public ListTable getListGrid() { + return listTable; } /* * For each specific implementation define the * DataGrid columns and how they must be initialized */ - public abstract void initColumns(ExtendedPagedTable extendedPagedTable); + public abstract void initColumns(ListTable extendedPagedTable); - public abstract void initSelectionModel(ExtendedPagedTable extendedPagedTable); + public abstract void initSelectionModel(ListTable extendedPagedTable); public abstract List getInitColumns(); public abstract List getBannedColumns(); - public abstract String getGridGlobalPreferencesKey(); - - public abstract String getNewFilterPopupTitle(); - - public MultiGridPreferencesStore getMultiGridPreferencesStore() { - if (filterPagedTable != null) { - return filterPagedTable.getMultiGridPreferencesStore(); - } - return null; - } - - public void initDefaultFilters() { - initSearchFilter(); - } - - protected void initSearchFilter() { - //Search Tab - final FilterSettings settings = presenter.createSearchTabSettings(); - settings.setTableName(constants.Search()); - settings.setTableDescription(constants.SearchResults()); - settings.setKey(TAB_SEARCH); - addNewTab(settings); - } - - public void initTabFilter(final FilterSettings tableSettings, - final String key, - final String tabName, - final String tabDesc, - final String dataSetUUID) { - - tableSettings.setKey(key); - tableSettings.setTableName(tabName); - tableSettings.setTableDescription(tabDesc); - tableSettings.setUUID(dataSetUUID); - - addNewTab(tableSettings); - } - - public void addNewTab(final FilterSettings tableSettings) { - final HashMap tabSettingsValues = new HashMap<>(); - - tabSettingsValues.put(FILTER_TABLE_SETTINGS, - dataSetEditorManager.getTableSettingsToStr(tableSettings)); - tabSettingsValues.put(NewTabFilterPopup.FILTER_TAB_NAME_PARAM, - tableSettings.getTableName()); - tabSettingsValues.put(NewTabFilterPopup.FILTER_TAB_DESC_PARAM, - tableSettings.getTableDescription()); - - filterPagedTable.saveNewTabSettings(tableSettings.getKey(), - tabSettingsValues); - - final ExtendedPagedTable extendedPagedTable = createGridInstance(tableSettings.getKey()); - currentListGrid = extendedPagedTable; - extendedPagedTable.setDataProvider(presenter.getDataProvider()); - - filterPagedTable.addTab(extendedPagedTable, - tableSettings.getKey(), - () -> { - currentListGrid = extendedPagedTable; - applyFilterOnPresenter(tableSettings.getKey()); - }, - false - ); - } - - public void selectFirstTabAndEnableQueries() { - Scheduler.get().scheduleDeferred(getSelectFirstTabAndEnableQueriesCommand()); - } - - protected Scheduler.ScheduledCommand getSelectFirstTabAndEnableQueriesCommand() { - return () -> { - presenter.setAddingDefaultFilters(false); - getMultiGridPreferencesStore().setSelectedGrid(TAB_SEARCH); - filterPagedTable.setSelectedTab(); - }; - } - - public void applyFilterOnPresenter(final String key) { - applyFilterOnPresenter(getTableFilterSettings(key)); - } - - public void applyFilterOnPresenter(final FilterSettings filterSettings) { - presenter.filterGrid(filterSettings); - } - - protected FilterSettings getTableFilterSettings(final String key) { - final HashMap params = getGridSettings(key); - final String tableSettingsJSON = (String) params.get(FILTER_TABLE_SETTINGS); - return dataSetEditorManager.getStrToTableSettings(tableSettingsJSON); - } - - @Override - public FilterSettings getAdvancedSearchFilterSettings() { - return getTableFilterSettings(TAB_SEARCH); - } - - @Override - public void saveAdvancedSearchFilterSettings(final FilterSettings settings) { - final HashMap gridSettings = getGridSettings(TAB_SEARCH); - gridSettings.put(FILTER_TABLE_SETTINGS, - dataSetEditorManager.getTableSettingsToStr(settings)); - filterPagedTable.saveTabSettings(TAB_SEARCH, - gridSettings); - } - - protected HashMap getGridSettings(final String key) { - return filterPagedTable.getMultiGridPreferencesStore().getGridSettings(key); - } - - public void setIdentity(User identity) { - this.identity = identity; - } - @Inject public void setUserPreferencesService(final Caller userPreferencesService) { this.userPreferencesService = userPreferencesService; - this.filterPagedTable.setPreferencesService(userPreferencesService); - } - - @Inject - public void setDataSetEditorManager(final DataSetEditorManager dataSetEditorManager) { - this.dataSetEditorManager = dataSetEditorManager; - } - - public FilterPagedTable getFilterPagedTable() { - return filterPagedTable; - } - - public void setFilterPagedTable(FilterPagedTable filterPagedTable) { - this.filterPagedTable = filterPagedTable; } public Column createTextColumn(final String columnId, @@ -487,17 +203,21 @@ public Number getValue(T domain) { return column; } - protected ColumnMeta initChecksColumn(final ExtendedPagedTable extendedPagedTable) { + protected ColumnMeta initChecksColumn(final ListTable extendedPagedTable) { CheckboxCell checkboxCell = new CheckboxCell(true, false); Column checkColumn = new Column(checkboxCell) { @Override - public Boolean getValue(T pis) { + public Boolean getValue(T item) { // Get the value from the selection model. - return pis.isSelected(); + return extendedPagedTable.isItemSelected(item); } }; + checkColumn.setSortable(false); + checkColumn.setDataStoreName(COL_ID_SELECT); + checkColumn.setCellStyleNames("kie-datatable-select"); + Header selectPageHeader = new Header(checkboxCell) { @Override public Boolean getValue() { @@ -506,109 +226,67 @@ public Boolean getValue() { }; selectPageHeader.setUpdater(value -> { - getListGrid().getVisibleItems().forEach(pis -> extendedPagedTable.setItemSelection(pis, - value)); - getListGrid().redraw(); + if (value) { + extendedPagedTable.selectAllItems(); + } else { + extendedPagedTable.deselectAllItems(); + } + controlBulkOperations(extendedPagedTable); + }); + selectPageHeader.setHeaderStyleNames("kie-datatable-select"); + + checkColumn.setFieldUpdater((int index, + T model, + Boolean value) -> { + extendedPagedTable.setItemSelection(model, + value); + + controlBulkOperations(extendedPagedTable); }); - checkColumn.setSortable(false); - checkColumn.setDataStoreName(COL_ID_SELECT); ColumnMeta checkColMeta = new ColumnMeta(checkColumn, ""); checkColMeta.setHeader(selectPageHeader); return checkColMeta; } - public int getRefreshValue() { - return getMultiGridPreferencesStore().getRefreshInterval(); - } + protected abstract List> getConditionalActions(); - public void saveRefreshValue(int newValue) { - filterPagedTable.saveNewRefreshInterval(newValue); - } + protected ColumnMeta initActionsColumn() { + final ConditionalKebabActionCell cell = conditionalKebabActionCell.get(); - @Override - public void addTextFilter(String label, - String placeholder, - Consumer addCallback, - Consumer removeCallback) { - advancedSearchFiltersView.addTextFilter(label, - placeholder, - addCallback, - removeCallback); - } + cell.setActions(getConditionalActions()); - @Override - public void addNumericFilter(String label, - String placeholder, - Consumer addCallback, - Consumer removeCallback) { - advancedSearchFiltersView.addNumericFilter(label, - placeholder, - addCallback, - removeCallback); - } + Column actionsColumn = new Column(cell) { + @Override + public T getValue(T object) { + return object; + } + }; + actionsColumn.setDataStoreName(COL_ID_ACTIONS); + actionsColumn.setCellStyleNames("kie-table-view-pf-actions text-center"); - @Override - public void addSelectFilter(String label, - Map options, - Boolean liveSearch, - Consumer addCallback, - Consumer removeCallback) { - advancedSearchFiltersView.addSelectFilter(label, - options, - liveSearch, - addCallback, - removeCallback); - } + Header header = new TextHeader(Constants.INSTANCE.Actions()); + header.setHeaderStyleNames("text-center"); - @Override - public void addActiveFilter(String labelKey, - String labelValue, - T value, - Consumer removeCallback) { - advancedSearchFiltersView.addActiveFilter(labelKey, - labelValue, - value, - removeCallback); + final ColumnMeta actionsColMeta = new ColumnMeta(actionsColumn, + ""); + actionsColMeta.setHeader(header); + return actionsColMeta; } @Override - public void addDataSetSelectFilter(String label, - String tableKey, - DataSetLookup lookup, - String textColumnId, - String valueColumnId, - Consumer addCallback, - Consumer removeCallback) { - advancedSearchFiltersView.addDataSetSelectFilter(label, - tableKey, - lookup, - textColumnId, - valueColumnId, - addCallback, - removeCallback); + public void setSaveFilterCallback(final BiConsumer> filterNameCallback) { + filters.setSaveFilterCallback(filterNameCallback); } @Override - public void addDateRangeFilter(String label, - String placeholder, - Boolean useMaxDate, - Consumer addCallback, - Consumer removeCallback) { - advancedSearchFiltersView.addDateRangeFilter(label, - placeholder, - useMaxDate, - addCallback, - removeCallback); + public void addActiveFilter(final ActiveFilterItem filter) { + filters.addActiveFilter(filter); } @Override public void removeAllActiveFilters() { - advancedSearchFiltersView.removeAllActiveFilters(); - } - - interface Binder extends UiBinder { - + filters.removeAllActiveFilters(); } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.ui.xml b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.ui.xml deleted file mode 100644 index fce689e72b..0000000000 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractMultiGridView.ui.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - .container { - padding-top: 20px; - padding-bottom: 20px; - } - - - - - - - - - diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractScreenListPresenter.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractScreenListPresenter.java index 88643300bf..c45d410c9d 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractScreenListPresenter.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AbstractScreenListPresenter.java @@ -17,13 +17,23 @@ import java.util.Optional; +import com.google.gwt.user.client.ui.IsWidget; import org.jboss.errai.security.shared.api.identity.User; -import org.jbpm.workbench.common.events.ServerTemplateSelected; +import org.jbpm.workbench.common.client.PerspectiveIds; +import org.jbpm.workbench.common.client.menu.ManageSelector; import org.jbpm.workbench.common.client.menu.ServerTemplateSelectorMenuBuilder; +import org.jbpm.workbench.common.client.resources.i18n.Constants; +import org.jbpm.workbench.common.events.ServerTemplateSelected; +import org.uberfire.client.annotations.WorkbenchPartTitle; +import org.uberfire.client.annotations.WorkbenchPartTitleDecoration; +import org.uberfire.client.mvp.PerspectiveManager; import org.uberfire.client.mvp.PlaceManager; +import org.uberfire.client.workbench.events.ClosePlaceEvent; +import org.uberfire.ext.widgets.common.client.breadcrumbs.UberfireBreadcrumbs; import org.uberfire.lifecycle.OnFocus; import org.uberfire.lifecycle.OnOpen; import org.uberfire.lifecycle.OnStartup; +import org.uberfire.mvp.Commands; import org.uberfire.mvp.PlaceRequest; import javax.enterprise.event.Observes; @@ -36,20 +46,50 @@ public abstract class AbstractScreenListPresenter extends AbstractListPresent protected User identity; + private String detailScreenId; + @Inject protected PlaceManager placeManager; + @Inject + private PerspectiveManager perspectiveManager; + + @Inject + UberfireBreadcrumbs breadcrumbs; + protected PlaceRequest place; protected ServerTemplateSelectorMenuBuilder serverTemplateSelectorMenuBuilder; + @Inject + protected ManageSelector manageSelector; + private String selectedServerTemplate = ""; + @WorkbenchPartTitle + public String getTitle() { + return Constants.INSTANCE.Manage(); + } + + @WorkbenchPartTitleDecoration + public IsWidget getTitleDecorator() { + return manageSelector.getManageSelectorWidget(); + } + @OnOpen public void onOpen() { + createListBreadcrumb(); setSelectedServerTemplate(serverTemplateSelectorMenuBuilder.getSelectedServerTemplate()); } + public void onDetailScreenClosed(@Observes ClosePlaceEvent closed) { + if (closed.getPlace() != null + && detailScreenId != null + && detailScreenId.equals(closed.getPlace().getIdentifier())) { + createListBreadcrumb(); + } + } + @OnFocus public void onFocus() { setSelectedServerTemplate(serverTemplateSelectorMenuBuilder.getSelectedServerTemplate()); @@ -58,6 +98,12 @@ public void onFocus() { @OnStartup public void onStartup(final PlaceRequest place) { this.place = place; + breadcrumbs.addToolbar(getPerspectiveId(), + serverTemplateSelectorMenuBuilder.getView().getElement()); + } + + public String getPerspectiveId() { + return perspectiveManager.getCurrentPerspective().getIdentifier(); } @Inject @@ -80,9 +126,57 @@ public String getSelectedServerTemplate() { public void setSelectedServerTemplate(final String selectedServerTemplate) { final String newServerTemplate = Optional.ofNullable(selectedServerTemplate).orElse("").trim(); - if (this.selectedServerTemplate.equals(newServerTemplate) == false) { + if (!this.selectedServerTemplate.equals(newServerTemplate)) { this.selectedServerTemplate = newServerTemplate; refreshGrid(); } } + + public abstract void createListBreadcrumb(); + + public void setupListBreadcrumb(PlaceManager placeManager, + String listLabel) { + breadcrumbs.clearBreadcrumbs(getPerspectiveId()); + + breadcrumbs.addBreadCrumb(getPerspectiveId(), + Constants.INSTANCE.Home(), + () -> placeManager.goTo(PerspectiveIds.HOME)); + breadcrumbs.addBreadCrumb(getPerspectiveId(), + listLabel, + Commands.DO_NOTHING); + } + + public void setupDetailBreadcrumb(PlaceManager placeManager, + String listLabel, + String detailLabel, + String detailScreenId) { + breadcrumbs.clearBreadcrumbs(getPerspectiveId()); + breadcrumbs.addBreadCrumb(getPerspectiveId(), + Constants.INSTANCE.Home(), + () -> placeManager.goTo(PerspectiveIds.HOME)); + breadcrumbs.addBreadCrumb(getPerspectiveId(), + listLabel, + () -> closeDetails(detailScreenId)); + breadcrumbs.addBreadCrumb(getPerspectiveId(), + detailLabel, + Commands.DO_NOTHING); + this.detailScreenId = detailScreenId; + } + + private void closeDetails(String detailScreenId) { + placeManager.closePlace(detailScreenId); + createListBreadcrumb(); + } + + public void setUberfireBreadcrumbs(UberfireBreadcrumbs breadcrumbs) { + this.breadcrumbs = breadcrumbs; + } + + public void setPerspectiveManager(PerspectiveManager perspectiveManager) { + this.perspectiveManager = perspectiveManager; + } + + public void setPlaceManager(PlaceManager placeManager) { + this.placeManager = placeManager; + } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemRemoved.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemRemoved.java deleted file mode 100644 index a192e27538..0000000000 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ActiveFilterItemRemoved.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. - * - * Licensed 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.jbpm.workbench.common.client.list; - -public class ActiveFilterItemRemoved { - - private ActiveFilterItem activeFilterItem; - - public ActiveFilterItemRemoved(final ActiveFilterItem activeFilterItem) { - this.activeFilterItem = activeFilterItem; - } - - public ActiveFilterItem getActiveFilterItem() { - return activeFilterItem; - } -} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.html deleted file mode 100644 index 2df5f74661..0000000000 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/AdvancedSearchFiltersViewImpl.html +++ /dev/null @@ -1,50 +0,0 @@ -
        -
        -
        -
        -
        -
        - - -
        -
        -
        - - - -
        -
        -
        -
        -
        -
        -
        - - -
        -
        -
        -
        -
        -
        -
        -
        -
        -

        :

        -
        -
        -
          -

          -
          -
          -
          -
          \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ExtendedPagedTable.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ExtendedPagedTable.java index 8ddb0f8bb8..e62ac6abc9 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ExtendedPagedTable.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ExtendedPagedTable.java @@ -18,20 +18,16 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.stream.StreamSupport; import com.google.gwt.dom.client.BrowserEvents; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.InputElement; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client.ColumnSortEvent.AsyncHandler; import com.google.gwt.view.client.CellPreviewEvent; import com.google.gwt.view.client.DefaultSelectionEventManager; import com.google.gwt.view.client.NoSelectionModel; -import org.jbpm.workbench.common.client.resources.CommonResources; -import org.jbpm.workbench.common.client.resources.css.CommonCSS; import org.jbpm.workbench.common.model.GenericSummary; import org.uberfire.ext.services.shared.preferences.GridGlobalPreferences; import org.uberfire.ext.widgets.common.client.tables.PagedTable; @@ -39,15 +35,11 @@ public class ExtendedPagedTable extends PagedTable { - private final CommonCSS commonCSS = CommonResources.INSTANCE.css(); - private List> ignoreSelectionColumns = new ArrayList>(); - private int selectedRow = -1; - - private List selectedItems; + private List selectedItems = new ArrayList(); - private BiConsumer selectionCallback = null; + private Consumer selectionCallback; public ExtendedPagedTable(final GridGlobalPreferences gridPreferences) { super(DEFAULT_PAGE_SIZE, @@ -58,17 +50,9 @@ public ExtendedPagedTable(final GridGlobalPreferences gridPreferences) { false, false); - selectedItems = new ArrayList(); dataGrid.addColumnSortHandler(new AsyncHandler(dataGrid)); setSelectionModel(createSelectionModel(), createNoActionColumnManager()); - setRowStyles((T row, - int rowIndex) -> { - if (rowIndex == selectedRow) { - return commonCSS.selected(); - } - return null; - }); } public void setTooltip(int row, @@ -119,7 +103,7 @@ public List getSelectedItems() { return selectedItems; } - public void setSelectedItems(List selectedItems) { + protected void setSelectedItems(List selectedItems) { this.selectedItems = selectedItems; } @@ -128,49 +112,63 @@ public boolean isItemSelected(T item) { } public boolean hasSelectedItems() { - return StreamSupport.stream(this.getVisibleItems().spliterator(), - false).anyMatch(domain -> domain.isSelected()); + return StreamSupport.stream(getVisibleItems().spliterator(), + false).anyMatch(item -> isItemSelected(item)); } public void deselectAllItems() { - this.getVisibleItems().forEach(pis -> pis.setSelected(false)); - selectedItems = new ArrayList(); + for (int i = 0; i < getVisibleItemCount(); i++) { + final T item = getVisibleItem(i); + if (selectedItems.contains(item)) { + updateSelectedColumnRow(i, + item, + false); + } + } + selectedItems.clear(); + } + + public void selectAllItems() { + for (int i = 0; i < getVisibleItemCount(); i++) { + final T item = getVisibleItem(i); + if (selectedItems.contains(item) == false) { + updateSelectedColumnRow(i, + item, + true); + selectedItems.add(item); + } + } + } + + public void updateSelectedColumnRow(final Integer row, + final T object, + final Boolean value) { + final Column column = (Column) this.dataGrid.getColumn(0); + column.getFieldUpdater().update(row, + object, + value); + dataGrid.redrawRow(row); } public boolean isAllItemsSelected() { - if (this.getVisibleItemCount() == 0) { + if (getVisibleItemCount() == 0) { return false; } else { - return StreamSupport.stream(this.getVisibleItems().spliterator(), - false).allMatch(pis -> pis.isSelected()); + return StreamSupport.stream(getVisibleItems().spliterator(), + false).allMatch(item -> isItemSelected(item)); } } protected NoSelectionModel createSelectionModel() { final NoSelectionModel selectionModel = new NoSelectionModel(); - final ExtendedPagedTable extendedPagedTable = this; selectionModel.addSelectionChangeHandler(event -> { - boolean close = false; - if (selectedRow == -1 || extendedPagedTable.getKeyboardSelectedRow() != selectedRow) { - selectedRow = extendedPagedTable.getKeyboardSelectedRow(); - extendedPagedTable.redraw(); - } else { - close = true; - } - if (selectionCallback != null) { - selectionCallback.accept(selectionModel.getLastSelectedObject(), - close); + selectionCallback.accept(selectionModel.getLastSelectedObject()); } }); return selectionModel; } - public void setVisibleSelectedItems() { - getVisibleItems().forEach(item -> item.setSelected(isItemSelected(item))); - redraw(); - } - protected DefaultSelectionEventManager createNoActionColumnManager() { final ExtendedPagedTable extendedPagedTable = this; return DefaultSelectionEventManager.createCustomManager(new DefaultSelectionEventManager.EventTranslator() { @@ -182,59 +180,37 @@ public boolean clearCurrentSelection(CellPreviewEvent event) { @Override public DefaultSelectionEventManager.SelectAction translateSelectionEvent(CellPreviewEvent event) { - DefaultSelectionEventManager.SelectAction ret = DefaultSelectionEventManager.SelectAction.DEFAULT; NativeEvent nativeEvent = event.getNativeEvent(); - if (BrowserEvents.CLICK.equals(nativeEvent.getType())) { + if (BrowserEvents.CLICK.equals(nativeEvent.getType()) && extendedPagedTable.isSelectionIgnoreColumn(event.getColumn())) { // Ignore if the event didn't occur in the correct column. - if (extendedPagedTable.isSelectionIgnoreColumn(event.getColumn())) { - ret = DefaultSelectionEventManager.SelectAction.IGNORE; - } - //Extension for checkboxes - Element target = nativeEvent.getEventTarget().cast(); - if ("input".equals(target.getTagName().toLowerCase())) { - final InputElement input = target.cast(); - if ("checkbox".equals(input.getType().toLowerCase())) { - // Synchronize the checkbox with the current selection state. - final T domain = event.getValue(); - if (domain.isSelected()) { - input.setChecked(false); - setItemSelection(domain, - false); - } else { - input.setChecked(true); - setItemSelection(domain, - true); - } - extendedPagedTable.redraw(); - ret = DefaultSelectionEventManager.SelectAction.IGNORE; - } - } + return DefaultSelectionEventManager.SelectAction.IGNORE; + } else { + return DefaultSelectionEventManager.SelectAction.DEFAULT; } - return ret; } }); } - public void setSelectionCallback(final BiConsumer selectionCallback) { + public void setSelectionCallback(final Consumer selectionCallback) { this.selectionCallback = selectionCallback; } - public int getSelectedRow() { - return selectedRow; - } + public void setItemSelection(final T item, + final Boolean newValue) { + if (item == null) { + return; + } - public void setItemSelection(T item, - boolean newValue) { - if (item == null || selectedItems == null) { + if (newValue == isItemSelected(item)) { return; } - boolean prevSelected = isItemSelected(item); - if (newValue && !prevSelected) { + + if (newValue) { selectedItems.add(item); - } - if (!newValue && prevSelected) { + } else { selectedItems.remove(item); } - item.setSelected(newValue); + + dataGrid.redrawHeaders(); } } diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListTable.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListTable.java new file mode 100644 index 0000000000..be559c17d5 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListTable.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.list; + +import org.jbpm.workbench.common.model.GenericSummary; +import org.uberfire.ext.services.shared.preferences.GridGlobalPreferences; + +public class ListTable extends ExtendedPagedTable { + + public static final int ROW_HEIGHT_PX = 47; + + public ListTable(GridGlobalPreferences gridPreferences) { + super(gridPreferences); + this.addDataGridStyles("kie-datatable", "kie-datatable"); + this.dataGrid.setStriped(false); + } + + @Override + protected void setTableHeight() { + int base = dataGrid.getRowCount() - dataGrid.getVisibleRange().getStart(); + int height = ((base <= 0 ? 1 : base) * ROW_HEIGHT_PX) + HEIGHT_OFFSET_PX; + this.dataGrid.setHeight(height + "px"); + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListView.java index fd19a7706c..e7d266c136 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListView.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/ListView.java @@ -31,7 +31,5 @@ public interface ListView extends IsWidget, void displayNotification(String text); - void showRestoreDefaultFilterConfirmationPopup(); - ExtendedPagedTable getListGrid(); } diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/MultiGridView.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/MultiGridView.java index cbfc23c86e..dee618b937 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/MultiGridView.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/list/MultiGridView.java @@ -16,23 +16,20 @@ package org.jbpm.workbench.common.client.list; -import org.jbpm.workbench.common.model.GenericSummary; -import org.jbpm.workbench.df.client.filter.FilterSettings; - -public interface MultiGridView extends ListView, - AdvancedSearchFiltersView { +import java.util.function.BiConsumer; +import java.util.function.Consumer; - int getRefreshValue(); - - void saveRefreshValue(int newValue); +import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; +import org.jbpm.workbench.common.model.GenericSummary; - void applyFilterOnPresenter(String key); +public interface MultiGridView extends ListView { - FilterSettings getAdvancedSearchFilterSettings(); + void addActiveFilter(ActiveFilterItem filter); - void saveAdvancedSearchFilterSettings(final FilterSettings settings); + void removeAllActiveFilters(); - void selectFirstTabAndEnableQueries(); + void loadListTable(String key, + Consumer> callback); - void restoreTabs(); + void setSaveFilterCallback(BiConsumer> filterNameCallback); } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/resources/org/jbpm/workbench/common/client/resources/css/common.css b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelector.java similarity index 71% rename from jbpm-wb-common/jbpm-wb-common-client/src/main/resources/org/jbpm/workbench/common/client/resources/css/common.css rename to jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelector.java index 5a7f569605..cb88db39ed 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/resources/org/jbpm/workbench/common/client/resources/css/common.css +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,11 @@ * limitations under the License. */ -.selected td { - background-color: #7dc3e8; +package org.jbpm.workbench.common.client.menu; + +import com.google.gwt.user.client.ui.IsWidget; + +public interface ManageSelector { + + IsWidget getManageSelectorWidget(); } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorImpl.java new file mode 100644 index 0000000000..7507d4a021 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorImpl.java @@ -0,0 +1,136 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.menu; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import com.google.gwt.user.client.ui.IsWidget; +import org.jboss.errai.common.client.api.elemental2.IsElement; +import org.jboss.errai.common.client.ui.ElementWrapperWidget; +import org.jboss.errai.security.shared.api.identity.User; +import org.jbpm.workbench.common.client.PerspectiveIds; +import org.jbpm.workbench.common.client.resources.i18n.Constants; +import org.uberfire.client.mvp.ActivityManager; +import org.uberfire.client.mvp.PerspectiveManager; +import org.uberfire.client.mvp.PlaceManager; + +import org.uberfire.mvp.Command; +import org.uberfire.mvp.impl.DefaultPlaceRequest; +import org.uberfire.security.ResourceRef; +import org.uberfire.security.authz.AuthorizationManager; +import org.uberfire.workbench.model.ActivityResourceType; + +@Dependent +public class ManageSelectorImpl implements ManageSelector { + + private static final Map availablePerspectives; + + @Inject + ManageSelectorView view; + + @Inject + private ActivityManager activityManager; + + @Inject + private AuthorizationManager authorizationManager; + + @Inject + private PerspectiveManager perspectiveManager; + + @Inject + private User identity; + + @Inject + private PlaceManager placeManager; + + static { + Map perspectives = new HashMap<>(); + + perspectives.put(PerspectiveIds.PROCESS_DEFINITIONS, + Constants.INSTANCE.Process_Definitions()); + perspectives.put(PerspectiveIds.PROCESS_INSTANCES, + Constants.INSTANCE.Process_Instances()); + perspectives.put(PerspectiveIds.TASKS_ADMIN, + Constants.INSTANCE.Tasks()); + perspectives.put(PerspectiveIds.EXECUTION_ERRORS, + Constants.INSTANCE.ExecutionErrors()); + perspectives.put(PerspectiveIds.JOBS, + Constants.INSTANCE.Jobs()); + + availablePerspectives = Collections.unmodifiableMap(perspectives); + } + + @PostConstruct + public void init() { + view.removeAllOptions(); + String currentPerspectiveId = perspectiveManager.getCurrentPerspective().getIdentifier(); + availablePerspectives.keySet().forEach(perspectiveId -> addPerspective(perspectiveId, + availablePerspectives.get(perspectiveId), + perspectiveId.equals(currentPerspectiveId))); + + view.setOptionChangeCommand(() -> goToPerspective(view.getSelectedOption())); + view.refresh(); + } + + private boolean hasAccessToPerspective(String perspectiveId) { + ResourceRef resourceRef = new ResourceRef(perspectiveId, + ActivityResourceType.PERSPECTIVE); + return authorizationManager.authorize(resourceRef, + identity); + } + + protected void addPerspective(String perspectiveId, + String optionLabel, + boolean selected) { + if (hasAccessToPerspective(perspectiveId) && + !activityManager.getActivities(new DefaultPlaceRequest(perspectiveId)).isEmpty()) { + view.addOption(optionLabel, + perspectiveId, + selected); + } + } + + public void goToPerspective(String perspectiveId) { + if (perspectiveId != null && !perspectiveId.isEmpty()) { + placeManager.goTo(new DefaultPlaceRequest(perspectiveId)); + } + } + + public IsWidget getManageSelectorWidget() { + return ElementWrapperWidget.getWidget(view.getElement()); + } + + public interface ManageSelectorView extends IsElement { + + void addOption(String label, + String value, + boolean selected); + + void removeAllOptions(); + + void setOptionChangeCommand(Command changeCommand); + + void refresh(); + + String getSelectedOption(); + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorViewImpl.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorViewImpl.html new file mode 100644 index 0000000000..ad8986fa8f --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorViewImpl.html @@ -0,0 +1,3 @@ +
          + +
          diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorViewImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorViewImpl.java new file mode 100644 index 0000000000..b5a714ca7b --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ManageSelectorViewImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.menu; + +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import elemental2.dom.HTMLDivElement; +import elemental2.dom.HTMLElement; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.Templated; +import org.uberfire.client.views.pfly.widgets.Select; +import org.uberfire.mvp.Command; + +@Dependent +@Templated +public class ManageSelectorViewImpl implements ManageSelectorImpl.ManageSelectorView { + + @Inject + @DataField("container") + HTMLDivElement container; + + @Inject + @DataField("selector") + private Select selector; + + @Override + public void addOption(String label, + String value, + boolean selected) { + selector.addOption(label, + value, + selected); + } + + @Override + public void removeAllOptions() { + selector.removeAllOptions(); + } + + @Override + public void setOptionChangeCommand(Command changeCommand) { + selector.getElement().addEventListener("change", + event -> changeCommand.execute(), + false); + } + + @Override + public void refresh() { + selector.refresh(); + } + + @Override + public String getSelectedOption() { + return selector.getValue(); + } + + @Override + public HTMLElement getElement() { + return container; + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/PrimaryActionMenuBuilder.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/PrimaryActionMenuBuilder.java new file mode 100644 index 0000000000..72ffd3baaa --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/PrimaryActionMenuBuilder.java @@ -0,0 +1,138 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.menu; + +import elemental2.dom.HTMLElement; +import org.jboss.errai.ioc.client.container.IOC; +import org.uberfire.client.views.pfly.widgets.Button; +import org.uberfire.mvp.Command; +import org.uberfire.workbench.model.menu.MenuFactory; +import org.uberfire.workbench.model.menu.MenuItem; +import org.uberfire.workbench.model.menu.impl.BaseMenuCustom; + +public class PrimaryActionMenuBuilder implements MenuFactory.CustomMenuBuilder { + + private boolean isOn = true; + private Button button; + + public PrimaryActionMenuBuilder(final String label, + final Command command) { + initPrimaryActionButton(label, + "", + ""); + button.setClickHandler(() -> command.execute()); + } + + public PrimaryActionMenuBuilder(final String onLabel, + final String onIcon, + final String onTitle, + final String offLabel, + final String offIcon, + final String offTitle, + final Command command) { + + isOn = true; + initPrimaryActionLink(onLabel, + onIcon, + onTitle); + button.setClickHandler(() -> { + if (isOn) { + setupButton(offLabel, + offIcon, + offTitle); + } else { + setupButton(onLabel, + onIcon, + onTitle); + } + command.execute(); + isOn = !isOn; + }); + } + + @Override + public void push(MenuFactory.CustomMenuBuilder element) { + } + + @Override + public MenuItem build() { + return new BaseMenuCustom() { + @Override + public HTMLElement build() { + return button.getElement(); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public void setEnabled(boolean enabled) { + + } + }; + } + + private void initPrimaryActionButton(String label, + String icon, + String title) { + button = IOC.getBeanManager().lookupBean(Button.class).newInstance(); + button.setType(Button.ButtonType.BUTTON); + button.setButtonStyleType(Button.ButtonStyleType.PRIMARY); + setupButton(label, + icon, + title); + } + + private void initPrimaryActionLink(String label, + String icon, + String title) { + button = IOC.getBeanManager().lookupBean(Button.class).newInstance(); + button.setButtonStyleType(Button.ButtonStyleType.LINK); + setupButton(label, + icon, + title); + } + + private void setupButton(String label, + String icon, + String title) { + while (button.getElement().hasChildNodes()) { + button.getElement().removeChild(button.getElement().lastChild); + } + + if (label != null && !label.isEmpty()) { + button.setText(label); + } + if (icon != null && !icon.isEmpty()) { + button.addIcon("fa", + icon); + } + if (title != null && !title.isEmpty()) { + button.getElement().title = title; + } + } + + public void setVisible(boolean visible) { + if (visible) { + button.show(); + } else { + button.hide(); + } + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/RefreshMenuBuilder.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/RefreshMenuBuilder.java new file mode 100644 index 0000000000..f02dddc5d6 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/RefreshMenuBuilder.java @@ -0,0 +1,74 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.menu; + +import elemental2.dom.HTMLElement; +import org.jboss.errai.ioc.client.container.IOC; +import org.uberfire.client.views.pfly.widgets.Button; +import org.uberfire.ext.widgets.common.client.resources.i18n.CommonConstants; +import org.uberfire.workbench.model.menu.MenuFactory; +import org.uberfire.workbench.model.menu.MenuItem; +import org.uberfire.workbench.model.menu.impl.BaseMenuCustom; + +public class RefreshMenuBuilder implements MenuFactory.CustomMenuBuilder { + + protected Button menuRefreshButton; + private SupportsRefresh supportsRefresh; + + public RefreshMenuBuilder(final SupportsRefresh supportsRefresh) { + this.supportsRefresh = supportsRefresh; + setupMenuButton(); + } + + @Override + public void push(MenuFactory.CustomMenuBuilder element) { + } + + @Override + public MenuItem build() { + return new BaseMenuCustom() { + @Override + public HTMLElement build() { + return menuRefreshButton.getElement(); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public void setEnabled(boolean enabled) { + + } + }; + } + + public void setupMenuButton() { + menuRefreshButton = IOC.getBeanManager().lookupBean(Button.class).newInstance(); + menuRefreshButton.setButtonStyleType(Button.ButtonStyleType.LINK); + menuRefreshButton.addIcon("fa", + "fa-refresh"); + menuRefreshButton.getElement().title = CommonConstants.INSTANCE.Refresh(); + menuRefreshButton.setClickHandler(() -> supportsRefresh.onRefresh()); + } + + public interface SupportsRefresh { + + void onRefresh(); + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorMenuBuilder.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorMenuBuilder.java index 930c2d2d29..c5854ce69b 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorMenuBuilder.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorMenuBuilder.java @@ -32,6 +32,7 @@ import org.kie.server.controller.api.model.events.ServerTemplateUpdated; import org.kie.server.controller.api.model.spec.ServerTemplateList; import org.kie.workbench.common.screens.server.management.service.SpecManagementService; +import org.uberfire.client.mvp.UberElement; import org.uberfire.mvp.ParameterizedCommand; import org.uberfire.workbench.model.menu.MenuFactory; import org.uberfire.workbench.model.menu.MenuItem; @@ -41,7 +42,10 @@ public class ServerTemplateSelectorMenuBuilder implements MenuFactory.CustomMenuBuilder { @Inject - private ServerTemplateSelectorView view; + private ServerTemplateSelectorWidgetView widgetView; + + @Inject + private ServerTemplateSelectorElementView view; @Inject private Caller specManagementService; @@ -51,36 +55,49 @@ public class ServerTemplateSelectorMenuBuilder implements MenuFactory.CustomMenu @PostConstruct public void init() { - view.setServerTemplateChangeHandler(e -> serverTemplateSelectedEvent.fire(new ServerTemplateSelected(e))); + widgetView.setServerTemplateChangeHandler(e -> { + serverTemplateSelectedEvent.fire(new ServerTemplateSelected(e)); + view.updateSelectedValue(e); + }); + view.setServerTemplateChangeHandler(e -> { + serverTemplateSelectedEvent.fire(new ServerTemplateSelected(e)); + widgetView.updateSelectedValue(e); + }); + loadServerTemplates(); } protected void loadServerTemplates() { + widgetView.removeAllServerTemplates(); + view.removeAllServerTemplates(); specManagementService.call((ServerTemplateList serverTemplates) -> { - view.removeAllServerTemplates(); - final Set ids = FluentIterable.from(serverTemplates.getServerTemplates()) .filter(s -> s.getServerInstanceKeys() != null && !s.getServerInstanceKeys().isEmpty()) .transform(s -> s.getId()) .toSortedSet(String.CASE_INSENSITIVE_ORDER); for (String id : ids) { + widgetView.addServerTemplate(id); view.addServerTemplate(id); } if (ids.size() == 1) { + widgetView.selectServerTemplate(ids.iterator().next()); view.selectServerTemplate(ids.iterator().next()); } else { - final String selectedServerTemplate = view.getSelectedServerTemplate(); + final String selectedServerTemplate = getSelectedServerTemplate(); if (selectedServerTemplate != null) { if (ids.contains(selectedServerTemplate)) { + widgetView.selectServerTemplate(selectedServerTemplate); view.selectServerTemplate(selectedServerTemplate); } else { + widgetView.clearSelectedServerTemplate(); view.clearSelectedServerTemplate(); } } } + widgetView.setVisible(ids.size() > 1); view.setVisible(ids.size() > 1); }).listServerTemplates(); } @@ -94,7 +111,7 @@ public MenuItem build() { return new BaseMenuCustom() { @Override public IsWidget build() { - return view; + return widgetView; } @Override @@ -108,6 +125,10 @@ public void setEnabled(boolean enabled) { }; } + public ServerTemplateSelectorElementView getView() { + return view; + } + public void onServerTemplateDeleted(@Observes final ServerTemplateDeleted serverTemplateDeleted) { loadServerTemplates(); } @@ -131,10 +152,12 @@ public String getSelectedServerTemplate() { return view.getSelectedServerTemplate(); } - public interface ServerTemplateSelectorView extends IsWidget { + public interface ServerTemplateSelectorView { void selectServerTemplate(String serverTemplateId); + void updateSelectedValue(String serverTemplateId); + void setVisible(boolean visible); void clearSelectedServerTemplate(); @@ -147,4 +170,14 @@ public interface ServerTemplateSelectorView extends IsWidget { void setServerTemplateChangeHandler(ParameterizedCommand command); } + + public interface ServerTemplateSelectorWidgetView extends ServerTemplateSelectorView, + IsWidget { + + } + + public interface ServerTemplateSelectorElementView extends ServerTemplateSelectorView, + UberElement { + + } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.css b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.css new file mode 100644 index 0000000000..6c3ebd27cf --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.css @@ -0,0 +1,11 @@ +.dropdown:hover { + cursor: pointer; +} + +.dropdown .server-template-dropdown-menu.dropdown-menu { + margin-top: 6px; +} + +.server-template-text { + color: #4d5258; +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.html b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.html new file mode 100644 index 0000000000..fb02fd7a52 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.html @@ -0,0 +1,7 @@ + diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.java index 06c7f7c000..9af061a4da 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorViewImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,89 +16,117 @@ package org.jbpm.workbench.common.client.menu; -import java.util.Iterator; -import javax.annotation.PostConstruct; import javax.enterprise.context.Dependent; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.Widget; -import org.gwtbootstrap3.client.ui.AnchorListItem; -import org.gwtbootstrap3.client.ui.Button; -import org.gwtbootstrap3.client.ui.ButtonGroup; -import org.gwtbootstrap3.client.ui.DropDownMenu; -import org.gwtbootstrap3.client.ui.constants.ButtonSize; -import org.gwtbootstrap3.client.ui.constants.IconType; -import org.gwtbootstrap3.client.ui.constants.Styles; -import org.gwtbootstrap3.client.ui.constants.Toggle; +import javax.inject.Inject; + +import org.jboss.errai.common.client.dom.Div; +import org.jboss.errai.common.client.dom.HTMLElement; +import org.jboss.errai.common.client.dom.NodeList; +import org.jboss.errai.common.client.dom.Span; +import org.jboss.errai.common.client.dom.UnorderedList; +import org.jboss.errai.ui.shared.api.annotations.DataField; +import org.jboss.errai.ui.shared.api.annotations.Templated; import org.jbpm.workbench.common.client.resources.i18n.Constants; import org.uberfire.mvp.ParameterizedCommand; +import static org.jboss.errai.common.client.dom.DOMUtil.addCSSClass; +import static org.jboss.errai.common.client.dom.DOMUtil.removeCSSClass; +import static org.jboss.errai.common.client.dom.DOMUtil.removeAllChildren; +import static org.jboss.errai.common.client.dom.Window.getDocument; + @Dependent -public class ServerTemplateSelectorViewImpl extends Composite implements ServerTemplateSelectorMenuBuilder.ServerTemplateSelectorView { +@Templated +public class ServerTemplateSelectorViewImpl implements ServerTemplateSelectorMenuBuilder.ServerTemplateSelectorElementView { private Constants constants = Constants.INSTANCE; - private DropDownMenu dropDownServerTemplates; + @Inject + @DataField + private Div container; - private Button serverTemplateButton; + @Inject + @DataField("selected-serverTemplate-text") + Span selectedServerTemplateText; - private ButtonGroup serverTemplates; + @Inject + @DataField("server-templates-list") + UnorderedList serverTemplatesList; private ParameterizedCommand changeCommand; - @PostConstruct - public void init() { - serverTemplateButton = GWT.create(Button.class); - serverTemplateButton.setText(constants.ServerTemplates()); - serverTemplateButton.setDataToggle(Toggle.DROPDOWN); - serverTemplateButton.setSize(ButtonSize.SMALL); - - dropDownServerTemplates = GWT.create(DropDownMenu.class); - dropDownServerTemplates.addStyleName(Styles.DROPDOWN_MENU + "-right"); - - serverTemplates = GWT.create(ButtonGroup.class); - serverTemplates.add(serverTemplateButton); - serverTemplates.add(dropDownServerTemplates); + @Override + public void init(final ServerTemplateSelectorMenuBuilder presenter) { + } - initWidget(serverTemplates); + @Override + public void selectServerTemplate(String serverTemplateId) { + NodeList childList = serverTemplatesList.getChildNodes(); + for (int i = 0; i < childList.getLength(); i++) { + if (childList.item(i).getLastChild().getTextContent().equals(serverTemplateId)) { + selectServerTemplate((HTMLElement) childList.item(i), + serverTemplateId, + false); + break; + } + } } @Override - public void selectServerTemplate(final String serverTemplateId) { - for (Widget widget : dropDownServerTemplates) { - if (widget instanceof AnchorListItem && ((AnchorListItem) widget).getText().equals(serverTemplateId)) { - selectServerTemplate((AnchorListItem) widget); + public void updateSelectedValue(String serverTemplateId) { + NodeList childList = serverTemplatesList.getChildNodes(); + for (int i = 0; i < childList.getLength(); i++) { + if (childList.item(i).getLastChild().getTextContent().equals(serverTemplateId)) { + selectServerTemplate((HTMLElement) childList.item(i), + serverTemplateId, + true); break; } } } @Override - public void addServerTemplate(final String serverTemplateId) { - final AnchorListItem serverTemplateNavLink = GWT.create(AnchorListItem.class); - serverTemplateNavLink.setText(serverTemplateId); - serverTemplateNavLink.setIcon(IconType.SERVER); - serverTemplateNavLink.setIconFixedWidth(true); - serverTemplateNavLink.addClickHandler(e -> selectServerTemplate(serverTemplateNavLink)); - dropDownServerTemplates.add(serverTemplateNavLink); + public void setVisible(boolean visible) { + if (visible) { + removeCSSClass(container, + "hidden"); + } else { + addCSSClass(container, + "hidden"); + } } - protected void selectServerTemplate(final AnchorListItem serverTemplateNavLink) { - final boolean serverChanged = serverTemplateNavLink.getText().equals(serverTemplateButton.getText()) == false; - unselectAllServerTemplateNavLinks(); - serverTemplateNavLink.setActive(true); + @Override + public void addServerTemplate(String serverTemplateId) { + final HTMLElement li = getDocument().createElement("li"); + final HTMLElement a = getDocument().createElement("a"); + final HTMLElement textSpan = getDocument().createElement("span"); + textSpan.setTextContent(serverTemplateId); + a.setOnclick(e -> selectServerTemplate(li, + serverTemplateId, + false)); + a.appendChild(textSpan); + li.appendChild(a); + serverTemplatesList.appendChild(li); + } + + protected void selectServerTemplate(final HTMLElement liOption, + String serverTemplateId, + boolean updating) { + final boolean serverChanged = serverTemplateId.equals(selectedServerTemplateText.getTextContent()) == false; + unSelectAllServerTemplateNavLinks(); + addCSSClass(liOption, + "active"); if (serverChanged) { - serverTemplateButton.setText(serverTemplateNavLink.getText()); - if (changeCommand != null) { - changeCommand.execute(serverTemplateNavLink.getText()); + selectedServerTemplateText.setTextContent(serverTemplateId); + if (changeCommand != null && !updating) { + changeCommand.execute(serverTemplateId); } } } @Override public void clearSelectedServerTemplate() { - serverTemplateButton.setText(constants.ServerTemplates()); + selectedServerTemplateText.setTextContent(constants.ServerTemplates()); if (changeCommand != null) { changeCommand.execute(null); } @@ -106,29 +134,30 @@ public void clearSelectedServerTemplate() { @Override public String getSelectedServerTemplate() { - final String serverTemplate = serverTemplateButton.getText(); + final String serverTemplate = selectedServerTemplateText.getTextContent(); return serverTemplate.equals(constants.ServerTemplates()) ? null : serverTemplate; } @Override public void removeAllServerTemplates() { - final Iterator iterator = dropDownServerTemplates.iterator(); - while (iterator.hasNext()) { - iterator.next(); - iterator.remove(); - } + removeAllChildren(serverTemplatesList); } @Override - public void setServerTemplateChangeHandler(final ParameterizedCommand command) { - changeCommand = command; + public void setServerTemplateChangeHandler(ParameterizedCommand command) { + this.changeCommand = command; } - private void unselectAllServerTemplateNavLinks() { - for (Widget widget : dropDownServerTemplates) { - if (widget instanceof AnchorListItem) { - ((AnchorListItem) widget).setActive(false); - } + private void unSelectAllServerTemplateNavLinks() { + NodeList childList = serverTemplatesList.getChildNodes(); + for (int i = 0; i < childList.getLength(); i++) { + removeCSSClass((HTMLElement) childList.item(i), + "active"); } } + + @Override + public HTMLElement getElement() { + return container; + } } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorWidgetViewImpl.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorWidgetViewImpl.java new file mode 100644 index 0000000000..ca2ade3c82 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/menu/ServerTemplateSelectorWidgetViewImpl.java @@ -0,0 +1,153 @@ +/* + * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.menu; + +import java.util.Iterator; +import javax.annotation.PostConstruct; +import javax.enterprise.context.Dependent; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; +import org.gwtbootstrap3.client.ui.AnchorListItem; +import org.gwtbootstrap3.client.ui.Button; +import org.gwtbootstrap3.client.ui.ButtonGroup; +import org.gwtbootstrap3.client.ui.DropDownMenu; +import org.gwtbootstrap3.client.ui.constants.ButtonSize; +import org.gwtbootstrap3.client.ui.constants.IconType; +import org.gwtbootstrap3.client.ui.constants.Styles; +import org.gwtbootstrap3.client.ui.constants.Toggle; +import org.jbpm.workbench.common.client.resources.i18n.Constants; +import org.uberfire.mvp.ParameterizedCommand; + +@Dependent +public class ServerTemplateSelectorWidgetViewImpl extends Composite implements ServerTemplateSelectorMenuBuilder.ServerTemplateSelectorWidgetView { + + private Constants constants = Constants.INSTANCE; + + private DropDownMenu dropDownServerTemplates; + + private Button serverTemplateButton; + + private ButtonGroup serverTemplates; + + private ParameterizedCommand changeCommand; + + @PostConstruct + public void init() { + serverTemplateButton = GWT.create(Button.class); + serverTemplateButton.setText(constants.ServerTemplates()); + serverTemplateButton.setDataToggle(Toggle.DROPDOWN); + serverTemplateButton.setSize(ButtonSize.SMALL); + + dropDownServerTemplates = GWT.create(DropDownMenu.class); + dropDownServerTemplates.addStyleName(Styles.DROPDOWN_MENU + "-right"); + + serverTemplates = GWT.create(ButtonGroup.class); + serverTemplates.add(serverTemplateButton); + serverTemplates.add(dropDownServerTemplates); + + initWidget(serverTemplates); + } + + @Override + public void selectServerTemplate(final String serverTemplateId) { + for (Widget widget : dropDownServerTemplates) { + if (widget instanceof AnchorListItem && ((AnchorListItem) widget).getText().equals(serverTemplateId)) { + selectServerTemplate((AnchorListItem) widget, + false); + break; + } + } + } + + @Override + public void updateSelectedValue(String serverTemplateId) { + for (Widget widget : dropDownServerTemplates) { + if (widget instanceof AnchorListItem && ((AnchorListItem) widget).getText().equals(serverTemplateId)) { + selectServerTemplate((AnchorListItem) widget, + true); + break; + } + } + } + + @Override + public void setVisible(boolean visible) { + serverTemplates.setVisible(visible); + } + + @Override + public void addServerTemplate(final String serverTemplateId) { + final AnchorListItem serverTemplateNavLink = GWT.create(AnchorListItem.class); + serverTemplateNavLink.setText(serverTemplateId); + serverTemplateNavLink.setIcon(IconType.SERVER); + serverTemplateNavLink.setIconFixedWidth(true); + serverTemplateNavLink.addClickHandler(e -> selectServerTemplate(serverTemplateNavLink, + false)); + dropDownServerTemplates.add(serverTemplateNavLink); + } + + protected void selectServerTemplate(final AnchorListItem serverTemplateNavLink, + boolean updating) { + final boolean serverChanged = serverTemplateNavLink.getText().equals(serverTemplateButton.getText()) == false; + unselectAllServerTemplateNavLinks(); + serverTemplateNavLink.setActive(true); + if (serverChanged) { + serverTemplateButton.setText(serverTemplateNavLink.getText()); + if (changeCommand != null && !updating) { + changeCommand.execute(serverTemplateNavLink.getText()); + } + } + } + + @Override + public void clearSelectedServerTemplate() { + serverTemplateButton.setText(constants.ServerTemplates()); + if (changeCommand != null) { + changeCommand.execute(null); + } + } + + @Override + public String getSelectedServerTemplate() { + final String serverTemplate = serverTemplateButton.getText(); + return serverTemplate.equals(constants.ServerTemplates()) ? null : serverTemplate; + } + + @Override + public void removeAllServerTemplates() { + final Iterator iterator = dropDownServerTemplates.iterator(); + while (iterator.hasNext()) { + iterator.next(); + iterator.remove(); + } + } + + @Override + public void setServerTemplateChangeHandler(final ParameterizedCommand command) { + changeCommand = command; + } + + private void unselectAllServerTemplateNavLinks() { + for (Widget widget : dropDownServerTemplates) { + if (widget instanceof AnchorListItem) { + ((AnchorListItem) widget).setActive(false); + } + } + } +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/perspectives/AbstractPerspective.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/perspectives/AbstractPerspective.java index 2fb8d0e2a6..4fd20d5d6f 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/perspectives/AbstractPerspective.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/perspectives/AbstractPerspective.java @@ -17,27 +17,47 @@ package org.jbpm.workbench.common.client.perspectives; import javax.annotation.PostConstruct; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import com.google.gwt.core.client.Scheduler; +import org.gwtbootstrap3.client.ui.constants.IconType; +import org.jbpm.workbench.common.client.resources.i18n.Constants; import org.uberfire.client.annotations.Perspective; -import org.uberfire.client.workbench.panels.impl.MultiListWorkbenchPanelPresenter; +import org.uberfire.client.workbench.docks.UberfireDock; +import org.uberfire.client.workbench.docks.UberfireDockPosition; +import org.uberfire.client.workbench.docks.UberfireDocks; +import org.uberfire.client.workbench.events.ClosePlaceEvent; +import org.uberfire.client.workbench.events.SelectPlaceEvent; +import org.uberfire.client.workbench.panels.impl.MultiScreenWorkbenchPanelPresenter; +import org.uberfire.lifecycle.OnOpen; import org.uberfire.lifecycle.OnStartup; import org.uberfire.mvp.PlaceRequest; +import org.uberfire.mvp.impl.DefaultPlaceRequest; import org.uberfire.workbench.model.PerspectiveDefinition; import org.uberfire.workbench.model.impl.PartDefinitionImpl; import org.uberfire.workbench.model.impl.PerspectiveDefinitionImpl; public abstract class AbstractPerspective { + @Inject + protected UberfireDocks uberfireDocks; + + protected UberfireDock basicFiltersDock; + + protected UberfireDock savedFiltersDock; + private PlaceRequest placeRequest; @PostConstruct protected void init() { placeRequest = getPlaceRequest(); + setupDocks(); } @Perspective public PerspectiveDefinition getPerspective() { - final PerspectiveDefinition p = new PerspectiveDefinitionImpl(MultiListWorkbenchPanelPresenter.class.getName()); + final PerspectiveDefinition p = new PerspectiveDefinitionImpl(MultiScreenWorkbenchPanelPresenter.class.getName()); p.setName(getPerspectiveId()); p.getRoot().addPart(new PartDefinitionImpl(placeRequest)); return p; @@ -53,7 +73,57 @@ public void onStartup(final PlaceRequest place) { } } + @OnOpen + public void onOpen() { + if (basicFiltersDock != null) { + Scheduler.get().scheduleDeferred(() -> { + uberfireDocks.show(UberfireDockPosition.WEST, + getPerspectiveId()); + uberfireDocks.open(basicFiltersDock); + }); + } + } + + public void onDetailsOpen(@Observes SelectPlaceEvent event) { + if(event.getPlace().getIdentifier().equals(getDetailsScreenId())){ + uberfireDocks.hide(UberfireDockPosition.WEST, + getPerspectiveId()); + } + } + + public void onDetailsClose(@Observes ClosePlaceEvent event) { + if(event.getPlace().getIdentifier().equals(getDetailsScreenId())){ + uberfireDocks.show(UberfireDockPosition.WEST, + getPerspectiveId()); + } + } + + protected void setupDocks() { + final String basicFiltersScreenId = getBasicFiltersScreenId(); + if (basicFiltersScreenId != null) { + basicFiltersDock = new UberfireDock(UberfireDockPosition.WEST, + IconType.FILTER.toString(), + new DefaultPlaceRequest(basicFiltersScreenId), + getPerspectiveId()).withSize(400).withLabel(Constants.INSTANCE.Filters()); + uberfireDocks.add(basicFiltersDock); + } + final String savedFiltersScreenId = getSavedFiltersScreenId(); + if (savedFiltersScreenId != null) { + savedFiltersDock = new UberfireDock(UberfireDockPosition.WEST, + IconType.STAR_O.toString(), + new DefaultPlaceRequest(savedFiltersScreenId), + getPerspectiveId()).withSize(400).withLabel(Constants.INSTANCE.SavedFilters()); + uberfireDocks.add(savedFiltersDock); + } + } + public abstract String getPerspectiveId(); + public abstract String getBasicFiltersScreenId(); + + public abstract String getSavedFiltersScreenId(); + + public abstract String getDetailsScreenId(); + public abstract PlaceRequest getPlaceRequest(); -} +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/css/kie-manage.less b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/css/kie-manage.less new file mode 100644 index 0000000000..07011b5ba0 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/css/kie-manage.less @@ -0,0 +1,221 @@ +@import "/org/uberfire/client/views/static/uberfire-variables.less"; + +// Styles for KIE Manage screens + +.manage { + + @kie-icon-size-base: (14 / @font-size-base) * 1px; + @pf-font-weight-bold: 600; + @min-touch-width: 44px; + @icon-size-md: 1.75rem; // 21 px + @list-pf-padding: 20px; + + ///////////////// + // filter styles + .kie-tab-content--filters { + //darken horizontal rules + hr { + border-color: @color-pf-black-300; + } + } + + // add background color. Left border may not be needed once in place + .tab-content { + //border-left: 1px solid @panel-default-border-color; + background-color: @color-pf-black-100; + } + + // New kind of list with a background color for placement on a background color other than white + .kie-list-pf-light { + background-color: @color-pf-white; + } + + // Remove gradient from collapsible panel heading + .panel-group .panel-default .panel-heading { + background: none; + } + + .panel-group .panel-heading + .panel-collapse .panel-body { + border-top-color: transparent; + } + + // Dock panel styles + + // adjust spacing of an HR + .kie-dock__divider { + margin-top: 25px; + margin-bottom: 15px; + .form-group + &, + .panel-group + & { + margin-top: 15px; + } + } + + .kie-dock__heading { + font-weight: @pf-font-weight-bold; + } + + .kie-dock__heading--section { + font-size: @font-size-base; + font-weight: @pf-font-weight-bold; + } + + .kie-dock__panel-group { + margin-bottom: 0; + } + + .kie-dock__panel { + background-color: transparent; + border: none; + box-shadow: none; + margin-bottom: 0; + } + + .kie-dock__panel-heading { + padding: 0; + } + + .kie-dock__panel-body { + padding-top: 0; + padding-bottom: 0; + border: none; + } + + .kie-dock__datepicker { + margin-bottom: @form-group-margin-bottom; + } + + // list inside the dock + .kie-dock__list-pf-item { + :hover { + background-color: #EDF8FF; + .btn-link { + color: @link-hover-color; + } + } + } + + .kie-dock__list-pf-item.active { + background-color: @color-pf-blue-50; + border-color: transparent; + } + + .kie-dock__list-pf-container { + padding: @list-pf-padding/2 0 @list-pf-padding/2 @list-pf-padding/2; + } + + .kie-dock__list-pf-left { + margin-right: @list-pf-padding/2; + } + + .kie-dock__list-pf-title { + margin-bottom: .5em; + } + + .kie-dock__list-pf-main-content { + line-height: 1.4em; + } + + .kie-dock__KVP:not(:last-child) { + margin-bottom: .5em; + } + + .kie-dock__list-pf-actions { + margin-left: 0; + } + + .kie-dock__list-pf-actions .btn-link { + color: @text-color; + font-size: @kie-icon-size-base; + min-width: @min-touch-width; + } + + .kie-list-pf-icon-md { + font-size: @icon-size-md; + } + + // override normal label and form-control for input box embedded inside the radio button (or checkbox) + .radio .kie-label--embedded, + .checkbox .kie-label--embedded { + padding-left: 0; + } + + .kie-input--inline, + .radio .kie-input--inline, + .checkbox .kie-input--inline { + display: inline-block; + width: auto; + } + + // Styles for left side dock selector + // For docks in other positions, the border will need to be adjusted to the appropriate side + + // Selector needed to override specificity + .kie-dock-selector > li > a { + padding: @pf-spacer-sm @pf-spacer-xxl; + color: @color-pf-black; + &:hover, + &:focus { + background-color: @color-pf-blue-50; + color: @link-color; + } + } + + .kie-dock-selector > li.active a { + background-color: @color-pf-blue-50; + color: @link-color; + } + + // Styles for KIE-specific datatables.net components + + .content-view-pf-pagination, + .table-view-pf-toolbar.toolbar-pf { + background-color: transparent; + border-color: transparent; + } + + .kie-datatable > thead > tr > th, + .kie-datatable > tbody > tr > th, + .kie-datatable > tfoot > tr > th, + .kie-datatable > thead > tr > td, + .kie-datatable > tbody > tr > td, + .kie-datatable tfoot > tr > td { + padding: @pf-spacer-sm @pf-spacer-md; + border-left-color: transparent; + border-right-color: transparent; + } + + .kie-datatable > thead { + background-color: @color-pf-black-150; + background-image: none; + } + + .table-view-pf-actions { + background-color: transparent; + } + + table.kie-datatable tbody > tr:hover > td.table-view-pf-actions { + background-color: transparent; + } + + table.dataTable thead .sorting_asc:before, + table.dataTable thead .sorting_desc:before { + background: transparent; + } + + ///// This styles the GWT-generated version of the table (in addition to inline styles where they already existed) + .kie-table--pagination .btn { + padding-left: @pf-spacer-xxs; + padding-right: @pf-spacer-xxs; + } + + .kie-table__cell--separated { + padding-left: @pf-spacer-xxs; + padding-right: @pf-spacer-xxs; + } + + .kie-datatable-select { + text-align: center; + } + +} \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/i18n/Constants.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/i18n/Constants.java index aa84f62569..d4ca6c02e1 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/i18n/Constants.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/resources/i18n/Constants.java @@ -97,6 +97,55 @@ String DataSetError(String dataSet, String LastDays(Integer days); String Custom(); - + + String Home(); + + String Filters(); + + String Select(); + + String Apply(); + + String AdvancedFilters(); + + String Process_Definitions(); + + String Process_Instances(); + + String Tasks(); + + String Task_Inbox(); + + String ExecutionErrors(); + + String Jobs(); + + String Manage(); + + String Manage_Process_Definitions(); + + String Manage_Process_Instances(); + + String Manage_Tasks(); + + String Manage_ExecutionErrors(); + + String Manage_Jobs(); + + String FilterBy(); + + String SavedFilters(); + + String RemoveSavedFilterTitle(); + + String RemoveSavedFilterMessage(String filterName); + + String Remove(); + String ErrorCountNumberView(@PluralCount int errCount); + + String UnexpectedError(String message); + + String FilterWithSameNameAlreadyExists(); + } \ No newline at end of file diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ButtonActionCell.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ButtonActionCell.java index ed74dd7ffd..b288d9406a 100644 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ButtonActionCell.java +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ButtonActionCell.java @@ -33,6 +33,8 @@ public class ButtonActionCell implements HasCell { private String text; + private ButtonSize size; + public ButtonActionCell(final ActionCell.Delegate delegate) { this("", delegate); @@ -40,7 +42,16 @@ public ButtonActionCell(final ActionCell.Delegate delegate) { public ButtonActionCell(final String text, final ActionCell.Delegate delegate) { + this(text, + delegate, + ButtonSize.SMALL); + } + + public ButtonActionCell(final String text, + final ActionCell.Delegate delegate, + final ButtonSize size) { this.text = text; + this.size = size; this.cell = new ActionCell(text, delegate) { @Override @@ -62,7 +73,7 @@ public void render(final Cell.Context context, btn.setText(getText(value)); btn.setTitle(getText(value)); btn.setType(ButtonType.DEFAULT); - btn.setSize(ButtonSize.SMALL); + btn.setSize(size); btn.getElement().getStyle().setMarginRight(5, Style.Unit.PX); mysb.appendHtmlConstant(btn.getElement().getString()); diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalAction.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalAction.java new file mode 100644 index 0000000000..14585b51e5 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalAction.java @@ -0,0 +1,56 @@ +/* + * Copyright 2017 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.util; + +import java.util.function.Consumer; +import java.util.function.Predicate; + +import org.jbpm.workbench.common.model.GenericSummary; + +public class ConditionalAction { + + private Predicate predicate; + private String text; + private Consumer callback; + private Boolean isNavigation; + + public ConditionalAction(final String text, + final Consumer callback, + final Predicate predicate, + final Boolean isNavigation) { + this.predicate = predicate; + this.text = text; + this.callback = callback; + this.isNavigation = isNavigation; + } + + public Consumer getCallback() { + return callback; + } + + public Predicate getPredicate() { + return predicate; + } + + public String getText() { + return text; + } + + public Boolean isNavigation() { + return isNavigation; + } +} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalButtonActionCell.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalButtonActionCell.java deleted file mode 100644 index bc0965f589..0000000000 --- a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalButtonActionCell.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. and/or its affiliates. - * - * Licensed 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.jbpm.workbench.common.client.util; - -import java.util.function.Predicate; - -import com.google.gwt.cell.client.ActionCell; -import com.google.gwt.cell.client.Cell; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; -import org.jbpm.workbench.common.model.GenericSummary; - -public class ConditionalButtonActionCell extends ButtonActionCell { - - private Predicate cond; - - public ConditionalButtonActionCell(final String text, - final ActionCell.Delegate delegate, - final Predicate cond) { - super(text, - delegate); - this.cond = cond; - } - - @Override - public void render(final Cell.Context context, - final T value, - final SafeHtmlBuilder sb) { - if (cond.test(value)) { - super.render(context, - value, - sb); - } - } -} diff --git a/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalKebabActionCell.java b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalKebabActionCell.java new file mode 100644 index 0000000000..641dacec09 --- /dev/null +++ b/jbpm-wb-common/jbpm-wb-common-client/src/main/java/org/jbpm/workbench/common/client/util/ConditionalKebabActionCell.java @@ -0,0 +1,167 @@ +/* + * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.jbpm.workbench.common.client.util; + +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; + +import com.google.gwt.cell.client.AbstractCell; +import com.google.gwt.cell.client.Cell; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.dom.client.Document; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import elemental2.dom.Element; +import elemental2.dom.HTMLDivElement; +import elemental2.dom.HTMLDocument; +import elemental2.dom.HTMLLIElement; +import org.jboss.errai.ioc.client.api.ManagedInstance; +import org.jbpm.workbench.common.model.GenericSummary; +import org.uberfire.client.views.pfly.widgets.Button; +import org.uberfire.client.views.pfly.widgets.KebabMenu; +import org.uberfire.client.views.pfly.widgets.KebabMenuItem; + +import static com.google.gwt.dom.client.BrowserEvents.CLICK; +import static com.google.gwt.dom.client.BrowserEvents.KEYDOWN; + +@Dependent +public class ConditionalKebabActionCell extends AbstractCell { + + private List> actions; + + @Inject + private HTMLDocument document; + + @Inject + private ManagedInstance kebabMenus; + + @Inject + private ManagedInstance kebabMenuItems; + + @Inject + private ManagedInstance