01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.viewsupport;
11:
12: import org.eclipse.jdt.core.IPackageFragment;
13:
14: import org.eclipse.jdt.ui.JavaElementImageDescriptor;
15: import org.eclipse.jdt.ui.ProblemsLabelDecorator;
16:
17: import org.eclipse.jdt.internal.ui.browsing.LogicalPackage;
18:
19: /**
20: * Special problem decorator for hierarchical package layout.
21: * <p>
22: * It only decorates package fragments which are not covered by the
23: * <code>ProblemsLabelDecorator</code>.
24: * </p>
25: *
26: * @see org.eclipse.jdt.ui.ProblemsLabelDecorator
27: * @since 2.1
28: */
29: public class TreeHierarchyLayoutProblemsDecorator extends
30: 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 element) {
54: if (element instanceof IPackageFragment) {
55: return computePackageAdornmentFlags((IPackageFragment) element);
56: } else if (element instanceof LogicalPackage) {
57: IPackageFragment[] fragments = ((LogicalPackage) element)
58: .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: }
|