ItEr53S14CUVistaRecursosTempoPorProxectoItEr49S16: Adds the filter by resources or by criterions in the resource load screen.

This commit is contained in:
Susana Montes Pedreira 2010-04-08 18:05:06 +02:00 committed by Javier Moran Rua
parent e41d203ade
commit 69dfd2e1b2
6 changed files with 144 additions and 31 deletions

View file

@ -0,0 +1,27 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.resourceload;
public interface IFilterChangedListener {
public void filterChanged(boolean filter);
}

View file

@ -20,6 +20,8 @@
package org.zkoss.ganttz.resourceload;
import static org.zkoss.ganttz.i18n.I18nHelper._;
import java.util.List;
import org.apache.commons.lang.StringUtils;
@ -30,6 +32,8 @@ import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.ComponentsFinder;
import org.zkoss.ganttz.util.MutableTreeModel;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.WeakReferencedListeners;
import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification;
import org.zkoss.ganttz.util.script.IScriptsRegister;
import org.zkoss.zk.au.out.AuInvoke;
import org.zkoss.zk.ui.Component;
@ -42,7 +46,6 @@ import org.zkoss.zul.ListModel;
import org.zkoss.zul.Separator;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.api.Listbox;
public class ResourcesLoadPanel extends HtmlMacroComponent {
public interface IToolbarCommand {
@ -59,16 +62,28 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
private ResourceLoadList resourceLoadList;
private final List<LoadTimeLine> groups;
private List<LoadTimeLine> groups;
private MutableTreeModel<LoadTimeLine> treeModel;
private final TimeTracker timeTracker;
private TimeTracker timeTracker;
private WeakReferencedListeners<IFilterChangedListener> zoomListeners = WeakReferencedListeners
.create();
private Listbox listZoomLevels;
private static final String filterResources = _("Filter by resources");
private static final String filterCriterions = _("Filter by criterions");
private boolean filterbyResources = true;
public ResourcesLoadPanel(List<LoadTimeLine> groups,
TimeTracker timeTracker) {
init(groups, timeTracker);
}
public void init(List<LoadTimeLine> groups, TimeTracker timeTracker) {
this.groups = groups;
this.timeTracker = timeTracker;
treeModel = createModelForTree();
@ -78,6 +93,37 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
registerNeededScripts();
}
public ListModel getFilters() {
String[] filters = new String[] { filterResources, filterCriterions };
return new SimpleListModel(filters);
}
public void setFilter(String filterby) {
if (filterby.equals(filterResources)) {
this.filterbyResources = true;
} else {
this.filterbyResources = false;
}
}
public boolean getFilter() {
return filterbyResources;
}
public void onApplyFilter() {
zoomListeners
.fireEvent(new IListenerNotification<IFilterChangedListener>() {
@Override
public void doNotify(IFilterChangedListener listener) {
listener.filterChanged(getFilter());
}
});
}
public void addFilterListener(IFilterChangedListener listener) {
zoomListeners.addListener(listener);
}
public ListModel getZoomLevels() {
return new SimpleListModel(ZoomLevel.values());
}
@ -192,6 +238,12 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
listZoomLevels.setSelectedIndex(timeTracker.getDetailLevel().ordinal());
}
public void clearComponents() {
getFellow("insertionPointLeftPanel").getChildren().clear();
getFellow("insertionPointRightPanel").getChildren().clear();
getFellow("insertionPointTimetracker").getChildren().clear();
}
private TimeTrackerComponent createTimeTrackerHeader() {
return new TimeTrackerComponent(
timeTracker) {

View file

@ -38,22 +38,14 @@ resourcesLoadPanel = self;
onSelect="resourcesLoadPanel.setZoomLevel(self.selectedItem.value);" >
</listbox>
<separator/>
From: <datebox /> to: <datebox />
<separator/>
Filter:
<combobox>
<comboitem label="Orders"
description="Show full orders and company view" />
<comboitem label="Tasks"
description="Tasks inside orders or filtered" />
</combobox>
<combobox>
<comboitem label="Filter by Label" />
<comboitem label="Filter by criterion" />
<comboitem label="Filter by resources" />
<comboitem label="Critical way" />
</combobox>
<textbox/>
<listbox id="listFilters" mold="select" rows="1" width="200px"
model="${resourcesLoadPanel.filters}"
onSelect="resourcesLoadPanel.setFilter(self.selectedItem.value);" >
</listbox>
<button image="/common/img/ico_filter.png" style="margin-top: -4px"
tooltiptext="${i18n:_('Apply filtering to resource load satisfying required criteria')}"
onClick="resourcesLoadPanel.onApplyFilter()"/>
</hbox>
</north>

View file

@ -29,9 +29,9 @@ import org.zkoss.ganttz.util.Interval;
public interface IResourceLoadModel {
void initGlobalView();
void initGlobalView(boolean filterByResources);
void initGlobalView(Order filterBy);
void initGlobalView(Order filterBy, boolean filterByResources);
List<LoadTimeLine> getLoadTimeLines();

View file

@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.zkoss.ganttz.resourceload.IFilterChangedListener;
import org.zkoss.ganttz.resourceload.ResourcesLoadPanel;
import org.zkoss.ganttz.resourceload.ResourcesLoadPanel.IToolbarCommand;
import org.zkoss.ganttz.timetracker.TimeTracker;
@ -57,6 +58,12 @@ public class ResourceLoadController implements Composer {
private org.zkoss.zk.ui.Component parent;
private ResourcesLoadPanel resourcesLoadPanel;
private TimeTracker timeTracker;
private transient IFilterChangedListener filterChangedListener;
public ResourceLoadController() {
}
@ -72,14 +79,22 @@ public class ResourceLoadController implements Composer {
}
public void reload() {
// by default show the task by resources
boolean filterByResources = true;
reload(filterByResources);
}
private void reload(boolean filterByResources) {
try {
if (filterBy == null) {
resourceLoadModel.initGlobalView();
resourceLoadModel.initGlobalView(filterByResources);
} else {
resourceLoadModel.initGlobalView(filterBy);
resourceLoadModel.initGlobalView(filterBy, filterByResources);
}
timeTracker = buildTimeTracker();
resourcesLoadPanel = buildResourcesLoadPanel();
addListeners();
ResourcesLoadPanel resourcesLoadPanel = buildResourcesLoadPanel();
this.parent.getChildren().clear();
this.parent.appendChild(resourcesLoadPanel);
resourcesLoadPanel.afterCompose();
@ -96,16 +111,36 @@ public class ResourceLoadController implements Composer {
}
}
private void addListeners() {
filterChangedListener = new IFilterChangedListener() {
@Override
public void filterChanged(boolean filter) {
onApplyFilter(filter);
}
};
this.resourcesLoadPanel.addFilterListener(filterChangedListener);
}
public void onApplyFilter(boolean filterByResources) {
resourcesLoadPanel.clearComponents();
reload(filterByResources);
}
private void addCommands(ResourcesLoadPanel resourcesLoadPanel) {
resourcesLoadPanel.add(commands.toArray(new IToolbarCommand[0]));
}
private TimeTracker buildTimeTracker() {
return timeTracker = new TimeTracker(resourceLoadModel
.getViewInterval(), resourceLoadModel
.calculateInitialZoomLevel(), SeveralModificators.create(),
SeveralModificators.create(new BankHolidaysMarker()), parent);
}
private ResourcesLoadPanel buildResourcesLoadPanel() {
return new ResourcesLoadPanel(resourceLoadModel.getLoadTimeLines(),
new TimeTracker(resourceLoadModel.getViewInterval(),
resourceLoadModel.calculateInitialZoomLevel(),
SeveralModificators.create(), SeveralModificators
.create(new BankHolidaysMarker()), parent));
timeTracker);
}
public void filterBy(Order order) {

View file

@ -80,17 +80,21 @@ public class ResourceLoadModel implements IResourceLoadModel {
private Order filterBy;
private boolean filterByResources = true;
@Override
@Transactional(readOnly = true)
public void initGlobalView() {
public void initGlobalView(boolean filterByResources) {
filterBy = null;
this.filterByResources = filterByResources;
doGlobalView();
}
@Override
@Transactional(readOnly = true)
public void initGlobalView(Order filterBy) {
public void initGlobalView(Order filterBy, boolean filterByResources) {
this.filterBy = orderDAO.findExistingEntity(filterBy.getId());
this.filterByResources = filterByResources;
doGlobalView();
}
@ -112,8 +116,11 @@ public class ResourceLoadModel implements IResourceLoadModel {
private List<LoadTimeLine> calculateLoadTimeLines() {
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
result.addAll(groupsFor(resourcesToShow()));
result.addAll(groupsFor(genericAllocationsByCriterion()));
if (filterByResources) {
result.addAll(groupsFor(resourcesToShow()));
} else {
result.addAll(groupsFor(genericAllocationsByCriterion()));
}
return result;
}