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.comp;
011:
012: import java.util.List;
013:
014: import org.eclipse.jface.viewers.ILabelProvider;
015: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
016: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
017: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
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: * CompCSFormOutlinePage
024: *
025: */
026: public class CompCSFormOutlinePage extends FormOutlinePage {
027:
028: /**
029: * @param editor
030: */
031: public CompCSFormOutlinePage(PDEFormEditor editor) {
032: super (editor);
033: }
034:
035: /**
036: * CompCSLabelProvider
037: *
038: */
039: private class CompCSLabelProvider extends BasicLabelProvider {
040: public String getText(Object obj) {
041: if (obj instanceof ICompCSObject) {
042: return getObjectText((ICompCSObject) obj);
043: }
044: return super .getText(obj);
045: }
046: }
047:
048: /**
049: * @param obj
050: * @return
051: */
052: protected String getObjectText(ICompCSObject obj) {
053: int limit = 50;
054:
055: if (obj.getType() == ICompCSConstants.TYPE_COMPOSITE_CHEATSHEET) {
056: limit = 30;
057: } else if (obj.getType() == ICompCSConstants.TYPE_TASK) {
058: limit = 26;
059: } else if (obj.getType() == ICompCSConstants.TYPE_TASKGROUP) {
060: limit = 22;
061: }
062:
063: return PDETextHelper.truncateAndTrailOffText(PDETextHelper
064: .translateReadText(obj.getName()), limit);
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getChildren(java.lang.Object)
069: */
070: protected Object[] getChildren(Object parent) {
071: if (parent instanceof CompCSPage) {
072: ICompCSModel cheatsheet = (ICompCSModel) fEditor
073: .getAggregateModel();
074: if ((cheatsheet != null) && cheatsheet.isLoaded()) {
075: Object[] list = new Object[1];
076: list[0] = cheatsheet.getCompCS();
077: return list;
078: }
079: } else if (parent instanceof ICompCSObject) {
080: List list = ((ICompCSObject) parent).getChildren();
081: // List is never null
082: if (list.size() > 0) {
083: return list.toArray();
084: }
085: }
086: return super .getChildren(parent);
087: }
088:
089: /* (non-Javadoc)
090: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#createLabelProvider()
091: */
092: public ILabelProvider createLabelProvider() {
093: return new CompCSLabelProvider();
094: }
095:
096: /* (non-Javadoc)
097: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getParentPageId(java.lang.Object)
098: */
099: protected String getParentPageId(Object item) {
100: return CompCSPage.PAGE_ID;
101: }
102:
103: }
|