Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 40: interface to add invested task time #41

Merged
merged 2 commits into from
Oct 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.hp.alm.ali.idea.action.task;

import com.hp.alm.ali.idea.action.EntityAction;
import com.hp.alm.ali.idea.entity.EntityEditManager;
import com.hp.alm.ali.idea.model.Entity;
import com.hp.alm.ali.idea.ui.editor.TaskAddInvestedEditor;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;

import java.util.Collections;
import java.util.Set;

public class TaskAddInvestedAction extends EntityAction {

public TaskAddInvestedAction() {
super("Add invested", "Add time invested and decrease remaining time", IconLoader.getIcon("/actions/profile.png"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found that in Idea 13.1.6 this icon ("/actions/profile.png") does not exist.

}

@Override
protected Set<String> getSupportedEntityTypes() {
return Collections.singleton("project-task");
}

@Override
public void update(AnActionEvent event, Project project, Entity entity) {
EntityEditManager entityEditManager = project.getComponent(EntityEditManager.class);
event.getPresentation().setEnabled(!entityEditManager.isEditing(entity));
}

@Override
protected void actionPerformed(AnActionEvent event, Project project, Entity entity) {
TaskAddInvestedEditor taskAddInvestedEditor = new TaskAddInvestedEditor(project, entity);
taskAddInvestedEditor.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.hp.alm.ali.idea.translate.Translator;
import com.hp.alm.ali.idea.translate.ValueCallback;
import com.hp.alm.ali.idea.model.type.UserType;
import com.hp.alm.ali.idea.ui.editor.TaskAddInvestedEditor;
import com.hp.alm.ali.idea.ui.event.PopupAdapter;
import com.hp.alm.ali.idea.ui.Highlightable;
import com.hp.alm.ali.idea.ui.SimpleHighlight;
Expand Down Expand Up @@ -87,7 +88,7 @@ public class TaskPanel extends JLayeredPane implements Highlightable, DataProvid
private TranslateService translateService;
private Translator userTranslator;

public TaskPanel(Entity task, final Project project, BacklogItemPanel pBacklogItemPanel) {
public TaskPanel(final Entity task, final Project project, BacklogItemPanel pBacklogItemPanel) {
this.task = task;
this.project = project;
this.backlogItemPanel = pBacklogItemPanel;
Expand Down Expand Up @@ -163,6 +164,11 @@ public void mouseClicked(MouseEvent e) {
ActionPopupMenu popupMenu = ActionUtil.createActionPopup("hpali.task", "taskboard");
popupMenu.getComponent().show(moreLink, 0, 0);
}
point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), timePanel.effortLabel);
if (timePanel.effortLabel.contains(point)) {
TaskAddInvestedEditor taskAddInvestedEditor = new TaskAddInvestedEditor(project, task);
taskAddInvestedEditor.execute();
}
}
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class TimePanel extends JPanel {

private JLabel effortLabel;
JLabel effortLabel;
private JLabel investedLabel;
private JLabel investedEstimatedSeparator;
private JLabel remainingLabel;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.hp.alm.ali.idea.ui.editor;

import com.hp.alm.ali.idea.entity.EntityRef;
import com.hp.alm.ali.idea.model.Entity;
import com.hp.alm.ali.idea.services.EntityService;
import com.hp.alm.ali.idea.ui.editor.field.SpinnerField;
import com.intellij.openapi.project.Project;

import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;

public class TaskAddInvestedEditor extends BaseEditor {

protected EntityService entityService;

public TaskAddInvestedEditor(Project project, Entity task) {
this(project, task, new Edit(project));
}

public TaskAddInvestedEditor(Project project, Entity task, SaveHandler saveHandler) {
super(project, "Add invested time", task, saveHandler);

entityService = project.getComponent(EntityService.class);

setSize(new Dimension(290, 220));
centerOnOwner();
}

@Override
public void update() {
addField("invested", new SpinnerField("Add invested", "0", true));

JTextPane addProperty = new JTextPane();
addProperty.setBackground(gridFooter.getBackground());
addProperty.setEditorKit(new HTMLEditorKit());
addProperty.setText("<html><body><i style=\"font-size:x-small;\"><b>Info:</b><br/>Add selected amount to invested time and removes same<br> amount from remaining time.<br/>If there is not enough remaining time it will be set to 0.</i></body></html>");
addProperty.setEditable(false);
gridFooter.add(addProperty);

}

public static class Edit implements SaveHandler {

private EntityService entityService;

public Edit(Project project) {
entityService = project.getComponent(EntityService.class);
}

@Override
public boolean save(Entity modified, Entity entity) {
modified.setProperty("release-backlog-item-id", entity.getPropertyValue("release-backlog-item-id"));

int addInvested = Integer.valueOf(modified.getPropertyValue("invested"));
int invested = Integer.valueOf(entity.getPropertyValue("invested")) + addInvested;
int remaining = Integer.valueOf(entity.getPropertyValue("remaining")) - addInvested;
modified.setProperty("invested", String.valueOf(invested));
modified.setProperty("remaining", remaining > 0 ? String.valueOf(remaining) : "0");

final Entity updatedTask = entityService.updateEntity(modified, null, false);
if(updatedTask != null) {
entityService.getEntityAsync(new EntityRef("release-backlog-item", Integer.valueOf(entity.getPropertyValue("release-backlog-item-id"))), null);
return true;
} else {
return false;
}
}
}

}
1 change: 1 addition & 0 deletions ali-plugin-main/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@

<actions>
<group id="hpali.task">
<action id="hpali.task.addInvested" class="com.hp.alm.ali.idea.action.task.TaskAddInvestedAction"/>
<action id="hpali.task.modify" class="com.hp.alm.ali.idea.action.task.TaskEditAction"/>
<action id="hpali.task.delete" class="com.hp.alm.ali.idea.action.task.TaskDeleteAction"/>
</group>
Expand Down