public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath, IProgressMonitor monitor) { try { if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) { return; } if (!Objects.equals(fragment.getSourceAttachmentPath(), newSourcePath)) { // would be so cool if it refreshed the UI automatically fragment.attachSource(newSourcePath, null, monitor); // close the root so that source attachment cache is flushed. Else UI // won't update fragment.close(); // we have to manually fire a delta to notify the UI about the source // attachment. JavaModelManager manager = JavaModelManager.getJavaModelManager(); JavaElementDelta attachedSourceDelta = new JavaElementDelta(fragment.getJavaModel()); attachedSourceDelta.sourceAttached(fragment); manager.getDeltaProcessor().fire(attachedSourceDelta, ElementChangedEvent.POST_CHANGE); } } catch (CoreException e) { // ignore } }
private void firePostChangeDelta( IJavaElementDelta deltaToNotify, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { // post change deltas if (DEBUG) { System.out.println( "FIRING POST_CHANGE Delta [" + Thread.currentThread() + "]:"); // $NON-NLS-1$//$NON-NLS-2$ System.out.println( deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); // $NON-NLS-1$ } if (deltaToNotify != null) { // flush now so as to keep listener reactions to post their own deltas for subsequent // iteration flush(); // // mark the operation stack has not modifying resources since resource deltas are being // fired // JavaModelOperation.setAttribute(JavaModelOperation.HAS_MODIFIED_RESOURCE_ATTR, null); notifyListeners( deltaToNotify, ElementChangedEvent.POST_CHANGE, listeners, listenerMask, listenerCount); } }
private void fireReconcileDelta( IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { IJavaElementDelta deltaToNotify = mergeDeltas(this.reconcileDeltas.values()); if (DEBUG) { System.out.println( "FIRING POST_RECONCILE Delta [" + Thread.currentThread() + "]:"); // $NON-NLS-1$//$NON-NLS-2$ System.out.println( deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); // $NON-NLS-1$ } if (deltaToNotify != null) { // flush now so as to keep listener reactions to post their own deltas for subsequent // iteration this.reconcileDeltas = new HashMap(); notifyListeners( deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount); } }
protected void init(IJavaProject project) { if (project == null || !project.exists() || !project.getResource().isAccessible()) throw new IllegalArgumentException("Invalid javaProject"); this.javaProject = project; getURLClassloader(); listener = new IElementChangedListener() { public void elementChanged(final ElementChangedEvent event) { if (ignoreClasspathChanges(event)) return; System.out.println("CLASSPATH CHANGED:" + event); // FIXME should release this classloader // what happend with current objects? we have 1 loader per // project, maybe se can filter some events? to have less // updates curlLoader = null; getURLClassloader(); if (events != null) events.firePropertyChange("classpath", false, true); } }; JavaCore.addElementChangedListener(listener, ElementChangedEvent.POST_CHANGE); }
private boolean ignoreClasspathChanges(ElementChangedEvent event) { if (event.getDelta() == null && event.getDelta().getChangedChildren() == null) return true; for (IJavaElementDelta delta : event.getDelta().getChangedChildren()) { if (delta.getResourceDeltas() == null) return false; for (IResourceDelta rd : delta.getResourceDeltas()) { if (rd.getFullPath() == null) continue; String path = rd.getFullPath().getFileExtension(); if (path != null && !(path.equalsIgnoreCase(FileExtension.JRXML) || path.equalsIgnoreCase(FileExtension.JASPER))) return false; } } return true; }
/** * {@inheritDoc} */ public void elementChanged(ElementChangedEvent event) { IWorkingSet[] workingSets; synchronized(fWorkingSets) { workingSets= fWorkingSets.toArray(new IWorkingSet[fWorkingSets.size()]); } for (int w= 0; w < workingSets.length; w++) { WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]); processJavaDelta(workingSetDelta, event.getDelta()); IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas(); if (resourceDeltas != null) { for (int r= 0; r < resourceDeltas.length; r++) { processResourceDelta(workingSetDelta, resourceDeltas[r]); } } workingSetDelta.process(); } }
public static void fire(final ElementChangedEvent extraEvent) { for (int i = 0; i < elementChangedListenerCount; i++) { if ((elementChangedListenerMasks[i] & extraEvent.getType()) != 0) { final IElementChangedListener listener = elementChangedListeners[i]; // wrap callbacks with Safe runnable for subsequent listeners to // be called when some are causing grief SafeRunner.run(new ISafeRunnable() { @Override public void handleException(Throwable exception) { // Util.log(exception, "Exception occurred in listener // of Java element change notification"); //$NON-NLS-1$ } @Override public void run() throws Exception { listener.elementChanged(extraEvent); } }); } } }
@Override public void elementChanged(ElementChangedEvent event) { final IJavaProject javaProject = getCachedJavaProject(); if (javaProject == null) { return; } final IJavaElementDelta[] children = event.getDelta().getChangedChildren(); for (int i = 0; i < children.length; i++) { final IJavaElementDelta child = children[i]; if (javaProject.equals(child.getElement())) { if (isClasspathChange(child)) { setCachedJavaProject(null); } } } }
@Override public void start(BundleContext context) throws Exception { instance = this; detectionJob = new WildlfySwarmDetectionJob(); classpathChangeListener = new ClasspathChangeListener(detectionJob); JavaCore.addElementChangedListener(classpathChangeListener, ElementChangedEvent.POST_CHANGE); }
public void elementChanged(ElementChangedEvent event) { if (event.getDelta() != null) { if (isAffectingPackageFragmentRoots(event.getDelta())) { initialize(); } } }
public void elementChanged(ElementChangedEvent event) { // long t0= System.currentTimeMillis(); IJavaElementDelta delta = event.getDelta(); Set<IAdaptable> removedElements = new HashSet<IAdaptable>(); Set<IAdaptable> potentiallyRemovedElements = new HashSet<IAdaptable>(); collectRemoved(potentiallyRemovedElements, removedElements, delta); if (removedElements.size() > 0) handleRemoved(removedElements); if (potentiallyRemovedElements.size() > 0) handleRemoved(potentiallyRemovedElements); // System.out.println(this+"handled delta in: "+(System.currentTimeMillis()-t0)); }
public void elementChanged(ElementChangedEvent event) { for (IJavaElementDelta delta : event.getDelta().getChangedChildren()) { int flags = delta.getFlags(); if ((flags & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) { IJavaElement element = delta.getElement(); if (element.getElementType() != IJavaElement.JAVA_PROJECT) { continue; } classpathChanged((IJavaProject) element); } } }
public void elementChanged(ElementChangedEvent event) { final Map<IJavaElement, IJavaElementDelta> changedElements = new HashMap<IJavaElement, IJavaElementDelta>(); JavaModelSearch.visitJavaElementDelta(event.getDelta(), new IJavaElementDeltaVisitor() { public boolean visit(IJavaElementDelta delta) { IJavaElement element = delta.getElement(); /* * We care about packages being only added or removed because if we * called the change listeners on a change to a package, any change * to any file in that package will cause all ui.xml files that * reference that package (say with xmlns urn imports) to be * revalidated. Some projects end up having hundreds of ui.xml files * referencing a package, and then saving any change in that package * ends up taking tens of seconds. */ int type = element.getElementType(); if (type == IJavaElement.PACKAGE_FRAGMENT && delta.getKind() == IJavaElementDelta.CHANGED) { return true; } Set<IReference> references = referenceManager.getReferencesWithMatchingJavaElement( element, EnumSet.of(ReferenceLocationType.TARGET)); if (references != null && references.size() > 0) { changedElements.put(element, delta); } return true; } }); if (changedElements.size() > 0) { callReferenceChangeListeners(changedElements); } }
public void elementChanged(ElementChangedEvent e) { IJavaElementDelta delta= findElement(fInput, e.getDelta()); if (delta != null && (delta.getFlags() & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_CHILDREN)) != 0) { if (shouldIgnoreDelta(e.getDelta().getCompilationUnitAST(), delta)) return; fUpdatingCount++; try { update(createContext(false)); } finally { fUpdatingCount--; } } }
public void elementChanged(final ElementChangedEvent event) { try { processDelta(event.getDelta()); } catch(JavaModelException e) { JavaPlugin.log(e); } }
public void elementChanged(final ElementChangedEvent event) { final ArrayList<Runnable> runnables= new ArrayList<Runnable>(); try { // 58952 delete project does not update Package Explorer [package explorer] // if the input to the viewer is deleted then refresh to avoid the display of stale elements if (inputDeleted(runnables)) return; processDelta(event.getDelta(), runnables); } catch (JavaModelException e) { JavaPlugin.log(e); } finally { executeRunnables(runnables); } }
/** * {@inheritDoc} */ public void elementChanged(ElementChangedEvent event) { List<IJavaElement> changed= new ArrayList<IJavaElement>(); processDelta(event.getDelta(), changed); if (changed.size() == 0) return; fireChange(changed.toArray(new IJavaElement[changed.size()])); }
public void elementChanged(ElementChangedEvent event) { //long t0= System.currentTimeMillis(); IJavaElementDelta delta= event.getDelta(); Set<IAdaptable> removedElements= new HashSet<IAdaptable>(); Set<IAdaptable> potentiallyRemovedElements= new HashSet<IAdaptable>(); collectRemoved(potentiallyRemovedElements, removedElements, delta); if (removedElements.size() > 0) handleRemoved(removedElements); if (potentiallyRemovedElements.size() > 0) handleRemoved(potentiallyRemovedElements); //System.out.println(this+"handled delta in: "+(System.currentTimeMillis()-t0)); }
public void elementChanged(final ElementChangedEvent e) { if (getControl() == null) return; Display d= getControl().getDisplay(); if (d != null) { d.asyncExec(new Runnable() { public void run() { ICompilationUnit cu= (ICompilationUnit) fInput; IJavaElement base= cu; if (fTopLevelTypeOnly) { base= cu.findPrimaryType(); if (base == null) { if (fOutlineViewer != null) fOutlineViewer.refresh(true); return; } } IJavaElementDelta delta= findElement(base, e.getDelta()); if (delta != null && fOutlineViewer != null) { fOutlineViewer.reconcile(delta); } } }); } }
public void elementChanged(ElementChangedEvent event) { if (fViewer == null) return; Object input= fViewer.getInput(); if (!(input instanceof IJavaElement)) return; if (fRunnable != null) return; final IJavaElement changedElement= getChangedParentElement((IJavaElement) input, event.getDelta()); if (changedElement == null) return; fRunnable= new Runnable() { public void run() { if (fViewer == null) return; Object newInput= getCurrentInput(); if (newInput instanceof IJavaElement) newInput= getInput((IJavaElement) newInput); fViewer.setInput(newInput); fRunnable= null; } }; fViewer.getControl().getDisplay().asyncExec(fRunnable); }
public void elementChanged(ElementChangedEvent event) { if (fChangeListeners.isEmpty()) { return; } if (fHierarchyRefreshNeeded) { return; } else { ArrayList<IType> changedTypes= new ArrayList<IType>(); processDelta(event.getDelta(), changedTypes); if (changedTypes.size() > 0) { fireChange(changedTypes.toArray(new IType[changedTypes.size()])); } } }
public void elementChanged(ElementChangedEvent event) { IJavaProject javaProject= getCachedJavaProject(); if (javaProject == null) return; IJavaElementDelta[] children= event.getDelta().getChangedChildren(); for (int i= 0; i < children.length; i++) { IJavaElementDelta child= children[i]; if (javaProject.equals(child.getElement())) { if (isClasspathChange(child)) { setCachedJavaProject(null); } } } }
public void elementChanged(ElementChangedEvent event) { if (isRunningInReconcilerThread()) return; if (event.getDelta().getFlags() == IJavaElementDelta.F_AST_AFFECTED || canIgnore(event.getDelta().getAffectedChildren())) return; setJavaModelChanged(true); if (isEditorActive()) JavaReconciler.this.forceReconciling(); }
public void elementChanged(ElementChangedEvent event) { ITypedElement[] elements= findAffectedElement(event); for (int i= 0; i < elements.length; i++) { ITypedElement e= elements[i]; if (e == null || !(e instanceof IContentChangeNotifier)) continue; contentChanged((IContentChangeNotifier)e); } }
/** * Tells which elements of the comparison are affected by the change. * * @param event element changed event * @return array of typed elements affected by the event. May return an empty array. * @since 3.5 */ private ITypedElement[] findAffectedElement(ElementChangedEvent event) { Object input= getInput(); if (!(input instanceof ICompareInput)) return new ITypedElement[0]; Set<ITypedElement> affectedElements= new HashSet<ITypedElement>(); ICompareInput ci= (ICompareInput)input; IJavaElementDelta delta= event.getDelta(); addAffectedElement(ci.getAncestor(), delta, affectedElements); addAffectedElement(ci.getLeft(), delta, affectedElements); addAffectedElement(ci.getRight(), delta, affectedElements); return affectedElements.toArray(new ITypedElement[affectedElements.size()]); }
public void elementChanged(ElementChangedEvent event) { try { processDelta(event.getDelta()); } catch (JavaModelException e) { JavaPlugin.log(e); } }
public void elementChanged(final ElementChangedEvent event) { try { processDelta(event.getDelta()); } catch(JavaModelException e) { JavaPlugin.log(e.getStatus()); } }
public void init(WorkingSetModel model) { fWorkingSetModel= model; fResourceChangeListener= new ResourceChangeListener(); ResourcesPlugin.getWorkspace().addResourceChangeListener(fResourceChangeListener, IResourceChangeEvent.POST_CHANGE); fWorkingSetListener= new WorkingSetListener(); PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(fWorkingSetListener); fJavaElementChangeListener= new JavaElementChangeListener(); JavaCore.addElementChangedListener(fJavaElementChangeListener, ElementChangedEvent.POST_CHANGE); }