Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 479126
Collapse All | Expand All

(-)a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java (+36 lines)
Lines 17-23 Link Here
17
import java.io.IOException;
17
import java.io.IOException;
18
import java.net.URL;
18
import java.net.URL;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.LinkedHashSet;
20
import java.util.List;
21
import java.util.List;
22
import java.util.Set;
21
import javax.annotation.PostConstruct;
23
import javax.annotation.PostConstruct;
22
import javax.annotation.PreDestroy;
24
import javax.annotation.PreDestroy;
23
import javax.inject.Inject;
25
import javax.inject.Inject;
Lines 401-406 Link Here
401
				}
403
				}
402
			}
404
			}
403
		}
405
		}
406
407
		createPerspectiveBarExtras();
408
	}
409
410
	/**
411
	 * Add ToolItems for perspectives specified in "PERSPECTIVE_BAR_EXTRAS"
412
	 */
413
	private void createPerspectiveBarExtras() {
414
		String persps = PrefUtil.getAPIPreferenceStore()
415
				.getString(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS);
416
		String[] parts = persps.split(" "); //$NON-NLS-1$
417
		Set<String> perspSet = new LinkedHashSet<>();
418
		for (String part : parts) {
419
			String[] parts2 = part.split(","); //$NON-NLS-1$
420
			for (String part2 : parts2) {
421
				part2 = part2.trim();
422
				if (!part2.isEmpty())
423
					perspSet.add(part2);
424
			}
425
		}
426
427
		WorkbenchPage page = (WorkbenchPage) window.getContext().get(IWorkbenchPage.class);
428
		for (String perspId : perspSet) {
429
			MPerspective persp = (MPerspective) modelService.find(perspId, window);
430
			if (persp != null)
431
				continue; // already in stack, i.e. has already been added above
432
			IPerspectiveDescriptor desc = getDescriptorFor(perspId);
433
			if (desc == null)
434
				continue; // this perspective does not exist
435
			persp = page.createPerspective(desc);
436
			persp.setLabel(desc.getLabel());
437
			getPerspectiveStack().getChildren().add(persp);
438
			// "add" fires Event, causes creation of ToolItem on perspective bar
439
		}
404
	}
440
	}
405
441
406
	protected Point downPos = null;
442
	protected Point downPos = null;
(-)a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-14 / +22 lines)
Lines 4032-4052 Link Here
4032
				perspective.getId(), window);
4032
				perspective.getId(), window);
4033
4033
4034
		if (modelPerspective == null) {
4034
		if (modelPerspective == null) {
4035
4036
			// couldn't find the perspective, create a new one
4035
			// couldn't find the perspective, create a new one
4037
			modelPerspective = modelService.createModelElement(MPerspective.class);
4036
			modelPerspective = createPerspective(perspective);
4038
4039
			// tag it with the same id
4040
			modelPerspective.setElementId(perspective.getId());
4041
4042
			// instantiate the perspective
4043
			IPerspectiveFactory factory = ((PerspectiveDescriptor) perspective).createFactory();
4044
			ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService,
4045
					partService, modelPerspective, perspective, this, true);
4046
			factory.createInitialLayout(modelLayout);
4047
			PerspectiveTagger.tagPerspective(modelPerspective, modelService);
4048
			PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
4049
			reader.extendLayout(getExtensionTracker(), perspective.getId(), modelLayout);
4050
		}
4037
		}
4051
4038
4052
		modelPerspective.setLabel(perspective.getLabel());
4039
		modelPerspective.setLabel(perspective.getLabel());
Lines 4076-4081 Link Here
4076
		UIEvents.publishEvent(UIEvents.UILifeCycle.PERSPECTIVE_OPENED, modelPerspective);
4063
		UIEvents.publishEvent(UIEvents.UILifeCycle.PERSPECTIVE_OPENED, modelPerspective);
4077
	}
4064
	}
4078
4065
4066
	/**
4067
	 * @param perspective
4068
	 * @return never null
4069
	 */
4070
	public MPerspective createPerspective(IPerspectiveDescriptor perspective) {
4071
		MPerspective modelPerspective = modelService.createModelElement(MPerspective.class);
4072
4073
		// tag it with the same id
4074
		modelPerspective.setElementId(perspective.getId());
4075
4076
		// instantiate the perspective
4077
		IPerspectiveFactory factory = ((PerspectiveDescriptor) perspective).createFactory();
4078
		ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService,
4079
				partService, modelPerspective, perspective, this, true);
4080
		factory.createInitialLayout(modelLayout);
4081
		PerspectiveTagger.tagPerspective(modelPerspective, modelService);
4082
		PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
4083
		reader.extendLayout(getExtensionTracker(), perspective.getId(), modelLayout);
4084
		return modelPerspective;
4085
	}
4086
4079
	void perspectiveActionSetChanged(Perspective perspective, IActionSetDescriptor descriptor,
4087
	void perspectiveActionSetChanged(Perspective perspective, IActionSetDescriptor descriptor,
4080
			int changeType) {
4088
			int changeType) {
4081
		if (perspective == getActivePerspective()) {
4089
		if (perspective == getActivePerspective()) {

Return to bug 479126