Skip to content

Commit

Permalink
Ensure that in an IDE with ReportEditorInput the source tab works
Browse files Browse the repository at this point in the history
Use a subclass of
org.eclipse.birt.report.designer.internal.ui.editors.ReportEditorInput
that implements org.eclipse.ui.IStorageEditorInput.
Also guard against stack overflow from
ReportEditorInput.getAdapter(Class).

eclipse-birt#1589
  • Loading branch information
merks committed Mar 26, 2024
1 parent 1ea24f6 commit 92bc0a2
Showing 1 changed file with 40 additions and 0 deletions.
Expand Up @@ -14,8 +14,13 @@

package org.eclipse.birt.report.designer.ui.editors;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.birt.report.designer.core.model.SessionHandleAdapter;
import org.eclipse.birt.report.designer.internal.ui.editors.IReportEditor;
import org.eclipse.birt.report.designer.internal.ui.editors.ReportEditorInput;
import org.eclipse.birt.report.designer.internal.ui.views.actions.GlobalActionFactory;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -25,6 +30,7 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartConstants;
Expand Down Expand Up @@ -107,6 +113,10 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
instance.dispose();
}

if (input instanceof ReportEditorInput) {
input = new ReportEditorStorageInput((((ReportEditorInput) input).getFile()));
}

if (input instanceof IFileEditorInput || input instanceof IURIEditorInput) {
instance = new IDEMultiPageReportEditor();
} else {
Expand Down Expand Up @@ -507,3 +517,33 @@ public boolean equals(Object obj) {
return super.equals(obj);
}
}

class ReportEditorStorageInput extends ReportEditorInput implements IStorageEditorInput {

public ReportEditorStorageInput(File file) {
super(file);
}

@Override
public Object getAdapter(Class adapter) {
// Avoid stack overflow from recursion on the same adapter type.
Set<Class<?>> computationInProgress = COMPUTATION_IN_PROGRESS.get();
if (!computationInProgress.contains(adapter)) {
try {
if (computationInProgress.add(adapter)) {
return super.getAdapter(adapter);
}
} finally {
computationInProgress.remove(adapter);
}
}
return null;
}

private static final ThreadLocal<Set<Class<?>>> COMPUTATION_IN_PROGRESS = new ThreadLocal<Set<Class<?>>>() {
@Override
protected java.util.Set<Class<?>> initialValue() {
return new HashSet<Class<?>>();
}
};
}

0 comments on commit 92bc0a2

Please sign in to comment.