blob: 2c9080372d14a253562a638d5dd365696061313c (
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
|
/*******************************************************************************
* 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.doors.connector.ui.viewer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
import org.eclipse.osee.doors.connector.core.Requirement;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.skynet.core.utility.JsonArtifactRepresentation;
import org.eclipse.osee.framework.skynet.core.utility.JsonAttributeRepresentation;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Control;
/**
* @author David W. Miller
*/
public class RdfExplorerDragAndDrop {
private DragSource dragSource;
private final List<Requirement> reqs = new ArrayList<Requirement>();
public RdfExplorerDragAndDrop(Control source) {
if (source != null) {
dragSource = new DragSource(source, DND.DROP_MOVE | DND.DROP_COPY);
setupDragSupport();
}
}
private void setupDragSupport() {
dragSource.setTransfer(new Transfer[] {TextTransfer.getInstance()});
dragSource.addDragListener(new DragSourceListener() {
@Override
public void dragFinished(DragSourceEvent event) {
// do nothing
}
@Override
public void dragSetData(DragSourceEvent event) {
performDataTransafer(event);
}
@Override
public void dragStart(DragSourceEvent event) {
// do nothing
}
});
}
private void performDataTransafer(DragSourceEvent event) {
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
textTransferDragSetData(event);
}
}
public void textTransferDragSetData(DragSourceEvent event) {
List<JsonArtifactRepresentation> reqsOut = new ArrayList<JsonArtifactRepresentation>();
for (Requirement reqt : reqs) {
reqsOut.add(makeJsonArtifactRepresentation(reqt));
}
ObjectMapper mapper = new ObjectMapper();
try {
event.data = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(reqsOut);
} catch (IOException ex) {
//
}
}
private JsonArtifactRepresentation makeJsonArtifactRepresentation(Requirement reqt) {
JsonArtifactRepresentation artRep = new JsonArtifactRepresentation();
artRep.setArtifactTypeId(CoreArtifactTypes.Url.getId());
artRep.setName(reqt.getShortName());
List<JsonAttributeRepresentation> attrs = new ArrayList<JsonAttributeRepresentation>();
attrs.add(new JsonAttributeRepresentation(CoreAttributeTypes.Description.getId(), reqt.getName()));
attrs.add(new JsonAttributeRepresentation(CoreAttributeTypes.ContentUrl.getId(), reqt.getPath()));
artRep.setAttrs(attrs);
return artRep;
}
public void clearRequirements() {
if (reqs.size() > 0) {
reqs.clear();
}
}
public void addRequirement(Requirement req) {
reqs.add(req);
}
public void performDragOver(DropTargetEvent event) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND;
event.detail = DND.DROP_NONE;
}
}
|