1 11 12 package org.eclipse.ant.internal.ui.model; 13 14 import org.apache.tools.ant.BuildException; 15 import org.apache.tools.ant.Task; 16 import org.eclipse.ant.core.AntSecurityException; 17 import org.eclipse.ant.internal.ui.AntUIImages; 18 import org.eclipse.ant.internal.ui.AntUtil; 19 import org.eclipse.ant.internal.ui.IAntUIConstants; 20 import org.eclipse.ant.internal.ui.editor.AntEditorCompletionProcessor; 21 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 22 import org.eclipse.core.resources.IFile; 23 import org.eclipse.jface.resource.ImageDescriptor; 24 import org.xml.sax.Attributes ; 25 26 public class AntImportNode extends AntTaskNode { 27 28 private String fFile= null; 29 30 public AntImportNode(Task task, Attributes attributes) { 31 super(task); 32 fFile= attributes.getValue(IAntModelConstants.ATTR_FILE); 33 } 34 35 public String getFile() { 36 return fFile; 37 } 38 39 42 protected ImageDescriptor getBaseImageDescriptor() { 43 return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_IMPORT); 44 } 45 46 public String getLabel() { 47 if (fLabel == null) { 48 StringBuffer label= new StringBuffer (getTask().getTaskName()); 49 label.append(' '); 50 label.append(fFile); 51 52 if (isExternal()) { 53 appendEntityName(label); 54 } 55 fLabel= label.toString(); 56 } 57 return fLabel; 58 } 59 60 64 public boolean configure(boolean validateFully) { 65 if (fConfigured) { 66 return false; 67 } 68 try { 69 getTask().maybeConfigure(); 70 getTask().execute(); 71 fConfigured= true; 72 return true; 73 } catch (BuildException be) { 74 handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_IMPORTS); 75 } catch (AntSecurityException se) { 76 handleBuildException(new BuildException(AntModelMessages.AntImportNode_0), AntEditorPreferenceConstants.PROBLEM_SECURITY); 78 } 79 return false; 80 } 81 82 public IFile getIFile() { 83 IFile file; 84 if (isExternal()) { 85 file= AntUtil.getFileForLocation(getFilePath(), null); 86 } else { 87 String path= getFile(); 88 file= AntUtil.getFileForLocation(path, getAntModel().getEditedFile().getParentFile()); 89 } 90 return file; 91 } 92 93 96 public String getReferencedElement(int offset) { 97 if (fFile != null) { 98 String textToSearch= getAntModel().getText(getOffset(), offset - getOffset()); 99 if (textToSearch != null && textToSearch.length() != 0) { 100 String attributeString = AntEditorCompletionProcessor.getAttributeStringFromDocumentStringToPrefix(textToSearch); 101 if (IAntModelConstants.ATTR_FILE.equals(attributeString)) { 102 return fFile; 103 } 104 } 105 } 106 return null; 107 } 108 } 109 | Popular Tags |