@Override
protected void populateItem(final Item<GanttTreeTableNode> item)
{
final GanttTreeTableNode node = item.getModelObject();
final GanttTask ganttObject = node.getGanttObject();
final TaskDO task = taskDao.getTaskTree().getTaskById((Integer) ganttObject.getId());
if (item.getIndex() % 2 == 0) {
item.add(AttributeModifier.replace("class", "even"));
} else {
item.add(AttributeModifier.replace("class", "odd"));
}
final Label formattedLabel = new Label(ListSelectActionPanel.LABEL_ID, new Model<String>() {
@Override
public String getObject()
{
if (NumberHelper.greaterZero((Integer) ganttObject.getId()) == true) {
return ganttObject.getTitle();
} else {
return "*" + ganttObject.getTitle() + "*";
}
};
}) {
@Override
protected void onBeforeRender()
{
final boolean clipboarded = clipboard != null && clipboard.getId() == ganttObject.getId();
if (clipboarded == true) {
add(AttributeModifier.replace("style", "font-weight: bold; color:red;"));
} else {
final Behavior behavior = WicketUtils.getAttributeModifier(this, "style");
if (behavior != null) {
this.remove(behavior);
}
}
super.onBeforeRender();
}
};
final TreeIconsActionPanel< ? extends TreeTableNode> treeIconsActionPanel = new TreeIconsActionPanel<GanttTreeTableNode>("tree",
new Model<GanttTreeTableNode>(node), formattedLabel, getTreeTable());
treeIconsActionPanel.setUseAjaxAtDefault(false).setUseSubmitLinkImages(true);
addColumn(item, treeIconsActionPanel, null);
treeIconsActionPanel.init(GanttChartEditTreeTablePanel.this, node);
treeIconsActionPanel.add(AttributeModifier.append("style", new Model<String>("white-space: nowrap;")));
treeIconsActionPanel.setUseAjaxAtDefault(false);
{
final WebMarkupContainer dropDownMenu = new WebMarkupContainer("dropDownMenu");
addColumn(item, dropDownMenu, "white-space: nowrap; width: 32px;");
dropDownMenu.add(new PresizedImage("cogImage", WebConstants.IMAGE_COG));
dropDownMenu.add(new PresizedImage("arrowDownImage", WebConstants.IMAGE_ARROW_DOWN));
final RepeatingView menuRepeater = new RepeatingView("menuEntriesRepeater");
dropDownMenu.add(menuRepeater);
menuRepeater.add(new ContextMenuEntry(menuRepeater.newChildId(), "mark") {
@Override
void onSubmit()
{
if (clipboard != null && clipboard == node.getGanttObject()) {
clipboard = null;
} else {
clipboard = node.getGanttObject();
}
};
});
menuRepeater.add(new ContextMenuEntry(menuRepeater.newChildId(), "gantt.predecessor.paste") {
@Override
public boolean isVisible()
{
return clipboard != null && clipboard != ganttObject;
}
@Override
void onSubmit()
{
ganttObject.setPredecessor(clipboard);
};
}.addTooltip(new Model<String>() {
@Override
public String getObject()
{
return getString("paste") + ": " + (clipboard != null ? clipboard.getTitle() : "-");
}
}));
menuRepeater.add(new ContextMenuEntry(menuRepeater.newChildId(), "gantt.contextMenu.newSubActivity") {
@Override
void onSubmit()
{
final GanttTaskImpl root = (GanttTaskImpl) ganttChartData.getRootObject();
final Integer nextId = root.getNextId();
ganttObject.addChild(new GanttTaskImpl(nextId).setVisible(true).setTitle(getString("untitled")));
final Set<Serializable> openNodes = getOpenNodes();
openNodes.add(ganttObject.getId());
refreshTreeTable();
setOpenNodes(openNodes);
form.getParentPage().refresh();
};
});
menuRepeater.add(new ContextMenuEntry(menuRepeater.newChildId(), new Model<String>() {
@Override
public String getObject()
{
if (clipboard == ganttObject) {
return PFUserContext.getLocalizedString("gantt.action.moveToTop");
} else {
return PFUserContext.getLocalizedString("gantt.action.move");
}
};
}) {
@Override
public boolean isVisible()
{
if (clipboard == null) {
return false;
}
if (clipboard != ganttObject) {
return true;
}
final GanttTaskImpl root = (GanttTaskImpl) ganttChartData.getRootObject();
final GanttTask parent = root.findParent(ganttObject.getId());
return (root != parent);
}
@Override
void onSubmit()
{
if (clipboard == null) {
return;
}
final GanttTaskImpl root = (GanttTaskImpl) ganttChartData.getRootObject();
final GanttTask parent = root.findParent(clipboard.getId());
final TaskDO task = taskDao.getTaskTree().getTaskById((Integer) clipboard.getId());
parent.removeChild(clipboard);
if (clipboard == ganttObject) {
// Move to top level:
root.addChild(ganttObject);
final TaskDO rootTask = form.getData().getTask();
if (rootTask != null && task != null) {
task.setParentTask(rootTask);
taskDao.update(task);
}
} else {
// Move as a child of this Gantt activity:
ganttObject.addChild(clipboard);
final TaskDO parentTask = taskDao.getTaskTree().getTaskById((Integer) ganttObject.getId());
if (parentTask != null && task != null) {
task.setParentTask(parentTask);
taskDao.update(task);
}
getOpenNodes().add(ganttObject.getId());
}
final Set<Serializable> openNodes = getOpenNodes();
refreshTreeTable();
setOpenNodes(openNodes);
form.getParentPage().refresh();
};
@Override
protected void onBeforeRender()
{
if (clipboard != null) {
final TaskDO task = taskDao.getTaskTree().getTaskById((Integer) clipboard.getId());
if (task != null && onClick == null) {
// Question for safety before moving a task.
setOnClick("if (!showMoveTaskQuestionDialog()) return;");
}
}
super.onBeforeRender();
}
});
menuRepeater.add(new ContextMenuEntry(menuRepeater.newChildId(), "delete") {
@Override
public boolean isVisible()
{
return task == null;
}
@Override
void onSubmit()
{
final GanttTaskImpl root = (GanttTaskImpl) ganttChartData.getRootObject();
final GanttTask parent = root.findParent(ganttObject.getId());
parent.removeChild(ganttObject);
final Set<Serializable> openNodes = getOpenNodes();
refreshTreeTable();
setOpenNodes(openNodes);
form.getParentPage().refresh();
};
}.setOnClick("if (!showDeleteQuestionDialog()) return;"));
menuRepeater.add(new ContextMenuEntry(menuRepeater.newChildId(), "gantt.contextMenu.saveAsTask") {
@Override
public boolean isVisible()
{
return task == null;
}
@Override
void onSubmit()
{
final GanttTaskImpl root = (GanttTaskImpl) ganttChartData.getRootObject();
final GanttTask parent = root.findParent(ganttObject.getId());
final TaskDO parentTask = taskDao.getTaskTree().getTaskById((Integer) parent.getId());
if (parentTask == null) {
throw new UserException("gantt.error.parentObjectIsNotAPFTask");
}
TaskDO task = taskDao.getTaskTree().getTaskById((Integer) ganttObject.getId());
if (task != null) {
// Oups, Gantt object is already a ProjectForge task.
return;
}
task = Task2GanttTaskConverter.convertToTask(ganttObject);
task.setParentTask(parentTask);
final GanttTask predecessor = ganttObject.getPredecessor();
if (predecessor != null) {
final TaskDO predecessorTask = taskDao.getTaskTree().getTaskById((Integer) predecessor.getId());
if (predecessorTask != null) {
task.setGanttPredecessor(predecessorTask);
}
}
final Set<Serializable> openNodes = getOpenNodes();