blob: 573b084922d03028f340ba62ce5cd3015fe6568c (
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
|
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ant.internal.ui.model;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.ant.core.AntSecurityException;
import org.eclipse.ant.internal.core.IAntCoreConstants;
import org.eclipse.ant.internal.ui.AntUIImages;
import org.eclipse.ant.internal.ui.AntUtil;
import org.eclipse.ant.internal.ui.IAntUIConstants;
import org.eclipse.ant.internal.ui.editor.AntEditorCompletionProcessor;
import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.resource.ImageDescriptor;
import org.xml.sax.Attributes;
public class AntImportNode extends AntTaskNode {
private String fFile = null;
public AntImportNode(Task task, Attributes attributes) {
super(task);
fFile = attributes.getValue(IAntCoreConstants.FILE);
}
public String getFile() {
return fFile;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#getBaseImageDescriptor()
*/
@Override
protected ImageDescriptor getBaseImageDescriptor() {
return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_IMPORT);
}
@Override
public String getLabel() {
if (fLabel == null) {
StringBuffer label = new StringBuffer(getTask().getTaskName());
label.append(' ');
label.append(fFile);
if (isExternal()) {
appendEntityName(label);
}
fLabel = label.toString();
}
return fLabel;
}
/**
* Execute the import. Returns <code>true</code> as the import adds to the Ant model
*/
@Override
public boolean configure(boolean validateFully) {
if (fConfigured) {
return false;
}
try {
getTask().maybeConfigure();
getTask().execute();
fConfigured = true;
return true;
}
catch (BuildException be) {
handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_IMPORTS);
}
catch (AntSecurityException se) {
// either a system exit or setting of system property was attempted
handleBuildException(new BuildException(AntModelMessages.AntImportNode_0), AntEditorPreferenceConstants.PROBLEM_SECURITY);
}
return false;
}
@Override
public IFile getIFile() {
IFile file;
if (isExternal()) {
file = AntUtil.getFileForLocation(getFilePath(), null);
} else {
String path = getFile();
file = AntUtil.getFileForLocation(path, getAntModel().getEditedFile().getParentFile());
}
return file;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ant.internal.ui.model.AntElementNode#getReferencedElement(int)
*/
@Override
public String getReferencedElement(int offset) {
if (fFile != null) {
String textToSearch = getAntModel().getText(getOffset(), offset - getOffset());
if (textToSearch != null && textToSearch.length() != 0) {
String attributeString = AntEditorCompletionProcessor.getAttributeStringFromDocumentStringToPrefix(textToSearch);
if (IAntCoreConstants.FILE.equals(attributeString)) {
return fFile;
}
}
}
return null;
}
}
|