public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) { if (p == null) { IFile f = EclipseResourceUtil.getFile(jarFile); if (f == null) return null; p = f.getProject(); } if (p == null) return null; IModelNature n = EclipseResourceUtil.getModelNature(p); XModel model = null; if (n != null) { model = n.getModel(); } else { XModelObject o = EclipseResourceUtil.createObjectForResource(p); if (o != null) model = o.getModel(); } if (model == null) return null; XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren(); for (XModelObject s : fs) { String loc = Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties()); if (new File(loc).equals(new File(jarFile))) { XModelObject result = s.getChildByPath(entry); if (result == null && entry != null) { int q = entry.indexOf('/'); int d = entry.indexOf('.'); if (q > d && d >= 0) { String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q); result = s.getChildByPath(entry1); } } if (result != null) return result; } } return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$ }
public void synchronize() { XModelObject o = getXModelObject(); IFile f1 = super.getFile(); if (o == null || o.getPath() == null) return; IFile f2 = getFileByObject(o); if (!f1.equals(f2) && f2 != null) hackSetFile(f2); }
public boolean isFileChanged() { XModelObject o = getXModelObject(); IFile f1 = super.getFile(); if (o == null || o.getPath() == null) return false; IFile f2 = getFileByObject(o); return !f1.equals(f2); }
public void revalidate() { IFile f = getFile(); if (f == null || f.equals(super.getFile())) return; try { Field field = FileEditorInput.class.getDeclaredField("file"); // $NON-NLS-1$ field.setAccessible(true); field.set(this, f); } catch (NoSuchFieldException e) { ModelUIPlugin.getPluginLog().logError(e); } catch (IllegalArgumentException e) { ModelUIPlugin.getPluginLog().logError(e); } catch (IllegalAccessException e) { ModelUIPlugin.getPluginLog().logError(e); } }
private static IEditorInput convertFileInput(IFileEditorInput input) { IFileEditorInput fi = (IFileEditorInput) input; IFile f = fi.getFile(); if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) { try { f.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // ignore } } XModelObject o = EclipseResourceUtil.getObjectByResource(f); if (o == null) { o = EclipseResourceUtil.createObjectForResource(f); } return (o == null || o.getFileType() != XModelObject.FILE) ? input : new XModelObjectEditorInput(getMainObject(o)); }
public boolean equals(Object o) { getXModelObject(); if (this == o) return true; if (o instanceof FileEditorInput) { if (getFile() == null) return false; FileEditorInput other = (FileEditorInput) o; IFile f1 = getFile(); IFile f2 = other.getFile(); if (f1 == null || f2 == null) return f1 == f2; if (f1.equals(f2)) return true; IPath loc1 = f1.getLocation(); IPath loc2 = f2.getLocation(); if (loc1 == null || loc2 == null) return loc1 == loc2; return loc1.equals(loc2); } if (o instanceof XModelObjectEditorInput) { return object.equals(((XModelObjectEditorInput) o).getXModelObject()); } return false; }
public boolean exists() { IFile f = getFile(); return f != null && f.exists(); }
public String getToolTipText() { IFile f = (IFile) EclipseResourceUtil.getResource(object); if (f != null && f.exists()) return f.getLocation().toString(); return object.getPresentationString(); }