KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > viewsupport > TreeHierarchyLayoutProblemsDecorator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 package org.eclipse.jdt.internal.ui.viewsupport;
12
13 import org.eclipse.jdt.core.IPackageFragment;
14
15 import org.eclipse.jdt.ui.JavaElementImageDescriptor;
16 import org.eclipse.jdt.ui.ProblemsLabelDecorator;
17
18 import org.eclipse.jdt.internal.ui.browsing.LogicalPackage;
19
20 /**
21  * Special problem decorator for hierarchical package layout.
22  * <p>
23  * It only decorates package fragments which are not covered by the
24  * <code>ProblemsLabelDecorator</code>.
25  * </p>
26  *
27  * @see org.eclipse.jdt.ui.ProblemsLabelDecorator
28  * @since 2.1
29  */

30 public class TreeHierarchyLayoutProblemsDecorator extends ProblemsLabelDecorator {
31
32     private boolean fIsFlatLayout;
33     
34     public TreeHierarchyLayoutProblemsDecorator() {
35         this(false);
36     }
37     
38     public TreeHierarchyLayoutProblemsDecorator(boolean isFlatLayout) {
39         super(null);
40         fIsFlatLayout= isFlatLayout;
41     }
42     
43     protected int computePackageAdornmentFlags(IPackageFragment fragment) {
44         if (!fIsFlatLayout && !fragment.isDefaultPackage()) {
45             return super.computeAdornmentFlags(fragment.getResource());
46         }
47         return super.computeAdornmentFlags(fragment);
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.jdt.ui.ProblemsLabelDecorator#computeAdornmentFlags(java.lang.Object)
52      */

53     protected int computeAdornmentFlags(Object JavaDoc element) {
54         if (element instanceof IPackageFragment) {
55             return computePackageAdornmentFlags((IPackageFragment) element);
56         } else if (element instanceof LogicalPackage) {
57             IPackageFragment[] fragments= ((LogicalPackage) element).getFragments();
58             int res= 0;
59             for (int i= 0; i < fragments.length; i++) {
60                 int flags= computePackageAdornmentFlags(fragments[i]);
61                 if (flags == JavaElementImageDescriptor.ERROR) {
62                     return flags;
63                 } else if (flags != 0) {
64                     res= flags;
65                 }
66             }
67             return res;
68         }
69         return super.computeAdornmentFlags(element);
70     }
71     
72     public void setIsFlatLayout(boolean state) {
73         fIsFlatLayout= state;
74     }
75
76 }
77
Popular Tags