-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
ali-plugin-main/src/main/java/com/hp/alm/ali/idea/action/task/TaskAddInvestedAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
|
||
@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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
ali-plugin-main/src/main/java/com/hp/alm/ali/idea/ui/editor/TaskAddInvestedEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.