KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > comp > CompCSFormOutlinePage


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.comp;
13
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jface.viewers.ILabelProvider;
17 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
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  * CompCSFormOutlinePage
26  *
27  */

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

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

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

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

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

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

101     protected String JavaDoc getParentPageId(Object JavaDoc item) {
102         return CompCSPage.PAGE_ID;
103     }
104     
105 }
106
Popular Tags