]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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 | @Override | |
54 | protected int computeAdornmentFlags(Object element) { | |
55 | if (element instanceof IPackageFragment) { | |
56 | return computePackageAdornmentFlags((IPackageFragment) element); | |
57 | } else if (element instanceof LogicalPackage) { | |
58 | IPackageFragment[] fragments= ((LogicalPackage) element).getFragments(); | |
59 | int res= 0; | |
60 | for (int i= 0; i < fragments.length; i++) { | |
61 | int flags= computePackageAdornmentFlags(fragments[i]); | |
62 | if (flags == JavaElementImageDescriptor.ERROR) { | |
63 | return flags; | |
64 | } else if (flags != 0) { | |
65 | res= flags; | |
66 | } | |
67 | } | |
68 | return res; | |
69 | } | |
70 | return super.computeAdornmentFlags(element); | |
71 | } | |
72 | ||
73 | public void setIsFlatLayout(boolean state) { | |
74 | fIsFlatLayout= state; | |
75 | } | |
76 | ||
77 | } |