aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-13 11:44:03 (EDT)
committerChris Aniszczyk2011-04-14 10:48:19 (EDT)
commit8f7221c3d29ed844278b879935a03ec4efbe9fad (patch)
tree82b5a6c4bf4f6377ff8de553b77fe0bbb0fe8b1a
parentd18bdab77d43f36efd037f6830f78c4c5d4a0735 (diff)
downloadegit-github-8f7221c3d29ed844278b879935a03ec4efbe9fad.zip
egit-github-8f7221c3d29ed844278b879935a03ec4efbe9fad.tar.gz
egit-github-8f7221c3d29ed844278b879935a03ec4efbe9fad.tar.bz2
Add custom issue attribute part instead of extendingrefs/changes/90/3090/4
This attribute part uses a custom layout to display only the milestones and labels attributes. Change-Id: Iea495085a3929ff556470a2f1c293bccaa223fb7 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/IssueAttributePart.java216
1 files changed, 211 insertions, 5 deletions
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/IssueAttributePart.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/IssueAttributePart.java
index f06977b..0dc2766 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/IssueAttributePart.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/IssueAttributePart.java
@@ -10,20 +10,58 @@
*******************************************************************************/
package org.eclipse.mylyn.github.ui.internal;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.github.internal.GitHubTaskAttributes;
-import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttributePart;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonFormUtil;
+import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AbstractTaskEditorSection;
+import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
+import org.eclipse.mylyn.internal.tasks.ui.editors.Messages;
+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.internal.tasks.ui.views.UpdateRepositoryConfigurationAction;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
+import org.eclipse.mylyn.tasks.core.sync.TaskJob;
+import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* GitHub issue task editor attribute part that display labels and milestone
* attribute editors.
*/
-public class IssueAttributePart extends TaskEditorAttributePart {
+public class IssueAttributePart extends AbstractTaskEditorSection {
+
+ private List<AbstractAttributeEditor> attributeEditors;
+
+ private boolean hasIncoming;
+
+ private Composite attributesComposite;
+
+ public IssueAttributePart() {
+ setPartName(Messages.TaskEditorAttributePart_Attributes);
+ }
- /**
- * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart#createAttributeEditor(org.eclipse.mylyn.tasks.core.data.TaskAttribute)
- */
+ @Override
protected AbstractAttributeEditor createAttributeEditor(
TaskAttribute attribute) {
if (GitHubTaskAttributes.LABELS.getId().equals(attribute.getId())) {
@@ -35,4 +73,172 @@ public class IssueAttributePart extends TaskEditorAttributePart {
return null;
}
+ private void createAttributeControls(Composite attributesComposite,
+ FormToolkit toolkit, int columnCount) {
+ for (AbstractAttributeEditor attributeEditor : attributeEditors) {
+ if (attributeEditor.hasLabel())
+ attributeEditor
+ .createLabelControl(attributesComposite, toolkit);
+ attributeEditor.createControl(attributesComposite, toolkit);
+ Object data = attributeEditor.getControl().getLayoutData();
+ if (data == null) {
+ data = GridDataFactory.swtDefaults().create();
+ attributeEditor.getControl().setLayoutData(data);
+ }
+ if (data instanceof GridData)
+ ((GridData) data).widthHint = 140;
+ getTaskEditorPage().getAttributeEditorToolkit().adapt(
+ attributeEditor);
+ }
+ }
+
+ @Override
+ public void createControl(Composite parent, final FormToolkit toolkit) {
+ initialize();
+ super.createControl(parent, toolkit);
+ }
+
+ @Override
+ protected String getInfoOverlayText() {
+ return null;
+ }
+
+ @Override
+ protected boolean shouldExpandOnCreate() {
+ return getTaskData().isNew() || hasIncoming;
+ }
+
+ @Override
+ protected Control createContent(FormToolkit toolkit, Composite parent) {
+ attributesComposite = toolkit.createComposite(parent);
+ attributesComposite.addListener(SWT.MouseDown, new Listener() {
+ public void handleEvent(Event event) {
+ Control focus = event.display.getFocusControl();
+ if (focus instanceof Text
+ && ((Text) focus).getEditable() == false)
+ getManagedForm().getForm().setFocus();
+ }
+ });
+
+ GridLayout attributesLayout = EditorUtil.createSectionClientLayout();
+ attributesLayout.numColumns = 2;
+ attributesLayout.horizontalSpacing = 7;
+ attributesLayout.verticalSpacing = 6;
+ attributesComposite.setLayout(attributesLayout);
+
+ GridData attributesData = new GridData(GridData.FILL_BOTH);
+ attributesData.horizontalSpan = 1;
+ attributesData.grabExcessVerticalSpace = false;
+ attributesComposite.setLayoutData(attributesData);
+
+ createAttributeControls(attributesComposite, toolkit,
+ attributesLayout.numColumns);
+ toolkit.paintBordersFor(attributesComposite);
+
+ return attributesComposite;
+ }
+
+ @Override
+ protected void fillToolBar(ToolBarManager toolBar) {
+ UpdateRepositoryConfigurationAction repositoryConfigRefresh = new UpdateRepositoryConfigurationAction() {
+ @Override
+ public void run() {
+ getTaskEditorPage().showEditorBusy(true);
+ final TaskJob job = TasksUiInternal.getJobFactory()
+ .createUpdateRepositoryConfigurationJob(
+ getTaskEditorPage().getConnector(),
+ getTaskEditorPage().getTaskRepository(),
+ getTaskEditorPage().getTask());
+ job.addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void done(IJobChangeEvent event) {
+ PlatformUI.getWorkbench().getDisplay()
+ .asyncExec(new Runnable() {
+ public void run() {
+ getTaskEditorPage().showEditorBusy(
+ false);
+ if (job.getStatus() != null) {
+ getTaskEditorPage()
+ .getTaskEditor()
+ .setStatus(
+ Messages.TaskEditorAttributePart_Updating_of_repository_configuration_failed,
+ Messages.TaskEditorAttributePart_Update_Failed,
+ job.getStatus());
+ } else {
+ getTaskEditorPage().refresh();
+ }
+ }
+ });
+ }
+ });
+ job.setUser(true);
+ job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY,
+ Boolean.TRUE);
+ job.setPriority(Job.INTERACTIVE);
+ job.schedule();
+ };
+
+ };
+ repositoryConfigRefresh
+ .setImageDescriptor(TasksUiImages.REPOSITORY_SYNCHRONIZE_SMALL);
+ repositoryConfigRefresh.selectionChanged(new StructuredSelection(
+ getTaskEditorPage().getTaskRepository()));
+ repositoryConfigRefresh
+ .setToolTipText(Messages.TaskEditorAttributePart_Refresh_Attributes);
+ toolBar.add(repositoryConfigRefresh);
+ }
+
+ private void initialize() {
+ attributeEditors = new ArrayList<AbstractAttributeEditor>();
+ hasIncoming = false;
+
+ TaskAttribute root = getTaskData().getRoot();
+ List<TaskAttribute> attributes = new LinkedList<TaskAttribute>();
+ TaskAttribute milestones = root
+ .getAttribute(GitHubTaskAttributes.MILESTONE.getId());
+ if (milestones != null)
+ attributes.add(milestones);
+
+ TaskAttribute labels = root.getAttribute(GitHubTaskAttributes.LABELS
+ .getId());
+ if (labels != null)
+ attributes.add(labels);
+
+ for (TaskAttribute attribute : attributes) {
+ AbstractAttributeEditor attributeEditor = createAttributeEditor(attribute);
+ if (attributeEditor != null) {
+ attributeEditors.add(attributeEditor);
+ if (getModel().hasIncomingChanges(attribute))
+ hasIncoming = true;
+ }
+ }
+ }
+
+ @Override
+ public boolean setFormInput(Object input) {
+ if (input instanceof String) {
+ String text = (String) input;
+ Map<String, TaskAttribute> attributes = getTaskData().getRoot()
+ .getAttributes();
+ for (TaskAttribute attribute : attributes.values())
+ if (text.equals(attribute.getId())) {
+ TaskAttributeMetaData properties = attribute.getMetaData();
+ if (TaskAttribute.KIND_DEFAULT.equals(properties.getKind()))
+ selectReveal(attribute);
+ }
+ }
+ return super.setFormInput(input);
+ }
+
+ public void selectReveal(TaskAttribute attribute) {
+ if (attribute == null)
+ return;
+
+ if (!getSection().isExpanded())
+ CommonFormUtil.setExpanded(getSection(), true);
+
+ EditorUtil.reveal(getTaskEditorPage().getManagedForm().getForm(),
+ attribute.getId());
+ }
+
} \ No newline at end of file