Skip to content

Commit

Permalink
Add support for github votes.
Browse files Browse the repository at this point in the history
Signed-off-by: michael handler <michael.handler@fullstop.at>
  • Loading branch information
mhandler committed Feb 24, 2010
1 parent 5b55627 commit d61a4d1
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 1 deletion.
Empty file modified .gitignore
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum GitHubTaskAttributes {

TITLE("Summary", TaskAttribute.SUMMARY, TaskAttribute.TYPE_SHORT_TEXT, true, false, true),

VOTES("Votes", TaskAttribute.RANK, TaskAttribute.TYPE_INTEGER, false, true, false),
VOTES("Votes", "task.github.votes", TaskAttribute.TYPE_INTEGER, false, true, false),

BODY("Description", TaskAttribute.DESCRIPTION, TaskAttribute.TYPE_LONG_RICH_TEXT, true, false,
true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
import java.util.Set;

import org.eclipse.mylyn.github.internal.GitHub;
import org.eclipse.mylyn.github.ui.internal.editorpart.GitHubIntegerEditor;
import org.eclipse.mylyn.github.ui.internal.editorpart.GitHubTaskEditorPartDescriptor;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;

Expand Down Expand Up @@ -54,7 +59,21 @@ protected Set<TaskEditorPartDescriptor> createPartDescriptors() {
iterator.remove();
}
}
partDescriptors.add(new GitHubTaskEditorPartDescriptor());
return partDescriptors;
}

@Override
protected AttributeEditorFactory createAttributeEditorFactory() {
return new AttributeEditorFactory(getModel(), getTaskRepository(), getEditorSite()) {
@Override
public AbstractAttributeEditor createEditor(String type, TaskAttribute taskAttribute) {
if (type.equals("integer")) {
return new GitHubIntegerEditor(getModel(), taskAttribute);
}
return super.createEditor(type, taskAttribute);
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.eclipse.mylyn.github.ui.internal.editorpart;

import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class GitHubIntegerEditor extends AbstractAttributeEditor {

public GitHubIntegerEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
}

@Override
public void createControl(Composite parent, FormToolkit toolkit) {
Text text = new Text(parent, SWT.FLAT | SWT.READ_ONLY);
toolkit.adapt(text, false, false);
text.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
text.setText(getTaskAttribute().getValue());
setControl(text);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.eclipse.mylyn.github.ui.internal.editorpart;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class GitHubTaskEditorPart extends AbstractTaskEditorPart {

@Override
public String getPartName() {
return "GitHub Attributes";
}

@Override
public void createControl(Composite parent, FormToolkit toolkit) {
int style = ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
| ExpandableComposite.EXPANDED;

Section section = createSection(parent, toolkit, style);
GridDataFactory.fillDefaults().grab(true, false).applyTo(section);
section.setText("Github Attributes");
GridDataFactory.fillDefaults().grab(true, false).applyTo(section);
setSection(toolkit, section);

Composite composite = toolkit.createComposite(section);
GridLayout layout2 = createSectionClientLayout();
layout2.numColumns = 1;
composite.setLayout(layout2);

Composite headerComposite = toolkit.createComposite(composite);
GridLayout layout = new GridLayout(1, false);
layout.verticalSpacing = 1;
layout.marginHeight = 0;
layout.marginWidth = 0;
headerComposite.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, false).applyTo(headerComposite);

TaskAttribute statusAtribute = getTaskData().getRoot().getMappedAttribute(
"task.github.votes");
addAttribute(headerComposite, toolkit, statusAtribute, 0);

// ensure layout does not wrap
layout.numColumns = headerComposite.getChildren().length;

// ensure that the composite does not show a bunch of blank space
if (layout.numColumns == 0) {
layout.numColumns = 1;
toolkit.createLabel(headerComposite, " "); //$NON-NLS-1$
}

toolkit.paintBordersFor(composite);
section.setClient(composite);
}

private GridLayout createSectionClientLayout() {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
// leave 1px for borders
layout.marginTop = 2;
// spacing if a section is expanded
layout.marginBottom = 8;
return layout;
}

private void addAttribute(Composite composite, FormToolkit toolkit, TaskAttribute attribute,
int indent) {
AbstractAttributeEditor editor = createAttributeEditor(attribute);
if (editor != null) {
// having editable controls in the header looks odd
editor.setReadOnly(true);
editor.setDecorationEnabled(false);

editor.createLabelControl(composite, toolkit);
GridDataFactory.defaultsFor(editor.getLabelControl()).indent(indent, 0).applyTo(
editor.getLabelControl());

editor.createControl(composite, toolkit);
getTaskEditorPage().getAttributeEditorToolkit().adapt(editor);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.eclipse.mylyn.github.ui.internal.editorpart;

import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;

public class GitHubTaskEditorPartDescriptor extends TaskEditorPartDescriptor {

public GitHubTaskEditorPartDescriptor() {
super("org.eclipse.mylyn.github.editor.parts.github");
setPath(AbstractTaskEditorPage.PATH_ATTRIBUTES);
}

@Override
public AbstractTaskEditorPart createPart() {
return new GitHubTaskEditorPart();
}

}

0 comments on commit d61a4d1

Please sign in to comment.