| /****************************************************************************** |
| * Copyright (c) David Orme and others |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * David Orme - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.e4.ui.app.skeleton; |
| |
| import org.eclipse.e4.core.metaconfig.Configuration; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.application.IWorkbenchConfigurer; |
| import org.eclipse.ui.application.IWorkbenchWindowConfigurer; |
| import org.eclipse.ui.application.WorkbenchAdvisor; |
| import org.eclipse.ui.application.WorkbenchWindowAdvisor; |
| |
| |
| /** |
| * class WorkbenchAdvisor. This is a standard Eclipse workbench advisor with |
| * the addition that it looks up the default perspective ID in the configuration |
| * file. |
| */ |
| public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { |
| |
| /** |
| * The key to look for in the configuration file identifying the default perspective |
| */ |
| private static final String DEFAULT_PERSPECTIVE_ID_KEY = "org.eclipse.e4.enterprise.DEFAULT_PERSPECTIVE_ID"; |
| |
| public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { |
| return new ApplicationWorkbenchWindowAdvisor(configurer); |
| } |
| |
| public void initialize(IWorkbenchConfigurer configurer) { |
| super.initialize(configurer); |
| configurer.setSaveAndRestore(true); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId() |
| */ |
| public String getInitialWindowPerspectiveId() { |
| /* |
| * Query the configuration for the default perspective ID and try that first. |
| * Else return some hard-coded perspective ID. Eclipse won't load any |
| * perspective if it can't find this one. |
| */ |
| Configuration config = Activator.getDefault().getConfiguration(); |
| String defaultPerspectiveId = (String) config.getProperties().get(DEFAULT_PERSPECTIVE_ID_KEY); |
| |
| if (perspectiveExists(defaultPerspectiveId)) { |
| return defaultPerspectiveId; |
| } else { |
| //null is fine to return here as Eclipse interprets this as not opening any perspective at all |
| //If your code gets in here it is highly likely that you have either a) misspelled the ID of your perspective being downloaded |
| //or b) the download failed and the perspective isn't available |
| // return null; |
| return "org.eclipse.e4.enterprise.bootsrapper.client.perspective"; |
| } |
| } |
| |
| private boolean perspectiveExists(String perspectiveId) { |
| if (PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(perspectiveId) != null) { |
| return true; |
| } else { |
| return false; |
| } |
| } |
| } |