Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7d1ec1d890e441f3de9962e002392426a61a6b40 (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
/*******************************************************************************
 * 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 org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.plugin.util.SelectionCountChangeListener;
import org.eclipse.osee.framework.ui.skynet.ArtifactExplorer;
import org.eclipse.osee.framework.ui.skynet.ArtifactImageManager;
import org.eclipse.osee.framework.ui.skynet.OseeContributionItem;
import org.eclipse.osee.framework.ui.skynet.RelationsComposite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.StatusLineContributionItem;

public class ArtifactEditorContributor extends MultiPageEditorActionBarContributor {

	private StatusLineContributionItem typeStatusItem;
	private ShowInExplorerAction showInExplorerAction;

	public ArtifactEditorContributor() {
		super();
		createActions();
	}

	@Override
	public void setActiveEditor(IEditorPart part) {
		super.setActiveEditor(part);
		Artifact artifact = (Artifact) part.getAdapter(Artifact.class);
		if (artifact != null) {
			typeStatusItem.setText(artifact.getArtifactType().getName());
			typeStatusItem.setImage(ArtifactImageManager.getImage(artifact));
			showInExplorerAction.setArtifact(artifact);

			RelationsComposite composite = (RelationsComposite) part.getAdapter(RelationsComposite.class);
			if (composite != null) {
				composite.getTreeViewer().addSelectionChangedListener(
							new SelectionCountChangeListener(this.getActionBars().getStatusLineManager()));
			}
		}
	}

	@Override
	public void setActivePage(IEditorPart part) {
	}

	private void createActions() {
		typeStatusItem = new StatusLineContributionItem("skynet.artifactType", true, 25);
		typeStatusItem.setToolTipText("The type of the artifact being edited.");

		showInExplorerAction = new ShowInExplorerAction();
	}

	@Override
	public void contributeToStatusLine(IStatusLineManager statusLineManager) {
		statusLineManager.add(typeStatusItem);
		OseeContributionItem.addTo(statusLineManager);
	}

	@Override
	public void contributeToCoolBar(ICoolBarManager coolBarManager) {
		coolBarManager.add(showInExplorerAction);
	}

	private static class ShowInExplorerAction extends Action {
		private Artifact artifact;

		public ShowInExplorerAction() {
			setText("Show in Artifact Explorer");
			setToolTipText("Show the Artifact being edited in the Artifact Explorer");
		}

		public void setArtifact(Artifact artifact) {
			this.artifact = artifact;
		}

		@Override
		public void run() {
			ArtifactExplorer.revealArtifact(artifact);
		}
	}
}

Back to the top