Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab2040630f28a55f578d6bddf05936fdbfbc4dc4 (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
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.internal.trac.ui.wizard;

import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.mylar.internal.trac.core.ITracClient;
import org.eclipse.mylar.internal.trac.core.TracCorePlugin;
import org.eclipse.mylar.internal.trac.core.TracException;
import org.eclipse.mylar.internal.trac.core.TracOfflineTaskHandler;
import org.eclipse.mylar.internal.trac.core.TracRepositoryConnector;
import org.eclipse.mylar.internal.trac.ui.TracUiPlugin;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

/**
 * Wizard page for creating new Trac tickets through a rich editor.
 * 
 * @author Steffen Pingel
 */
public class NewTracTaskPage extends WizardPage {

	// private boolean firstTime;

	private TaskRepository taskRepository;

	private RepositoryTaskData taskData;

	public NewTracTaskPage(TaskRepository taskRepository) {
		super("New Task");

		setTitle("Create via Rich Editor");
		setDescription("This will open an editor that can be used to create a new task.");

		this.taskRepository = taskRepository;
	}

	public void createControl(Composite parent) {
		Text text = new Text(parent, SWT.WRAP);
		text.setEditable(false);
		setControl(text);
	}

	@Override
	public void setVisible(boolean visible) {
		super.setVisible(visible);

		// if (visible && firstTime) {
		// firstTime = false;
		// if (!hasAttributes()) {
		// // delay the execution so the dialog's progress bar is visible
		// // when the attributes are updated
		// Display.getDefault().asyncExec(new Runnable() {
		// public void run() {
		// if (getControl() != null && !getControl().isDisposed()) {
		// updateAttributesFromRepository();
		// }
		// }
		// });
		// }
		// }
		updateAttributesFromRepository();
	}

	// private boolean hasAttributes() {
	// TracRepositoryConnector connector = (TracRepositoryConnector)
	// TasksUiPlugin.getRepositoryManager()
	// .getRepositoryConnector(TracCorePlugin.REPOSITORY_KIND);
	// try {
	// ITracClient client =
	// connector.getClientManager().getRepository(taskRepository);
	// return client.hasAttributes();
	// } catch (MalformedURLException e) {
	// return false;
	// }
	// }

	@Override
	public boolean isPageComplete() {
		return taskData != null;
	}

	private void updateAttributesFromRepository() {
		TracRepositoryConnector connector = (TracRepositoryConnector) TasksUiPlugin.getRepositoryManager()
				.getRepositoryConnector(TracCorePlugin.REPOSITORY_KIND);
		final ITracClient client;
		try {
			client = connector.getClientManager().getRepository(taskRepository);
		} catch (MalformedURLException e) {
			TracUiPlugin.handleTracException(e);
			return;
		}

		if (!client.hasAttributes()) {
			try {
				IRunnableWithProgress runnable = new IRunnableWithProgress() {
					public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
						try {
							client.updateAttributes(monitor, true);
						} catch (TracException e) {
							throw new InvocationTargetException(e);
						}
					}
				};

				getContainer().run(true, true, runnable);
			} catch (InvocationTargetException e) {
				TracUiPlugin.handleTracException(e.getCause());
				return;
			} catch (InterruptedException e) {
				return;
			}
		}

		TracOfflineTaskHandler offlineHandler = (TracOfflineTaskHandler) connector.getTaskDataHandler();
		this.taskData = new RepositoryTaskData(offlineHandler.getAttributeFactory(), TracCorePlugin.REPOSITORY_KIND,
				taskRepository.getUrl(), TasksUiPlugin.getDefault().getNextNewRepositoryTaskId());
		TracOfflineTaskHandler.createDefaultAttributes(offlineHandler.getAttributeFactory(), taskData, client, false);
	}

	public RepositoryTaskData getRepositoryTaskData() {
		return taskData;
	}

}

Back to the top