Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2011-05-15 17:09:54 +0000
committerspingel2011-05-15 17:09:54 +0000
commit92a92f2b7e3b1690ad14a88089cea7f62dc3efe8 (patch)
treec05e6e146adf11f0aefc810dcb10e1dd1f71f821 /org.eclipse.mylyn.tasks.ui
parentf431995476b7fdfa11a229c8a1711a4c0dbf3260 (diff)
downloadorg.eclipse.mylyn.tasks-92a92f2b7e3b1690ad14a88089cea7f62dc3efe8.tar.gz
org.eclipse.mylyn.tasks-92a92f2b7e3b1690ad14a88089cea7f62dc3efe8.tar.xz
org.eclipse.mylyn.tasks-92a92f2b7e3b1690ad14a88089cea7f62dc3efe8.zip
NEW - bug 345826: show Gravatar images in task editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=345826
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java11
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorSummaryPart.java15
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/UserAttributeEditor.java155
4 files changed, 179 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF
index a97f2218d..d68c34f2f 100644
--- a/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF
@@ -21,6 +21,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.mylyn.commons.core;bundle-version="[3.0.0,4.0.0)",
org.eclipse.mylyn.monitor.ui;bundle-version="[3.0.0,4.0.0)",
org.eclipse.mylyn.tasks.core;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.mylyn.commons.identity;bundle-version="0.8.0",
org.eclipse.mylyn.commons.net;bundle-version="[3.0.0,4.0.0)",
org.eclipse.mylyn.commons.ui;bundle-version="[3.0.0,4.0.0)",
org.eclipse.mylyn.monitor.core;bundle-version="[3.0.0,4.0.0)",
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java
index bdf405d1e..71ae0d530 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java
@@ -54,6 +54,8 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.context.core.ContextCore;
+import org.eclipse.mylyn.internal.commons.identity.IdentityModel;
+import org.eclipse.mylyn.internal.commons.identity.gravatar.GravatarConnector;
import org.eclipse.mylyn.internal.commons.ui.TaskBarManager;
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin;
@@ -1016,6 +1018,8 @@ public class TasksUiPlugin extends AbstractUIPlugin {
private final Map<String, List<IDynamicSubMenuContributor>> menuContributors = new HashMap<String, List<IDynamicSubMenuContributor>>();
+ private IdentityModel identityModel;
+
public Map<String, List<IDynamicSubMenuContributor>> getDynamicMenuMap() {
return menuContributors;
}
@@ -1394,4 +1398,11 @@ public class TasksUiPlugin extends AbstractUIPlugin {
return synchronizationManger;
}
+ public IdentityModel getIdentityModel() {
+ if (identityModel == null) {
+ identityModel = new IdentityModel(new File(getDataDirectory(), "cache"));
+ identityModel.addConnector(new GravatarConnector());
+ }
+ return identityModel;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorSummaryPart.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorSummaryPart.java
index 276185b8a..180748591 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorSummaryPart.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorSummaryPart.java
@@ -159,7 +159,7 @@ public class TaskEditorSummaryPart extends AbstractTaskEditorPart {
public void createControl(Composite parent, FormToolkit toolkit) {
Composite composite = toolkit.createComposite(parent);
GridLayout layout = EditorUtil.createSectionClientLayout();
- layout.numColumns = 2;
+ layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginTop = 0;
layout.marginWidth = 0;
@@ -182,12 +182,20 @@ public class TaskEditorSummaryPart extends AbstractTaskEditorPart {
}
}
});
- } else {
- layout.numColumns = 1;
+ layout.numColumns++;
}
addSummaryText(composite, toolkit);
+ TaskAttribute userAssignedAttribute = getTaskData().getRoot().getMappedAttribute(TaskAttribute.USER_ASSIGNED);
+ if (userAssignedAttribute != null) {
+ UserAttributeEditor editor = new UserAttributeEditor(getModel(), userAssignedAttribute);
+ editor.createControl(composite, toolkit);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).span(1, 2).applyTo(editor.getControl());
+ layout.marginRight = 1;
+ layout.numColumns++;
+ }
+
if (needsHeader()) {
createHeaderLayout(composite, toolkit);
}
@@ -258,6 +266,7 @@ public class TaskEditorSummaryPart extends AbstractTaskEditorPart {
layout.numColumns = 1;
toolkit.createLabel(headerComposite, " "); //$NON-NLS-1$
}
+
return headerComposite;
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/UserAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/UserAttributeEditor.java
new file mode 100644
index 000000000..b8842f428
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/UserAttributeEditor.java
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.editors;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.ByteArrayInputStream;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.mylyn.commons.identity.Account;
+import org.eclipse.mylyn.commons.identity.IIdentity;
+import org.eclipse.mylyn.commons.identity.IProfileImage;
+import org.eclipse.mylyn.commons.identity.spi.ProfileImage;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
+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.mylyn.tasks.ui.editors.LayoutHint;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * @author Steffen Pingel
+ */
+public class UserAttributeEditor extends AbstractAttributeEditor {
+
+ private static final int IMAGE_SIZE = 48;
+
+ private Label label;
+
+ private IIdentity identity;
+
+ private final PropertyChangeListener imageListener = new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getPropertyName().equals("image")) {
+ final ProfileImage profileImage = (ProfileImage) event.getNewValue();
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ if (!label.isDisposed()) {
+ updateImage(profileImage);
+ }
+ }
+ });
+ }
+ }
+ };
+
+ private Image image;
+
+ public UserAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
+ super(manager, taskAttribute);
+ setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
+ }
+
+ protected Image updateImage(IProfileImage profileImage) {
+ if (image != null) {
+ image.dispose();
+ }
+ ImageData data;
+ if (profileImage != null) {
+ data = new ImageData(new ByteArrayInputStream(profileImage.getData()));
+ if (data.width != IMAGE_SIZE || data.height != IMAGE_SIZE) {
+ data = data.scaledTo(IMAGE_SIZE, IMAGE_SIZE);
+ }
+ } else {
+ data = CommonImages.PERSON_LARGE.getImageData();
+ }
+ Image image = new Image(label.getDisplay(), data);
+ label.setImage(image);
+ return image;
+ }
+
+ @Override
+ public void createControl(Composite parent, FormToolkit toolkit) {
+ label = new Label(parent, SWT.NONE);
+ label.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
+ label.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ if (image != null) {
+ image.dispose();
+ }
+ if (identity != null) {
+ identity.removePropertyChangeListener(imageListener);
+ }
+ }
+ });
+ refresh();
+ toolkit.adapt(label, false, false);
+ setControl(label);
+ }
+
+ public Image getValue() {
+ return image;
+ }
+
+ @Override
+ public void refresh() {
+ if (label.isDisposed()) {
+ return;
+ }
+ if (identity != null) {
+ identity.removePropertyChangeListener(imageListener);
+ }
+ Account account;
+ if (TaskAttribute.TYPE_PERSON.equals(getTaskAttribute().getMetaData().getType())) {
+ IRepositoryPerson person = getTaskAttribute().getTaskData()
+ .getAttributeMapper()
+ .getRepositoryPerson(getTaskAttribute());
+ account = Account.id(person.getPersonId()).name(person.getName());
+ label.setToolTipText(getLabel() + " " + person.toString()); //$NON-NLS-1$
+ } else {
+ account = Account.id(getTaskAttribute().getValue());
+ label.setToolTipText(getDescription());
+ }
+ account = account.kind(getModel().getTaskRepository().getConnectorKind()).url(
+ getModel().getTaskRepository().getRepositoryUrl());
+ identity = TasksUiPlugin.getDefault().getIdentityModel().getIdentity(account);
+ identity.addPropertyChangeListener(imageListener);
+ Future<IProfileImage> result = identity.requestImage(IMAGE_SIZE, IMAGE_SIZE);
+ if (result.isDone()) {
+ try {
+ updateImage(result.get(0, TimeUnit.SECONDS));
+ } catch (Exception e) {
+ // the event listener will eventually update the image
+ updateImage(null);
+ }
+ } else {
+ updateImage(null);
+ }
+ }
+
+}

Back to the top