/** * Adds to the list all perspective IDs in the Workbench who's original ID * matches the given ID. * * @param perspectiveIds * the list of perspective IDs to supplement. * @param id * the id to query. * @since 3.0 */ @SuppressWarnings({ "unchecked" }) private static void addPerspectiveAndDescendants(List perspectiveIds, String id) { IPerspectiveRegistry registry = PlatformUI.getWorkbench() .getPerspectiveRegistry(); IPerspectiveDescriptor[] perspectives = registry.getPerspectives(); for (int i = 0; i < perspectives.length; i++) { // @issue illegal ref to workbench internal class; // consider adding getOriginalId() as API on IPerspectiveDescriptor PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]); if (descriptor.getOriginalId().equals(id)) { perspectiveIds.add(descriptor.getId()); } } }
/** * Adds to the list all perspective IDs in the Workbench who's original ID * matches the given ID. * * @param perspectiveIds * the list of perspective IDs to supplement. * @param id * the id to query. * @since 3.0 */ private static void addPerspectiveAndDescendants(List perspectiveIds, String id) { IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry(); IPerspectiveDescriptor[] perspectives = registry.getPerspectives(); for (int i = 0; i < perspectives.length; i++) { // @issue illegal ref to workbench internal class; // consider adding getOriginalId() as API on IPerspectiveDescriptor PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]); if (descriptor.getOriginalId().equals(id)) { perspectiveIds.add(descriptor.getId()); } } }
public static List<String> missingInitialViews(final IWorkbenchPage page) { final IPerspectiveFactory factory; factory = ((PerspectiveDescriptor)page.getPerspective()).createFactory(); ViewCapturingLayout layout = new ViewCapturingLayout(); factory.createInitialLayout(layout); final F<String, Boolean> missing = new F<String, Boolean>() { @Override public Boolean f(final String viewId) { return page.findView(viewId) == null; } }; return fj(layout.viewIds).filter(missing).toList(); }
static PerspectiveDescriptor getSimulationDescriptor() { return (PerspectiveDescriptor) getPerspectiveRegistry().findPerspectiveWithId(PERSPECTIVE_SIMULATION_ID); }
@SuppressWarnings("restriction") private IPerspectiveDescriptor importPerspectiveFromStream(InputStream in, IStateCallback iStateHandle, boolean openPerspectiveIfAdded) throws IOException{ MPerspective mPerspective = loadPerspectiveFromStream(in); if (mPerspective != null) { IPerspectiveRegistry iPerspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry(); // the perspective id to import String id = mPerspective.getElementId(); IPerspectiveDescriptor existingPerspectiveDescriptor = iPerspectiveRegistry.findPerspectiveWithId(id); // the active perspective id String activePerspectiveId = getActivePerspectiveId(); // check if the import should be done if (existingPerspectiveDescriptor == null || iStateHandle == null || iStateHandle.state(State.OVERRIDE)) { IPerspectiveDescriptor activePd = iPerspectiveRegistry.findPerspectiveWithId(activePerspectiveId); // delete if a perspective with the id already exists int idx = deletePerspective(id); // add the new perspective to the registry ((PerspectiveRegistry) iPerspectiveRegistry).addPerspective(mPerspective); IPerspectiveDescriptor createdPd = iPerspectiveRegistry.findPerspectiveWithId(id); if (createdPd != null) { ((PerspectiveDescriptor) createdPd).setHasCustomDefinition(false); //no original descriptor should exists } // check if the new perspective should be opened if (idx > -1 || openPerspectiveIfAdded) { openPerspective(createdPd); // there was already an opened active perspective switch back to it openPerspective(activePd); } return createdPd; } } return null; }
@SuppressWarnings("restriction") @Override public void savePerspectiveAs(String perspectiveId, String newName){ EModelService modelService = getService(EModelService.class); MApplication mApplication = getService(MApplication.class); PerspectiveRegistry perspectiveRegistry = (PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry(); PerspectiveDescriptor existingPerspectiveDescriptor = (PerspectiveDescriptor) perspectiveRegistry.findPerspectiveWithId(perspectiveId); if (existingPerspectiveDescriptor != null) { int idx = isPerspectiveInsideStack(existingPerspectiveDescriptor); // loads the mapplication from the orginal descriptor openPerspective(existingPerspectiveDescriptor); // the model must be loaded List<MPerspective> modelPerspective = modelService.findElements(mApplication, existingPerspectiveDescriptor.getId(), MPerspective.class, null); // check if the model is loaded if (!modelPerspective.isEmpty()) { // create a new pd PerspectiveDescriptor newPd = perspectiveRegistry.createPerspective(newName, existingPerspectiveDescriptor); // saves an opens the new perspective PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .savePerspectiveAs(newPd); // close the new created one closePerspective(newPd); if (idx > -1) { // opens the original descriptor if it was already opened openPerspective(existingPerspectiveDescriptor); } } } }