Skip to content

Commit

Permalink
Fix #427 : look for spy parts in all application model and from any w…
Browse files Browse the repository at this point in the history
…indow
  • Loading branch information
opcoach authored and jukzi committed Jul 10, 2023
1 parent c8754be commit f0a8ae2
Showing 1 changed file with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.MParameter;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;

Check warning on line 28 in ui/org.eclipse.pde.spy.core/src/org/eclipse/pde/spy/core/SpyHandler.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.e4.ui.model.application.ui.MUIElement;

Check warning on line 29 in ui/org.eclipse.pde.spy.core/src/org/eclipse/pde/spy/core/SpyHandler.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.e4.ui.model.application.ui.SideValue;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;

Check warning on line 33 in ui/org.eclipse.pde.spy.core/src/org/eclipse/pde/spy/core/SpyHandler.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
Expand Down Expand Up @@ -57,28 +60,28 @@ public class SpyHandler {
public void run(EPartService ps, @Optional @Named(SpyProcessor.SPY_COMMAND_PARAM) String viewID, MApplication appli,
EModelService modelService) {

MWindow spyWindow = prepareSpyWindow(appli, modelService);

MPartStack partStack = (MPartStack) modelService.find(E4_SPIES_PART_STACK, spyWindow);

MPart p = ps.findPart(viewID);
// Fix #427 : search for the part in application model instead of current window
// because the part can be outside of the spy window or searched from another
// main window
List<MPart> parts = modelService.findElements(appli, viewID, MPart.class);
MPart p = (parts.size() >= 1) ? parts.get(0) : null;
if (p == null) {
// Create the part in the spyWindow...
MWindow spyWindow = prepareSpyWindow(appli, modelService);
MPartStack partStack = (MPartStack) modelService.find(E4_SPIES_PART_STACK, spyWindow);
p = ps.createPart(viewID);
partStack.getChildren().add(p);
partStack.setSelectedElement(p);
}

p.setVisible(true);

// modelService.bringToTop(spyWindow);
ps.activate(p, true);
modelService.bringToTop(p);

}

/**
* Prepare the spy window : add the toolbar Item to be called for each spies
* in the tool bar The structure is defined in the fragment.
* Prepare the spy window : add the toolbar Item to be called for each spies in
* the tool bar The structure is defined in the fragment.
*
* @param appli
* @param modelService
Expand All @@ -96,24 +99,17 @@ private MWindow prepareSpyWindow(MApplication appli, EModelService modelService)
// from the
// snippet.
MTrimmedWindow tws = (MTrimmedWindow) modelService.findSnippet(appli, E4_SPIES_WINDOW);

// Fix #579332 : must copy the snippet to keep it in the snippet list if it must be re-created later.
EObject eObj = (EObject) tws;
MTrimmedWindow tw = (MTrimmedWindow) EcoreUtil.copy(eObj);

// Fix #579332 : must copy the snippet to keep it in the snippet list if it must
// be re-created later.
EObject eObj = (EObject) tws;
MTrimmedWindow tw = (MTrimmedWindow) EcoreUtil.copy(eObj);

MTrimBar trimBar = tw.getTrimBars().stream().filter(t -> t.getSide() == SideValue.TOP).findFirst().get();
MToolBar toolbar = (MToolBar) trimBar.getChildren().get(0);

// Get the spy command (added by fragment)
MCommand spyCmd = null;
for (MCommand cmd : appli.getCommands()) {
if (SpyProcessor.SPY_COMMAND.equals(cmd.getElementId())) {
// Do nothing if command exists
spyCmd = cmd;
break;
}
}
MCommand spyCmd = appli.getCommand(SpyProcessor.SPY_COMMAND);

// Create one toolbar element for each 'spy' tagged descriptor
for (MPartDescriptor mp : appli.getDescriptors()) {
Expand Down Expand Up @@ -148,10 +144,8 @@ private MWindow prepareSpyWindow(MApplication appli, EModelService modelService)
/**
* Make the spy window centered on top of main window.
*
* @param appli
* current appli
* @param tw
* main trim window
* @param appli current appli
* @param tw main trim window
*/
private void centerSpyWindow(MApplication appli, MTrimmedWindow tw) {
MWindow mainWindow = appli.getChildren().get(0);
Expand All @@ -165,5 +159,4 @@ private void centerSpyWindow(MApplication appli, MTrimmedWindow tw) {
tw.setHeight(spyH);
}


}

0 comments on commit f0a8ae2

Please sign in to comment.