Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.adt.internal.ui;
     18 
     19 import org.eclipse.ui.IViewPart;
     20 import org.eclipse.ui.IWorkbenchPage;
     21 import org.eclipse.ui.IWorkbenchWindow;
     22 import org.eclipse.ui.PartInitException;
     23 import org.eclipse.ui.PlatformUI;
     24 
     25 /**
     26  * Helpers for Eclipse UI related stuff.
     27  */
     28 public final class EclipseUiHelper {
     29 
     30     /** View Id for the default Eclipse Content Outline view. */
     31     public static final String CONTENT_OUTLINE_VIEW_ID = "org.eclipse.ui.views.ContentOutline";
     32     /** View Id for the default Eclipse Property Sheet view. */
     33     public static final String PROPERTY_SHEET_VIEW_ID  = "org.eclipse.ui.views.PropertySheet";
     34 
     35     /** This class never gets instantiated. */
     36     private EclipseUiHelper() {
     37     }
     38 
     39     /**
     40      * Shows the corresponding view.
     41      * <p/>
     42      * Silently fails in case of error.
     43      *
     44      * @param viewId One of {@link #CONTENT_OUTLINE_VIEW_ID}, {@link #PROPERTY_SHEET_VIEW_ID}.
     45      * @param activate True to force activate (i.e. takes focus), false to just make visible (i.e.
     46      *                 does not steal focus.)
     47      */
     48     public static void showView(String viewId, boolean activate) {
     49         IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     50         if (win != null) {
     51             IWorkbenchPage page = win.getActivePage();
     52             if (page != null) {
     53                 try {
     54                     IViewPart part = page.showView(viewId,
     55                             null /* secondaryId */,
     56                             activate ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_VISIBLE);
     57                 } catch (PartInitException e) {
     58                     // ignore
     59                 }
     60             }
     61         }
     62 
     63     }
     64 }
     65