blob: 2ef74e0df9d70244f9beac90a050d938ba330677 (
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
|
/*******************************************************************************
* 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.commandHandlers;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.internal.ServiceUtil;
import org.eclipse.osee.framework.ui.skynet.util.ArtifactClipboard;
import org.eclipse.search.ui.text.Match;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.part.ViewPart;
/**
* @author Jeff C. Phillips
*/
public class CopyHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (HandlerUtil.getActivePartChecked(event) instanceof ViewPart) {
ViewPart view = (ViewPart) HandlerUtil.getActivePartChecked(event);
IWorkbenchPartSite myIWorkbenchPartSite = view.getSite();
ISelectionProvider selectionProvider = myIWorkbenchPartSite.getSelectionProvider();
if (selectionProvider != null && selectionProvider.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection();
List<String> names = new LinkedList<String>();
List<Artifact> artifacts = new LinkedList<Artifact>();
ArtifactClipboard clipboard = new ArtifactClipboard(view.getSite().getId());
Iterator<?> iterator = selection.iterator();
Object selectionObject = null;
try {
while (iterator.hasNext()) {
Object object = iterator.next();
if (object instanceof IAdaptable) {
selectionObject = ((IAdaptable) object).getAdapter(Branch.class);
if (selectionObject == null) {
selectionObject = ((IAdaptable) object).getAdapter(Artifact.class);
}
} else if (object instanceof Match) {
selectionObject = ((Match) object).getElement();
}
if (selectionObject instanceof IOseeBranch) {
names.add(((IOseeBranch) selectionObject).getName());
} else if (selectionObject instanceof Artifact) {
Artifact artifact = (Artifact) selectionObject;
names.add(artifact.getName());
artifacts.add(artifact);
}
}
if (!names.isEmpty() && artifacts.isEmpty()) {
clipboard.setTextToClipboard(names);
} else if (!names.isEmpty() && !artifacts.isEmpty()) {
try {
clipboard.setArtifactsToClipboard(ServiceUtil.getAccessPolicy(), artifacts);
} catch (OseeCoreException ex) {
clipboard.dispose();
throw new ExecutionException(ex.getLocalizedMessage());
}
}
} finally {
clipboard.dispose();
}
}
}
return null;
}
@Override
public boolean isHandled() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}
|