Skip to main content
summaryrefslogtreecommitdiffstats
blob: c174c9af7ad408e05b260d377582609ff5f6ce45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.releng.tasks.table;

import org.eclipse.emf.cdo.releng.tasks.Activator;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.ITaskDataManager;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Eike Stepper
 */
@SuppressWarnings("restriction")
public class TaskModel
{
  private static final String QUERY_IDENTIFIER = "TaskTable";

  private org.eclipse.mylyn.internal.tasks.core.ITaskList taskList;

  private ITaskDataManager taskDataManager;

  private org.eclipse.mylyn.internal.tasks.core.RepositoryQuery query;

  private LogicalTask[] logicalTasks;

  private Version[] versions;

  // private ITaskListChangeListener taskListListener = new ITaskListChangeListener()
  // {
  // public void containersChanged(Set<TaskContainerDelta> deltas)
  // {
  // for (TaskContainerDelta delta : deltas)
  // {
  // IRepositoryElement element = delta.getElement();
  // if (element instanceof ITask && query.contains(element.getHandleIdentifier()))
  // {
  // refresh();
  // fireEvent(new Event(TaskModel.this));
  // break;
  //
  // // ITask task = (ITask)element;
  // // Kind kind = delta.getKind();
  // // System.out.println(kind + ": " + task);
  // //
  // // switch (kind)
  // // {
  // // case ADDED:
  // // taskAdded(task);
  // // break;
  // //
  // // case REMOVED:
  // // case DELETED:
  // // taskRemoved(task);
  // // break;
  // //
  // // case CONTENT:
  // // taskChanged(task);
  // // break;
  // //
  // // case ROOT:
  // // break;
  // // }
  // }
  // }
  // }
  //
  // private synchronized void taskAdded(ITask task)
  // {
  // // logicalTasks.put(task, new LogicalTask(task));
  // }
  //
  // private synchronized void taskRemoved(ITask task)
  // {
  // }
  //
  // private synchronized void taskChanged(ITask task)
  // {
  // }
  // };

  public TaskModel()
  {
    taskDataManager = org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin.getTaskDataManager();
    taskList = org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin.getTaskList();
    query = getQuery();
    refresh();
    // taskList.addChangeListener(taskListListener);
  }

  public void dispose()
  {
    // taskList.removeChangeListener(taskListListener);
  }

  public org.eclipse.mylyn.internal.tasks.core.ITaskList getTaskList()
  {
    return taskList;
  }

  public ITaskDataManager getTaskDataManager()
  {
    return taskDataManager;
  }

  public Version[] getVersions()
  {
    return versions;
  }

  public LogicalTask[] getLogicalTasks()
  {
    return logicalTasks;
  }

  public void refresh()
  {
    Map<String, LogicalTask> logicalTasks = new HashMap<String, LogicalTask>();
    Map<Version, Version> versions = new HashMap<Version, Version>();

    for (ITask task : query.getChildren())
    {
      // Activator.getDefault().getLog().log(
      // new Status(IStatus.INFO, Activator.PLUGIN_ID, "Processing task " + task.getTaskId()));

      LogicalTask logicalTask = null;
      VersionTask versionTask = null;

      try
      {
        String summary = task.getSummary();
        logicalTask = logicalTasks.get(summary);
        if (logicalTask == null)
        {
          logicalTask = new LogicalTask(this, summary);
          logicalTasks.put(summary, logicalTask);
        }

        TaskData taskData = taskDataManager.getTaskData(task);
        TaskAttributeMapper attributeMapper = taskData.getAttributeMapper();
        TaskAttribute root = taskData.getRoot();

        TaskAttribute versionAttribute = root.getMappedAttribute(TaskAttribute.VERSION);
        String versionStr = attributeMapper.getValue(versionAttribute);
        Version version = Version.getVersion(versionStr);

        Version existingVersion = versions.get(version);
        if (existingVersion == null)
        {
          versions.put(version, version);
        }
        else
        {
          version = existingVersion;
        }

        TaskAttribute severityAttribute = root.getMappedAttribute(TaskAttribute.SEVERITY);
        String severity = attributeMapper.getValue(severityAttribute);

        TaskAttribute statusAttribute = root.getMappedAttribute(TaskAttribute.STATUS);
        String status = attributeMapper.getValue(statusAttribute);

        TaskAttribute resolutionAttribute = root.getMappedAttribute(TaskAttribute.RESOLUTION);
        String resolution = attributeMapper.getValue(resolutionAttribute);

        versionTask = new VersionTask(logicalTask, task, version, severity, status, resolution);
        logicalTask.getVersionTasks().add(versionTask);

        Activator.getDefault().getLog()
            .log(new Status(IStatus.INFO, Activator.PLUGIN_ID, "Version " + version + " added to task " + logicalTask));
      }
      catch (Exception ex)
      {
        Activator.getDefault().getLog()
            .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Processing task " + task.getTaskId() + " failed", ex));
        ex.printStackTrace();

        // Cleanup
        if (versionTask != null)
        {
          if (logicalTask.getVersionTasks().remove(versionTask))
          {
            if (logicalTask.getVersionTasks().isEmpty())
            {
              logicalTasks.remove(logicalTask.getSummary());
            }
          }
        }
      }
    }

    this.logicalTasks = logicalTasks.values().toArray(new LogicalTask[logicalTasks.size()]);
    Arrays.sort(this.logicalTasks);

    this.versions = versions.keySet().toArray(new Version[versions.size()]);
    Arrays.sort(this.versions);
  }

  private org.eclipse.mylyn.internal.tasks.core.RepositoryQuery getQuery()
  {
    for (org.eclipse.mylyn.internal.tasks.core.RepositoryQuery query : taskList.getQueries())
    {
      String identifier = query.getSummary();
      if (QUERY_IDENTIFIER.equals(identifier))
      {
        return query;
      }
    }

    throw new IllegalStateException("Query 'TaskTable' is missing");
  }
}

Back to the top