KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > simple > SimpleCSFormOutlinePage


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple;
13
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jface.viewers.ILabelProvider;
17 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
18 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
19 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
20 import org.eclipse.pde.internal.core.util.PDETextHelper;
21 import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
22 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
23
24 /**
25  * SimpleCSFormOutlinePage
26  *
27  */

28 public class SimpleCSFormOutlinePage extends FormOutlinePage {
29     
30     /**
31      * @param editor
32      */

33     public SimpleCSFormOutlinePage(PDEFormEditor editor) {
34         super(editor);
35     }
36
37     /**
38      * SimpleCSLabelProvider
39      *
40      */

41     public class SimpleCSLabelProvider extends BasicLabelProvider {
42         public String JavaDoc getText(Object JavaDoc obj) {
43             if (obj instanceof ISimpleCSObject) {
44                 return getObjectText((ISimpleCSObject)obj);
45             }
46             return super.getText(obj);
47         }
48     }
49     
50     /**
51      * @param obj
52      * @return
53      */

54     protected String JavaDoc getObjectText(ISimpleCSObject obj) {
55         int limit = 50;
56         
57         if (obj.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) {
58             limit = 30;
59         } else if (obj.getType() == ISimpleCSConstants.TYPE_ITEM) {
60             limit = 26;
61         } else if (obj.getType() == ISimpleCSConstants.TYPE_INTRO) {
62             limit = 26;
63         } else if (obj.getType() == ISimpleCSConstants.TYPE_SUBITEM) {
64             limit = 22;
65         }
66
67         return PDETextHelper.truncateAndTrailOffText(
68                 PDETextHelper.translateReadText(obj.getName()), limit);
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getChildren(java.lang.Object)
73      */

74     protected Object JavaDoc[] getChildren(Object JavaDoc parent) {
75         if (parent instanceof SimpleCSPage) {
76             ISimpleCSModel cheatsheet = (ISimpleCSModel)fEditor.getAggregateModel();
77             if ((cheatsheet != null)
78                     && cheatsheet.isLoaded()) {
79                 Object JavaDoc[] list = new Object JavaDoc[1];
80                 list[0] = cheatsheet.getSimpleCS();
81                 return list;
82             }
83         } else if (parent instanceof ISimpleCSObject) {
84             List JavaDoc list = ((ISimpleCSObject)parent).getChildren();
85             // List is never null
86
if (list.size() > 0) {
87                 return list.toArray();
88             }
89         }
90         return super.getChildren(parent);
91     }
92     
93     /* (non-Javadoc)
94      * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#createLabelProvider()
95      */

96     public ILabelProvider createLabelProvider() {
97         return new SimpleCSLabelProvider();
98     }
99     
100     /* (non-Javadoc)
101      * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getParentPageId(java.lang.Object)
102      */

103     protected String JavaDoc getParentPageId(Object JavaDoc item) {
104         return SimpleCSPage.PAGE_ID;
105     }
106     
107 }
108
Popular Tags