1 /******************************************************************************* 2 * Copyright (c) 2011 Google, Inc. 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 * Google, Inc. - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.wb.internal.core.model.property.category; 12 13 import org.eclipse.wb.internal.core.model.property.Property; 14 import org.eclipse.wb.internal.core.utils.check.Assert; 15 16 /** 17 * Describes category of {@link Property}. 18 * 19 * @author scheglov_ke 20 * @coverage core.model.property 21 */ 22 public final class PropertyCategory { 23 /** 24 * "Normal" category, used for properties that should be displayed without any effect. 25 */ 26 public static final PropertyCategory NORMAL = new PropertyCategory(0, "NORMAL"); 27 /** 28 * "Preferred" category, for properties that are most useful for component. 29 */ 30 public static final PropertyCategory PREFERRED = new PropertyCategory(-1, "PREFERRED"); 31 /** 32 * "Advanced" category, for properties that are rarely used, visible if modified, even if not 33 * enabled. 34 */ 35 public static final PropertyCategory ADVANCED = new PropertyCategory(1, "ADVANCED"); 36 /** 37 * "Advanced" category, for properties that are rarely used, visible only if enabled. 38 */ 39 public static final PropertyCategory ADVANCED_REALLY = new PropertyCategory(2, "ADVANCED_REALLY"); 40 /** 41 * "Hidden" category, for properties that should not be displayed. 42 */ 43 public static final PropertyCategory HIDDEN = new PropertyCategory(3, "HIDDEN"); 44 45 //////////////////////////////////////////////////////////////////////////// 46 // 47 // System 48 // 49 //////////////////////////////////////////////////////////////////////////// 50 /** 51 * @return the system {@link PropertyCategory} with given priority. 52 */ 53 public static final PropertyCategory system(int priority) { 54 return new PropertyCategory(SYSTEM_BASE + priority, "SYSTEM:" + priority); 55 } 56 57 /** 58 * @return the system {@link PropertyCategory} with priority 59 * <code>system.getPriority() + additional</code>. 60 */ 61 public static final PropertyCategory system(PropertyCategory system, int additional) { 62 Assert.isTrue(system.isSystem()); 63 return system(system.getPriority() - SYSTEM_BASE + additional); 64 } 65 66 //////////////////////////////////////////////////////////////////////////// 67 // 68 // Instance fields 69 // 70 //////////////////////////////////////////////////////////////////////////// 71 private static final int SYSTEM_BASE = 1000; 72 private final int m_priority; 73 private final String m_string; 74 75 //////////////////////////////////////////////////////////////////////////// 76 // 77 // Constructor 78 // 79 //////////////////////////////////////////////////////////////////////////// 80 private PropertyCategory(int priority, String string) { 81 m_priority = priority; 82 m_string = string; 83 } 84 85 //////////////////////////////////////////////////////////////////////////// 86 // 87 // Object 88 // 89 //////////////////////////////////////////////////////////////////////////// 90 @Override 91 public String toString() { 92 return m_string; 93 } 94 95 @Override 96 public boolean equals(Object obj) { 97 if (obj == this) { 98 return true; 99 } 100 if (obj instanceof PropertyCategory) { 101 PropertyCategory category = (PropertyCategory) obj; 102 return m_priority == category.m_priority; 103 } 104 // unknown class 105 return false; 106 } 107 108 @Override 109 public int hashCode() { 110 return m_priority; 111 } 112 113 //////////////////////////////////////////////////////////////////////////// 114 // 115 // Access 116 // 117 //////////////////////////////////////////////////////////////////////////// 118 /** 119 * @return <code>true</code> if this property is preferred. 120 */ 121 public boolean isPreferred() { 122 return this == PREFERRED; 123 } 124 125 /** 126 * @return <code>true</code> if this property is advanced. 127 */ 128 public boolean isAdvanced() { 129 return this == ADVANCED; 130 } 131 132 /** 133 * @return <code>true</code> if this property is really advanced. 134 */ 135 public boolean isAdvancedReally() { 136 return this == ADVANCED_REALLY; 137 } 138 139 /** 140 * @return <code>true</code> if this property is hidden. 141 */ 142 public boolean isHidden() { 143 return this == HIDDEN; 144 } 145 146 /** 147 * @return <code>true</code> if this property is system. 148 */ 149 public boolean isSystem() { 150 return m_priority >= 900; 151 } 152 153 /** 154 * @return the priority of this category. 155 */ 156 public int getPriority() { 157 return m_priority; 158 } 159 } 160