org.eclipse.ui.internal.registry.PerspectiveDescriptor Java Examples

The following examples show how to use org.eclipse.ui.internal.registry.PerspectiveDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractNewProjectWizard.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #2
Source File: PerspectiveHelper.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
static PerspectiveDescriptor getSimulationDescriptor() {
	return (PerspectiveDescriptor) getPerspectiveRegistry().findPerspectiveWithId(PERSPECTIVE_SIMULATION_ID);
}
 
Example #3
Source File: PerspectiveImportService.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@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;
}
 
Example #4
Source File: PerspectiveImportService.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@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);
			}
		}
		
	}
}