Java 类org.eclipse.ui.internal.registry.PerspectiveRegistry 实例源码

项目:elexis-3-core    文件:PerspektiveImportHandler.java   
@SuppressWarnings("restriction")
private IPerspectiveDescriptor savePerspectiveToRegistryLegacy(MPerspective perspective){
    IPerspectiveRegistry perspectiveRegistry =
        (PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry();
    IPerspectiveDescriptor pd =
        perspectiveRegistry.findPerspectiveWithId(perspective.getElementId());
    if (pd == null) {
        ((PerspectiveRegistry) perspectiveRegistry).addPerspective(perspective);
        pd = perspectiveRegistry.findPerspectiveWithId(perspective.getElementId());
    } else {
        LoggerFactory.getLogger(PerspektiveImportHandler.class)
            .error("perspective descriptor already exists for perspective id: "
            + perspective.getElementId());
    }

    return pd;
}
项目:gama    文件:PerspectiveHelper.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
static void dirtySavePerspective(final SimulationPerspectiveDescriptor sp) {
    try {
        final Field descField = PerspectiveRegistry.class.getDeclaredField("descriptors");
        descField.setAccessible(true);
        final Map m = (Map) descField.get(getPerspectiveRegistry());
        m.put(sp.getId(), sp);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
项目:OpenSPIFe    文件:EnsembleWorkbenchWindowAdvisor.java   
protected void cleanupPerspectives() {
    PerspectiveRegistry pRegistry = (PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry();
    Collection<String> undesirables = getUndesirablePerspectives();
    List<IPerspectiveDescriptor> pToRemove = new ArrayList<IPerspectiveDescriptor>();
    for (IPerspectiveDescriptor pDesc : pRegistry.getPerspectives()) {
        if (undesirables.contains(pDesc.getId())) {
            pToRemove.add(pDesc);
        }
    }
    pRegistry.removeExtension(null, pToRemove.toArray(new Object[pToRemove.size()]));
    System.out.println();
}
项目:gama    文件:PerspectiveHelper.java   
public static PerspectiveRegistry getPerspectiveRegistry() {
    return (PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry();
}
项目:elexis-3-core    文件:PerspectiveImportService.java   
@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;
}
项目:elexis-3-core    文件:PerspectiveImportService.java   
@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);
            }
        }

    }
}