Skip to main content
summaryrefslogtreecommitdiffstats
blob: a543bf2c1b041b1360549a8a86c2e55defbbf9b7 (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/

package org.eclipse.osee.framework.ui.skynet.artifact.editor;

import java.util.logging.Level;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.plugin.core.IActionable;
import org.eclipse.osee.framework.plugin.core.util.Jobs;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.OseeContributionItem;
import org.eclipse.osee.framework.ui.skynet.RelationsComposite;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.osee.framework.ui.skynet.artifact.editor.pages.ArtifactEditorOutlinePage;
import org.eclipse.osee.framework.ui.skynet.artifact.editor.pages.ArtifactFormPage;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.Widgets;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

/**
 * @author Roberto E. Escobar
 */
public class ArtifactEditor extends AbstractEventArtifactEditor {
	public static final String EDITOR_ID = "org.eclipse.osee.framework.ui.skynet.artifact.editor.ArtifactEditor";

	private IActionContributor actionBarContributor;
	private ArtifactFormPage formPage;
	private ArtifactEditorOutlinePage outlinePage;

	public ArtifactEditor() {
		super();
	}

	public IActionContributor getActionBarContributor() {
		if (actionBarContributor == null) {
			actionBarContributor = new ArtifactEditorActionBarContributor(this);
		}
		return actionBarContributor;
	}

	@Override
	public BaseArtifactEditorInput getEditorInput() {
		return (BaseArtifactEditorInput) super.getEditorInput();
	}

	@Override
	public void onDirtied() {
		Displays.ensureInDisplayThread(new Runnable() {
			@Override
			public void run() {
				firePropertyChange(PROP_DIRTY);
			}
		});
	}

	@Override
	public void showBusy(boolean busy) {
		super.showBusy(busy);
		ArtifactFormPage page = getFormPage();
		if (page != null) {
			page.showBusy(busy);
		}
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		try {
			getFormPage().doSave(monitor);
			Artifact artifact = getEditorInput().getArtifact();
			artifact.persist();
			firePropertyChange(PROP_DIRTY);
		} catch (OseeCoreException ex) {
			onDirtied();
			OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
		}
	}

	@Override
	public void dispose() {
		try {
			// If the artifact is dirty when the editor gets disposed, then it needs to be reverted
			Artifact artifact = getEditorInput().getArtifact();
			if (!artifact.isDeleted() && artifact.isDirty()) {
				try {
					artifact.reloadAttributesAndRelations();
				} catch (OseeCoreException ex) {
					OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
				}
			}
		} catch (Exception ex) {
			OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
		} finally {
			super.dispose();
		}
	}

	@Override
	protected void checkEnabledTooltems() {
		//      if (!attributeComposite.isDisposed()) {
		//        				Displays.ensureInDisplayThread(new Runnable() {
		//		@Override
		//		public void run() {
		//               boolean isEditAllowed = artifact.isReadOnly() != true;
		//
		//               if (attributeComposite.getToolBar() == null || attributeComposite.getToolBar().isDisposed()) {
		//                  return;
		//               }
		//               attributeComposite.getToolBar().getItem(REVEAL_ARTIFACT_INDEX).setEnabled(true);
		//               attributeComposite.getToolBar().getItem(EDIT_ARTIFACT_INDEX).setEnabled(isEditAllowed);
		//               attributeComposite.getToolBar().update();
		//
		//               relationsComposite.getToolBar().getItem(REVEAL_ARTIFACT_INDEX).setEnabled(true);
		//               relationsComposite.getToolBar().getItem(EDIT_ARTIFACT_INDEX).setEnabled(isEditAllowed);
		//               relationsComposite.getToolBar().update();
		//            }
		//         });
		//      }
	}

	@Override
	public void closeEditor() {
		Displays.ensureInDisplayThread(new Runnable() {
			@Override
			public void run() {
				AWorkbench.getActivePage().closeEditor(ArtifactEditor.this, false);
			}
		});
	}

	@Override
	public void refreshDirtyArtifact() {
		Jobs.startJob(new RefreshDirtyArtifactJob());
	}

	@Override
	public void refreshRelations() {
		Jobs.startJob(new RefreshRelations());
	}

	@Override
	protected void addPages() {
		OseeContributionItem.addTo(this, true);
		setPartName(getEditorInput().getName());
		setTitleImage(getEditorInput().getImage());

		formPage = new ArtifactFormPage(this, "ArtifactFormPage", null);
		try {
			addPage(formPage);
		} catch (PartInitException ex) {
			OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
		}
	}

	private ArtifactFormPage getFormPage() {
		return formPage;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Object getAdapter(Class adapter) {
		if (adapter == IActionable.class) {
			return new IActionable() {
				@Override
				public String getActionDescription() {
					return "";
				}
			};
		} else if (adapter == IContentOutlinePage.class) {
			ArtifactEditorOutlinePage page = getOutlinePage();
			page.setInput(this);
			return page;
		} else if (adapter == RelationsComposite.class) {
			return getFormPage().getRelationsComposite();
		}
		return super.getAdapter(adapter);
	}

	protected ArtifactEditorOutlinePage getOutlinePage() {
		if (outlinePage == null) {
			outlinePage = new ArtifactEditorOutlinePage();
		}
		return outlinePage;
	}

	private final class RefreshRelations extends UIJob {
		public RefreshRelations() {
			super("Refresh Relations");
		}

		@Override
		public IStatus runInUIThread(IProgressMonitor monitor) {
			ArtifactFormPage page = getFormPage();
			if (page != null) {
				page.showBusy(true);
				RelationsComposite relationsComposite = page.getRelationsComposite();
				if (relationsComposite != null && !relationsComposite.isDisposed()) {
					relationsComposite.refresh();
					onDirtied();
				}
				page.showBusy(false);
			}
			return Status.OK_STATUS;
		}
	}

	private final class RefreshDirtyArtifactJob extends UIJob {

		public RefreshDirtyArtifactJob() {
			super("Refresh Dirty Artifact");
		}

		@Override
		public IStatus runInUIThread(IProgressMonitor monitor) {
			try {
				setPartName(getEditorInput().getName());
				setTitleImage(getEditorInput().getImage());
				ArtifactEditorOutlinePage outlinePage = getOutlinePage();
				if (outlinePage != null) {
					outlinePage.refresh();
				}
				ArtifactFormPage page = getFormPage();
				if (page != null && Widgets.isAccessible(page.getPartControl())) {
					page.refresh();
				}
				onDirtied();
			} catch (Exception ex) {
				OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
			}
			return Status.OK_STATUS;
		}
	}

	@Override
	public boolean isDisposed() {
		return formPage == null || formPage.getPartControl() == null || formPage.getPartControl().isDisposed();
	}
}

Back to the top