Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #427 : look for spy parts in all application model and from any window #489

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,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 26 in ui/org.eclipse.pde.spy.core/src/org/eclipse/pde/spy/core/SpyHandler.java

View check run for this annotation

Jenkins - eclipse-pde / Compiler and API Tools

Unnecessary Code

NORMAL: The import org.eclipse.e4.ui.model.application.ui.MElementContainer is never used
import org.eclipse.e4.ui.model.application.ui.MUIElement;

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

View check run for this annotation

Jenkins - eclipse-pde / Compiler and API Tools

Unnecessary Code

NORMAL: The import org.eclipse.e4.ui.model.application.ui.MUIElement is never used
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 31 in ui/org.eclipse.pde.spy.core/src/org/eclipse/pde/spy/core/SpyHandler.java

View check run for this annotation

Jenkins - eclipse-pde / Compiler and API Tools

Unnecessary Code

NORMAL: The import org.eclipse.e4.ui.model.application.ui.basic.MStackElement is never used
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 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.
*
* @return the model Spies window found in fragment.
*/
Expand All @@ -94,24 +97,17 @@
// 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 @@ -146,10 +142,8 @@
/**
* 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 @@ -163,5 +157,4 @@
tw.setHeight(spyH);
}


}
Loading