blob: ac0c3a33a555c2902debb1a581a214efe61fb553 (
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
|
/*****************************************************************************
* Copyright (c) 2014 CEA LIST.
*
*
* 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:
* Benoit Maggi benoit.maggi@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.onefile.internal.ui.testers;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.part.ResourceTransfer;
/**
* Papyrus tester on clipboard contents
* containsPapyrusModel : test if there is a papyrus model
*/
public class PapyrusClipboardTester extends PropertyTester {
public static final String CLIPBOARD_CONTAINS_PAPYRUS_MODEL = "containsPapyrusModel"; //$NON-NLS-1$
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver instanceof org.eclipse.swt.widgets.Shell) {
Clipboard clipboard = new Clipboard(Display.getDefault());
if (CLIPBOARD_CONTAINS_PAPYRUS_MODEL.equals(property)) {
boolean answer = containsPapyrusModel(clipboard);
return new Boolean(answer).equals(expectedValue);
}
}
return false;
}
/**
* Test if the clipboard contains some Papyrus model (that is with a di extension)
*
* @param clipboard
* @return
*/
protected boolean containsPapyrusModel(Clipboard clipboard) {
if (clipboard != null) {
String[] filePaths = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (filePaths != null) {
if (filePaths.length > 0) {
for (int i = 0; i < filePaths.length; i++) {
if (filePaths[i].endsWith("." + DiModel.MODEL_FILE_EXTENSION)) { //$NON-NLS-1$
return true;
}
}
}
} else {
IResource[] resources = (IResource[]) clipboard.getContents(ResourceTransfer.getInstance());
if (resources != null) {
if (resources.length > 0) {
for (int i = 0; i < resources.length; i++) {
if (DiModel.MODEL_FILE_EXTENSION.equals(resources[i].getFileExtension())) {
return true;
}
}
}
}
}
}
return false;
}
}
|