001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.cheatsheet.simple;
011:
012: import java.util.List;
013:
014: import org.eclipse.jface.viewers.ILabelProvider;
015: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
016: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
017: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
018: import org.eclipse.pde.internal.core.util.PDETextHelper;
019: import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
020: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
021:
022: /**
023: * SimpleCSFormOutlinePage
024: *
025: */
026: public class SimpleCSFormOutlinePage extends FormOutlinePage {
027:
028: /**
029: * @param editor
030: */
031: public SimpleCSFormOutlinePage(PDEFormEditor editor) {
032: super (editor);
033: }
034:
035: /**
036: * SimpleCSLabelProvider
037: *
038: */
039: public class SimpleCSLabelProvider extends BasicLabelProvider {
040: public String getText(Object obj) {
041: if (obj instanceof ISimpleCSObject) {
042: return getObjectText((ISimpleCSObject) obj);
043: }
044: return super .getText(obj);
045: }
046: }
047:
048: /**
049: * @param obj
050: * @return
051: */
052: protected String getObjectText(ISimpleCSObject obj) {
053: int limit = 50;
054:
055: if (obj.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) {
056: limit = 30;
057: } else if (obj.getType() == ISimpleCSConstants.TYPE_ITEM) {
058: limit = 26;
059: } else if (obj.getType() == ISimpleCSConstants.TYPE_INTRO) {
060: limit = 26;
061: } else if (obj.getType() == ISimpleCSConstants.TYPE_SUBITEM) {
062: limit = 22;
063: }
064:
065: return PDETextHelper.truncateAndTrailOffText(PDETextHelper
066: .translateReadText(obj.getName()), limit);
067: }
068:
069: /* (non-Javadoc)
070: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getChildren(java.lang.Object)
071: */
072: protected Object[] getChildren(Object parent) {
073: if (parent instanceof SimpleCSDefinitionPage) {
074: ISimpleCSModel cheatsheet = (ISimpleCSModel) fEditor
075: .getAggregateModel();
076: if ((cheatsheet != null) && cheatsheet.isLoaded()) {
077: Object[] list = new Object[1];
078: list[0] = cheatsheet.getSimpleCS();
079: return list;
080: }
081: } else if (parent instanceof ISimpleCSObject) {
082: List list = ((ISimpleCSObject) parent).getChildren();
083: // List is never null
084: if (list.size() > 0) {
085: return list.toArray();
086: }
087: }
088: return super .getChildren(parent);
089: }
090:
091: /* (non-Javadoc)
092: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#createLabelProvider()
093: */
094: public ILabelProvider createLabelProvider() {
095: return new SimpleCSLabelProvider();
096: }
097:
098: /* (non-Javadoc)
099: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getParentPageId(java.lang.Object)
100: */
101: protected String getParentPageId(Object item) {
102: return SimpleCSDefinitionPage.PAGE_ID;
103: }
104:
105: }
|