2009-10-01 18:46:46 +02:00
|
|
|
/*
|
2011-10-28 08:17:54 +02:00
|
|
|
* This file is part of LibrePlan
|
2009-10-01 18:46:46 +02:00
|
|
|
*
|
2010-07-19 09:36:44 +02:00
|
|
|
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
2010-07-19 09:47:20 +02:00
|
|
|
* Desenvolvemento Tecnolóxico de Galicia
|
2011-01-19 18:00:09 +01:00
|
|
|
* Copyright (C) 2010-2011 Igalia, S.L.
|
2009-10-01 18:46:46 +02:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
import java.text.DateFormat;
|
2011-11-11 11:25:53 +01:00
|
|
|
import java.text.ParseException;
|
2009-07-06 19:13:23 +02:00
|
|
|
import java.util.Arrays;
|
2009-04-14 17:51:03 +02:00
|
|
|
import java.util.Date;
|
2009-06-29 14:36:10 +02:00
|
|
|
import java.util.List;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2016-04-29 15:31:01 +03:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2009-04-14 17:51:03 +02:00
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
2010-10-01 17:40:24 +02:00
|
|
|
import org.joda.time.LocalDate;
|
2010-02-15 01:20:19 +01:00
|
|
|
import org.zkoss.ganttz.adapters.IDisabilityConfiguration;
|
2010-10-06 14:22:32 +02:00
|
|
|
import org.zkoss.ganttz.data.GanttDate;
|
2011-12-01 15:54:25 +01:00
|
|
|
import org.zkoss.ganttz.data.ITaskFundamentalProperties.IModifications;
|
|
|
|
|
import org.zkoss.ganttz.data.ITaskFundamentalProperties.IUpdatablePosition;
|
2009-07-20 18:00:11 +02:00
|
|
|
import org.zkoss.ganttz.data.Task;
|
2009-09-30 23:30:52 +02:00
|
|
|
import org.zkoss.ganttz.util.ComponentsFinder;
|
2009-06-20 18:32:34 +02:00
|
|
|
import org.zkoss.util.Locales;
|
2009-06-20 18:32:33 +02:00
|
|
|
import org.zkoss.zk.ui.Component;
|
2012-11-26 09:44:04 +01:00
|
|
|
import org.zkoss.zk.ui.Executions;
|
2009-07-06 19:13:23 +02:00
|
|
|
import org.zkoss.zk.ui.event.Event;
|
|
|
|
|
import org.zkoss.zk.ui.event.EventListener;
|
2012-11-26 09:44:04 +01:00
|
|
|
import org.zkoss.zk.ui.event.Events;
|
2009-06-29 14:36:10 +02:00
|
|
|
import org.zkoss.zk.ui.event.KeyEvent;
|
2009-07-05 17:15:31 +02:00
|
|
|
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
2009-04-14 17:51:03 +02:00
|
|
|
import org.zkoss.zul.Datebox;
|
|
|
|
|
import org.zkoss.zul.Textbox;
|
2009-07-05 17:15:31 +02:00
|
|
|
import org.zkoss.zul.Treecell;
|
2013-06-19 15:45:19 +02:00
|
|
|
import org.zkoss.zul.api.Div;
|
|
|
|
|
import org.zkoss.zul.api.Hlayout;
|
2010-08-17 16:26:01 +02:00
|
|
|
import org.zkoss.zul.api.Label;
|
2009-07-05 17:15:31 +02:00
|
|
|
import org.zkoss.zul.api.Treerow;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2011-11-11 11:25:53 +01:00
|
|
|
/**
|
|
|
|
|
* Row composer for Tasks details Tree <br />
|
|
|
|
|
*
|
|
|
|
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
|
|
|
|
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
|
|
|
|
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
2014-03-17 14:44:46 +01:00
|
|
|
* @author Jeroen Baten <jeroen@jeroenbaten.nl>
|
2011-11-11 11:25:53 +01:00
|
|
|
*/
|
2009-07-20 15:37:39 +02:00
|
|
|
public class LeftTasksTreeRow extends GenericForwardComposer {
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-07-20 15:37:39 +02:00
|
|
|
public interface ILeftTasksTreeNavigator {
|
|
|
|
|
LeftTasksTreeRow getBelowRow();
|
2009-07-05 17:15:27 +02:00
|
|
|
|
2009-07-20 15:37:39 +02:00
|
|
|
LeftTasksTreeRow getAboveRow();
|
2009-07-05 17:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
private final Task task;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2010-08-17 16:26:01 +02:00
|
|
|
private Label nameLabel;
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
private Textbox nameBox;
|
|
|
|
|
|
2010-08-17 16:26:01 +02:00
|
|
|
private Label startDateLabel;
|
|
|
|
|
|
2009-06-20 18:32:33 +02:00
|
|
|
private Textbox startDateTextBox;
|
|
|
|
|
|
2010-08-17 16:26:01 +02:00
|
|
|
private Label endDateLabel;
|
|
|
|
|
|
2009-06-20 18:32:33 +02:00
|
|
|
private Textbox endDateTextBox;
|
|
|
|
|
|
2011-11-11 11:25:53 +01:00
|
|
|
private Datebox openedDateBox = null;
|
2009-06-20 18:32:35 +02:00
|
|
|
|
|
|
|
|
private DateFormat dateFormat;
|
|
|
|
|
|
2011-11-14 19:18:23 +01:00
|
|
|
private Planner planner;
|
|
|
|
|
|
2013-06-19 15:45:19 +02:00
|
|
|
private Div hoursStatusDiv;
|
|
|
|
|
|
|
|
|
|
private Div budgetStatusDiv;
|
|
|
|
|
|
2009-07-20 15:37:39 +02:00
|
|
|
private final ILeftTasksTreeNavigator leftTasksTreeNavigator;
|
2009-07-05 17:15:27 +02:00
|
|
|
|
2010-02-15 01:20:19 +01:00
|
|
|
private final IDisabilityConfiguration disabilityConfiguration;
|
|
|
|
|
|
2016-04-29 15:31:01 +03:00
|
|
|
public static LeftTasksTreeRow create(IDisabilityConfiguration disabilityConfiguration,
|
|
|
|
|
Task bean,
|
|
|
|
|
ILeftTasksTreeNavigator taskDetailnavigator,
|
|
|
|
|
Planner planner) {
|
|
|
|
|
|
|
|
|
|
return new LeftTasksTreeRow(disabilityConfiguration, bean, taskDetailnavigator, planner);
|
2009-06-20 18:32:35 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-15 01:20:19 +01:00
|
|
|
private LeftTasksTreeRow(IDisabilityConfiguration disabilityConfiguration,
|
2016-04-29 15:31:01 +03:00
|
|
|
Task task,
|
|
|
|
|
ILeftTasksTreeNavigator leftTasksTreeNavigator,
|
|
|
|
|
Planner planner) {
|
|
|
|
|
|
2010-02-15 01:20:19 +01:00
|
|
|
this.disabilityConfiguration = disabilityConfiguration;
|
2009-07-20 18:00:11 +02:00
|
|
|
this.task = task;
|
2016-04-29 15:31:01 +03:00
|
|
|
this.dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locales.getCurrent());
|
2009-07-20 15:37:39 +02:00
|
|
|
this.leftTasksTreeNavigator = leftTasksTreeNavigator;
|
2011-11-14 19:18:23 +01:00
|
|
|
this.planner = planner;
|
2009-06-20 18:32:35 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
public Task getTask() {
|
|
|
|
|
return task;
|
2009-06-20 18:32:35 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
public Textbox getNameBox() {
|
|
|
|
|
return nameBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNameBox(Textbox nameBox) {
|
|
|
|
|
this.nameBox = nameBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
public Task getData() {
|
|
|
|
|
return task;
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-20 18:32:33 +02:00
|
|
|
/**
|
2009-06-29 14:36:09 +02:00
|
|
|
* When a text box associated to a datebox is requested to show the datebox,
|
|
|
|
|
* the corresponding datebox is shown
|
2009-06-20 18:32:33 +02:00
|
|
|
* @param component
|
|
|
|
|
* the component that has received focus
|
|
|
|
|
*/
|
2009-06-29 14:36:09 +02:00
|
|
|
public void userWantsDateBox(Component component) {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( component == startDateTextBox ) {
|
|
|
|
|
if ( canChangeStartDate() ) {
|
2011-11-11 11:25:53 +01:00
|
|
|
createDateBox(startDateTextBox);
|
2010-02-15 01:29:52 +01:00
|
|
|
}
|
2009-06-20 18:32:33 +02:00
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
if ( component == endDateTextBox ) {
|
|
|
|
|
if ( canChangeEndDate() ) {
|
2011-11-11 11:25:53 +01:00
|
|
|
createDateBox(endDateTextBox);
|
2010-02-15 01:29:52 +01:00
|
|
|
}
|
2009-06-20 18:32:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-11 11:25:53 +01:00
|
|
|
public void createDateBox(Textbox textbox) {
|
|
|
|
|
openedDateBox = new Datebox();
|
|
|
|
|
openedDateBox.setFormat("short");
|
|
|
|
|
openedDateBox.setButtonVisible(false);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
openedDateBox.setValue(dateFormat.parse(textbox.getValue()));
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerOnEnterOpenDateBox(openedDateBox);
|
|
|
|
|
registerBlurListener(openedDateBox);
|
|
|
|
|
registerOnChangeDatebox(openedDateBox, textbox);
|
|
|
|
|
|
|
|
|
|
textbox.setVisible(false);
|
|
|
|
|
textbox.getParent().appendChild(openedDateBox);
|
|
|
|
|
openedDateBox.setFocus(true);
|
|
|
|
|
openedDateBox.setOpen(true);
|
2009-06-20 18:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:36:10 +02:00
|
|
|
private enum Navigation {
|
|
|
|
|
LEFT, UP, RIGHT, DOWN;
|
|
|
|
|
public static Navigation getIntentFrom(KeyEvent keyEvent) {
|
|
|
|
|
return values()[keyEvent.getKeyCode() - 37];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void focusGoUp(int position) {
|
2009-07-20 15:37:39 +02:00
|
|
|
LeftTasksTreeRow aboveDetail = leftTasksTreeNavigator.getAboveRow();
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( aboveDetail != null ) {
|
2009-06-29 14:36:11 +02:00
|
|
|
aboveDetail.receiveFocus(position);
|
2009-06-29 14:36:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:36:11 +02:00
|
|
|
public void receiveFocus() {
|
|
|
|
|
receiveFocus(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void receiveFocus(int position) {
|
2009-07-06 19:13:23 +02:00
|
|
|
this.getTextBoxes().get(position).focus();
|
2009-06-29 14:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:36:10 +02:00
|
|
|
public void focusGoDown(int position) {
|
2009-07-20 15:37:39 +02:00
|
|
|
LeftTasksTreeRow belowDetail = leftTasksTreeNavigator.getBelowRow();
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( belowDetail != null ) {
|
2009-06-29 14:36:11 +02:00
|
|
|
belowDetail.receiveFocus(position);
|
2009-06-29 14:36:12 +02:00
|
|
|
} else {
|
2009-07-20 15:37:42 +02:00
|
|
|
getListDetails().getGoingDownInLastArrowCommand().doAction();
|
2009-06-29 14:36:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 15:37:39 +02:00
|
|
|
private LeftTasksTree getListDetails() {
|
2009-07-05 17:15:31 +02:00
|
|
|
Component current = nameBox;
|
2009-07-20 15:37:39 +02:00
|
|
|
while (!(current instanceof LeftTasksTree)) {
|
2009-06-29 14:36:12 +02:00
|
|
|
current = current.getParent();
|
|
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
2009-07-20 15:37:39 +02:00
|
|
|
return (LeftTasksTree) current;
|
2009-06-29 14:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:36:10 +02:00
|
|
|
public void userWantsToMove(Textbox textbox, KeyEvent keyEvent) {
|
|
|
|
|
Navigation navigation = Navigation.getIntentFrom(keyEvent);
|
2009-07-06 19:13:23 +02:00
|
|
|
List<Textbox> textBoxes = getTextBoxes();
|
|
|
|
|
int position = textBoxes.indexOf(textbox);
|
2009-06-29 14:36:10 +02:00
|
|
|
switch (navigation) {
|
2016-04-29 15:31:01 +03:00
|
|
|
case UP:
|
2009-06-29 14:36:10 +02:00
|
|
|
focusGoUp(position);
|
|
|
|
|
break;
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
case DOWN:
|
2009-06-29 14:36:10 +02:00
|
|
|
focusGoDown(position);
|
|
|
|
|
break;
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
default:
|
2009-06-29 14:36:10 +02:00
|
|
|
throw new RuntimeException("case not covered: " + navigation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-06 19:13:23 +02:00
|
|
|
private List<Textbox> getTextBoxes() {
|
|
|
|
|
return Arrays.asList(nameBox, startDateTextBox, endDateTextBox);
|
2009-06-29 14:36:10 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-20 18:32:33 +02:00
|
|
|
/**
|
|
|
|
|
* When the dateBox loses focus the corresponding textbox is shown instead.
|
|
|
|
|
* @param dateBox
|
|
|
|
|
* the component that has lost focus
|
|
|
|
|
*/
|
|
|
|
|
public void dateBoxHasLostFocus(Datebox dateBox) {
|
2011-11-11 11:25:53 +01:00
|
|
|
dateBox.getPreviousSibling().setVisible(true);
|
|
|
|
|
dateBox.setParent(null);
|
2009-06-20 18:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
@Override
|
2009-07-05 17:15:31 +02:00
|
|
|
public void doAfterCompose(Component component) throws Exception {
|
|
|
|
|
super.doAfterCompose(component);
|
|
|
|
|
findComponents((Treerow) component);
|
2011-11-11 11:25:53 +01:00
|
|
|
registerTextboxesListeners();
|
2009-04-14 17:51:03 +02:00
|
|
|
updateComponents();
|
2016-02-23 16:10:51 +02:00
|
|
|
task.addFundamentalPropertiesChangeListener(new PropertyChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
|
|
updateComponents();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2009-07-06 19:13:23 +02:00
|
|
|
}
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2011-11-11 11:25:53 +01:00
|
|
|
private void registerTextboxesListeners() {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( disabilityConfiguration.isTreeEditable() ) {
|
2010-08-17 16:26:01 +02:00
|
|
|
registerKeyboardListener(nameBox);
|
2011-11-11 11:25:53 +01:00
|
|
|
registerOnChange(nameBox);
|
2010-08-17 16:26:01 +02:00
|
|
|
registerKeyboardListener(startDateTextBox);
|
|
|
|
|
registerKeyboardListener(endDateTextBox);
|
|
|
|
|
registerOnEnterListener(startDateTextBox);
|
|
|
|
|
registerOnEnterListener(endDateTextBox);
|
2011-11-11 11:25:53 +01:00
|
|
|
registerOnChange(startDateTextBox);
|
|
|
|
|
registerOnChange(endDateTextBox);
|
2010-08-17 16:26:01 +02:00
|
|
|
}
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-05 17:15:31 +02:00
|
|
|
private void findComponents(Treerow row) {
|
|
|
|
|
List<Object> rowChildren = row.getChildren();
|
2016-04-29 15:31:01 +03:00
|
|
|
List<Treecell> treeCells = ComponentsFinder.findComponentsOfType(Treecell.class, rowChildren);
|
2013-06-19 15:45:19 +02:00
|
|
|
assert treeCells.size() == 4;
|
2016-04-29 15:31:01 +03:00
|
|
|
|
2009-07-05 17:15:31 +02:00
|
|
|
findComponentsForNameCell(treeCells.get(0));
|
|
|
|
|
findComponentsForStartDateCell(treeCells.get(1));
|
|
|
|
|
findComponentsForEndDateCell(treeCells.get(2));
|
2013-06-19 15:45:19 +02:00
|
|
|
findComponentsForStatusCell(treeCells.get(3));
|
2009-07-05 17:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Textbox findTextBoxOfCell(Treecell treecell) {
|
|
|
|
|
List<Object> children = treecell.getChildren();
|
2016-04-29 15:31:01 +03:00
|
|
|
return ComponentsFinder.findComponentsOfType(Textbox.class, children).get(0);
|
2009-07-05 17:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void findComponentsForNameCell(Treecell treecell) {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( disabilityConfiguration.isTreeEditable() ) {
|
2010-08-17 16:26:01 +02:00
|
|
|
nameBox = (Textbox) treecell.getChildren().get(0);
|
|
|
|
|
} else {
|
|
|
|
|
nameLabel = (Label) treecell.getChildren().get(0);
|
|
|
|
|
}
|
2009-07-05 17:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-06 19:13:23 +02:00
|
|
|
private void registerKeyboardListener(final Textbox textBox) {
|
|
|
|
|
textBox.addEventListener("onCtrlKey", new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-06-06 17:46:26 +02:00
|
|
|
public void onEvent(Event event) {
|
2009-07-06 19:13:23 +02:00
|
|
|
userWantsToMove(textBox, (KeyEvent) event);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 01:45:30 +01:00
|
|
|
private void registerOnChange(final Component component) {
|
2009-07-06 19:13:23 +02:00
|
|
|
component.addEventListener("onChange", new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-06-06 17:46:26 +02:00
|
|
|
public void onEvent(Event event) {
|
2010-02-15 01:45:30 +01:00
|
|
|
updateBean(component);
|
2009-07-06 19:13:23 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 15:31:01 +03:00
|
|
|
private void registerOnChangeDatebox(final Datebox datebox, final Textbox textbox) {
|
2011-11-11 11:25:53 +01:00
|
|
|
datebox.addEventListener("onChange", new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(Event event) {
|
|
|
|
|
textbox.setValue(dateFormat.format(datebox.getValue()));
|
|
|
|
|
updateBean(textbox);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-06 19:13:23 +02:00
|
|
|
private void registerOnEnterListener(final Textbox textBox) {
|
|
|
|
|
textBox.addEventListener("onOK", new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-06-06 17:46:26 +02:00
|
|
|
public void onEvent(Event event) {
|
2009-07-06 19:13:23 +02:00
|
|
|
userWantsDateBox(textBox);
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-07-06 20:01:27 +02:00
|
|
|
}
|
2009-07-06 19:13:23 +02:00
|
|
|
|
2009-07-06 20:01:27 +02:00
|
|
|
private void registerOnEnterOpenDateBox(final Datebox datebox) {
|
|
|
|
|
datebox.addEventListener("onOK", new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-06-06 17:46:26 +02:00
|
|
|
public void onEvent(Event event) {
|
2009-07-06 20:01:27 +02:00
|
|
|
datebox.setOpen(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-07-06 19:13:23 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-05 17:15:31 +02:00
|
|
|
private void findComponentsForStartDateCell(Treecell treecell) {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( disabilityConfiguration.isTreeEditable() ) {
|
2010-08-17 16:26:01 +02:00
|
|
|
startDateTextBox = findTextBoxOfCell(treecell);
|
|
|
|
|
} else {
|
|
|
|
|
startDateLabel = (Label) treecell.getChildren().get(0);
|
|
|
|
|
}
|
2009-07-05 17:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void findComponentsForEndDateCell(Treecell treecell) {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( disabilityConfiguration.isTreeEditable() ) {
|
2010-08-17 16:26:01 +02:00
|
|
|
endDateTextBox = findTextBoxOfCell(treecell);
|
|
|
|
|
} else {
|
|
|
|
|
endDateLabel = (Label) treecell.getChildren().get(0);
|
|
|
|
|
}
|
2009-07-05 17:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-19 15:45:19 +02:00
|
|
|
private void findComponentsForStatusCell(Treecell treecell) {
|
|
|
|
|
List<Object> children = treecell.getChildren();
|
|
|
|
|
|
2016-04-29 15:31:01 +03:00
|
|
|
Hlayout hlayout = ComponentsFinder.findComponentsOfType(Hlayout.class, children).get(0);
|
2013-06-19 15:45:19 +02:00
|
|
|
|
|
|
|
|
hoursStatusDiv = (Div) hlayout.getChildren().get(0);
|
2014-03-17 14:44:46 +01:00
|
|
|
// there is a <label> "/" between the divs
|
|
|
|
|
budgetStatusDiv = (Div) hlayout.getChildren().get(2);
|
2013-06-19 15:45:19 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-06 19:13:23 +02:00
|
|
|
private void registerBlurListener(final Datebox datebox) {
|
|
|
|
|
datebox.addEventListener("onBlur", new EventListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-06-06 17:46:26 +02:00
|
|
|
public void onEvent(Event event) {
|
2009-07-06 19:13:23 +02:00
|
|
|
dateBoxHasLostFocus(datebox);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 01:45:30 +01:00
|
|
|
public void updateBean(Component updatedComponent) {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( updatedComponent == getNameBox() ) {
|
|
|
|
|
|
2010-02-15 01:45:30 +01:00
|
|
|
task.setName(getNameBox().getValue());
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
if ( StringUtils.isEmpty(getNameBox().getValue()) ) {
|
2011-11-11 11:25:53 +01:00
|
|
|
getNameBox().setValue(task.getName());
|
|
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
} else if ( updatedComponent == getStartDateTextBox() ) {
|
|
|
|
|
|
2011-11-11 11:25:53 +01:00
|
|
|
try {
|
2016-04-29 15:31:01 +03:00
|
|
|
final Date begin = dateFormat.parse(getStartDateTextBox().getValue());
|
2011-12-01 15:54:25 +01:00
|
|
|
task.doPositionModifications(new IModifications() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void doIt(IUpdatablePosition position) {
|
|
|
|
|
position.moveTo(GanttDate.createFrom(begin));
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-11-11 11:25:53 +01:00
|
|
|
} catch (ParseException e) {
|
2012-04-30 18:22:22 +02:00
|
|
|
// Do nothing as textbox is rested in the next sentence
|
2011-11-11 11:25:53 +01:00
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
getStartDateTextBox().setValue(dateFormat.format(task.getBeginDate().toDayRoundedDate()));
|
|
|
|
|
|
|
|
|
|
} else if ( updatedComponent == getEndDateTextBox() ) {
|
|
|
|
|
|
2011-11-11 11:25:53 +01:00
|
|
|
try {
|
|
|
|
|
Date newEnd = dateFormat.parse(getEndDateTextBox().getValue());
|
|
|
|
|
task.resizeTo(LocalDate.fromDateFields(newEnd));
|
|
|
|
|
} catch (ParseException e) {
|
2012-04-30 18:22:22 +02:00
|
|
|
// Do nothing as textbox is rested in the next sentence
|
2011-11-11 11:25:53 +01:00
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
getEndDateTextBox().setValue(asString(task.getEndDate().toDayRoundedDate()));
|
2010-02-15 01:45:30 +01:00
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
2011-11-14 19:18:23 +01:00
|
|
|
planner.updateTooltips();
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateComponents() {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( disabilityConfiguration.isTreeEditable() ) {
|
2010-08-17 16:26:01 +02:00
|
|
|
getNameBox().setValue(task.getName());
|
|
|
|
|
getNameBox().setDisabled(!canRenameTask());
|
|
|
|
|
getNameBox().setTooltiptext(task.getName());
|
2010-02-15 01:29:52 +01:00
|
|
|
|
2010-08-17 16:26:01 +02:00
|
|
|
getStartDateTextBox().setDisabled(!canChangeStartDate());
|
|
|
|
|
getEndDateTextBox().setDisabled(!canChangeEndDate());
|
2010-02-15 01:29:52 +01:00
|
|
|
|
2016-04-29 15:31:01 +03:00
|
|
|
getStartDateTextBox().setValue(asString(task.getBeginDate().toDayRoundedDate()));
|
|
|
|
|
getEndDateTextBox().setValue(asString(task.getEndDate().toDayRoundedDate()));
|
2010-08-17 16:26:01 +02:00
|
|
|
} else {
|
|
|
|
|
nameLabel.setValue(task.getName());
|
2010-08-20 12:55:32 +02:00
|
|
|
nameLabel.setTooltiptext(task.getName());
|
2012-11-26 09:44:04 +01:00
|
|
|
nameLabel.setSclass("clickable-rows");
|
2016-04-29 15:31:01 +03:00
|
|
|
|
2012-11-26 09:44:04 +01:00
|
|
|
nameLabel.addEventListener(Events.ON_CLICK, new EventListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(Event arg0) throws Exception {
|
2016-04-29 15:31:01 +03:00
|
|
|
Executions.getCurrent().sendRedirect("/planner/index.zul;order=" + task.getProjectCode());
|
2012-11-26 09:44:04 +01:00
|
|
|
}
|
|
|
|
|
});
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
startDateLabel.setValue(asString(task.getBeginDate().toDayRoundedDate()));
|
|
|
|
|
endDateLabel.setValue(asString(task.getEndDate().toDayRoundedDate()));
|
2010-08-17 16:26:01 +02:00
|
|
|
}
|
2013-06-19 15:45:19 +02:00
|
|
|
|
2016-04-29 15:31:01 +03:00
|
|
|
setHoursStatus(task.getProjectHoursStatus(), task.getTooltipTextForProjectHoursStatus());
|
|
|
|
|
|
|
|
|
|
setBudgetStatus(task.getProjectBudgetStatus(), task.getTooltipTextForProjectBudgetStatus());
|
2009-06-20 18:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-15 01:20:19 +01:00
|
|
|
private boolean canChangeStartDate() {
|
2016-04-29 15:31:01 +03:00
|
|
|
return disabilityConfiguration.isMovingTasksEnabled() && task.canBeExplicitlyMoved();
|
2010-02-15 01:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean canChangeEndDate() {
|
2016-04-29 15:31:01 +03:00
|
|
|
return disabilityConfiguration.isResizingTasksEnabled() && task.canBeExplicitlyResized();
|
2010-02-15 01:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-23 13:31:35 +02:00
|
|
|
private boolean canRenameTask() {
|
|
|
|
|
return disabilityConfiguration.isRenamingTasksEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-20 18:32:33 +02:00
|
|
|
private String asString(Date date) {
|
|
|
|
|
return dateFormat.format(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Textbox getStartDateTextBox() {
|
|
|
|
|
return startDateTextBox;
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
2009-06-15 21:48:54 +02:00
|
|
|
|
2009-06-20 18:32:33 +02:00
|
|
|
public void setStartDateTextBox(Textbox startDateTextBox) {
|
|
|
|
|
this.startDateTextBox = startDateTextBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Textbox getEndDateTextBox() {
|
|
|
|
|
return endDateTextBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEndDateTextBox(Textbox endDateTextBox) {
|
|
|
|
|
this.endDateTextBox = endDateTextBox;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 15:45:19 +02:00
|
|
|
private void setHoursStatus(ProjectStatusEnum status, String tooltipText) {
|
|
|
|
|
hoursStatusDiv.setSclass(getProjectStatusSclass(status));
|
|
|
|
|
hoursStatusDiv.setTooltiptext(tooltipText);
|
|
|
|
|
onProjectStatusClick(hoursStatusDiv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setBudgetStatus(ProjectStatusEnum status, String tooltipText) {
|
|
|
|
|
budgetStatusDiv.setSclass(getProjectStatusSclass(status));
|
|
|
|
|
budgetStatusDiv.setTooltiptext(tooltipText);
|
|
|
|
|
onProjectStatusClick(budgetStatusDiv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getProjectStatusSclass(ProjectStatusEnum status) {
|
|
|
|
|
String cssClass;
|
2016-04-29 15:31:01 +03:00
|
|
|
|
2013-06-19 15:45:19 +02:00
|
|
|
switch (status) {
|
2016-04-29 15:31:01 +03:00
|
|
|
case MARGIN_EXCEEDED:
|
2013-06-19 15:45:19 +02:00
|
|
|
cssClass = "status-red";
|
|
|
|
|
break;
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
case WITHIN_MARGIN:
|
2013-06-19 15:45:19 +02:00
|
|
|
cssClass = "status-orange";
|
|
|
|
|
break;
|
2016-04-29 15:31:01 +03:00
|
|
|
|
|
|
|
|
case AS_PLANNED:
|
|
|
|
|
|
|
|
|
|
default:
|
2013-06-19 15:45:19 +02:00
|
|
|
cssClass = "status-green";
|
|
|
|
|
}
|
2016-04-29 15:31:01 +03:00
|
|
|
|
2013-06-19 15:45:19 +02:00
|
|
|
return cssClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onProjectStatusClick(Component statucComp) {
|
2016-04-29 15:31:01 +03:00
|
|
|
if ( !disabilityConfiguration.isTreeEditable() ) {
|
2013-06-19 15:45:19 +02:00
|
|
|
statucComp.addEventListener(Events.ON_CLICK, new EventListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(Event arg0) throws Exception {
|
2016-04-29 15:31:01 +03:00
|
|
|
Executions.getCurrent().sendRedirect("/planner/index.zul;order=" + task.getProjectCode());
|
2013-06-19 15:45:19 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|