|
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
| 4 | +package com.e1c.v8codestyle.bsl.check; |
| 5 | + |
| 6 | +import java.util.Collection; |
| 7 | +import java.util.Map; |
| 8 | +import java.util.Set; |
| 9 | + |
| 10 | +import org.eclipse.xtext.util.Pair; |
| 11 | +import org.eclipse.xtext.util.Tuples; |
| 12 | + |
| 13 | +import com._1c.g5.v8.dt.lcore.util.CaseInsensitiveString; |
| 14 | +import com._1c.g5.v8.dt.platform.IEObjectTypeNames; |
| 15 | +import com.google.inject.Singleton; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Dmitriy Marmyshev |
| 19 | + * |
| 20 | + */ |
| 21 | +@Singleton |
| 22 | +public class LocalizableRegistry |
| 23 | +{ |
| 24 | + |
| 25 | + private Map<CaseInsensitiveString, Collection<Integer>> staticInvocation; |
| 26 | + |
| 27 | + private Map<Pair<CaseInsensitiveString, Integer>, Collection<String>> dynamicInvocation; |
| 28 | + |
| 29 | + private Map<CaseInsensitiveString, Collection<String>> dynamicProperties; |
| 30 | + |
| 31 | + private volatile boolean initialized; |
| 32 | + |
| 33 | + public Collection<Integer> getStaticInvocationParameters(String methodName) |
| 34 | + { |
| 35 | + if (methodName == null) |
| 36 | + { |
| 37 | + return Set.of(); |
| 38 | + } |
| 39 | + checkInit(); |
| 40 | + |
| 41 | + return staticInvocation.getOrDefault(new CaseInsensitiveString(methodName), Set.of()); |
| 42 | + } |
| 43 | + |
| 44 | + public Collection<String> getDynamicTypesForMethod(String methodName, int index) |
| 45 | + { |
| 46 | + if (methodName == null || index < 0) |
| 47 | + { |
| 48 | + return Set.of(); |
| 49 | + } |
| 50 | + |
| 51 | + checkInit(); |
| 52 | + |
| 53 | + return dynamicInvocation.getOrDefault(Tuples.create(new CaseInsensitiveString(methodName), index), Set.of()); |
| 54 | + } |
| 55 | + |
| 56 | + public Collection<String> getDynamicTypesForProperty(String propertyName) |
| 57 | + { |
| 58 | + if (propertyName == null) |
| 59 | + { |
| 60 | + return Set.of(); |
| 61 | + } |
| 62 | + |
| 63 | + checkInit(); |
| 64 | + |
| 65 | + return dynamicProperties.getOrDefault(new CaseInsensitiveString(propertyName), Set.of()); |
| 66 | + } |
| 67 | + |
| 68 | + private void checkInit() |
| 69 | + { |
| 70 | + if (initialized) |
| 71 | + { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + init(); |
| 76 | + } |
| 77 | + |
| 78 | + private synchronized void init() |
| 79 | + { |
| 80 | + if (initialized) |
| 81 | + { |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + initStaticInvocation(); |
| 86 | + initDynamicInvocation(); |
| 87 | + initDynamicProperties(); |
| 88 | + |
| 89 | + initialized = true; |
| 90 | + } |
| 91 | + |
| 92 | + private void initStaticInvocation() |
| 93 | + { |
| 94 | + //@formatter:off |
| 95 | + |
| 96 | + // Global context method name and index of localizable string parameter |
| 97 | + staticInvocation = Map.of( |
| 98 | + new CaseInsensitiveString("ПоказатьВопрос"), Set.of(1, 5), //$NON-NLS-1$ |
| 99 | + new CaseInsensitiveString("ShowQueryBox"), Set.of(1, 5) //$NON-NLS-1$ |
| 100 | + ); |
| 101 | + //@formatter:on |
| 102 | + } |
| 103 | + |
| 104 | + private void initDynamicInvocation() |
| 105 | + { |
| 106 | + //@formatter:off |
| 107 | + |
| 108 | + // Object's method name and index of localizable string parameter, and collection of object's type names |
| 109 | + dynamicInvocation = Map.of( |
| 110 | + Tuples.create(new CaseInsensitiveString("Добавить"), 1), Set.of(IEObjectTypeNames.VALUE_LIST), //$NON-NLS-1$ |
| 111 | + Tuples.create(new CaseInsensitiveString("Add"), 1), Set.of(IEObjectTypeNames.VALUE_LIST) //$NON-NLS-1$ |
| 112 | + ); |
| 113 | + |
| 114 | + //@formatter:on |
| 115 | + |
| 116 | + } |
| 117 | + |
| 118 | + private void initDynamicProperties() |
| 119 | + { |
| 120 | + //@formatter:off |
| 121 | + |
| 122 | + // Types that contains property Title |
| 123 | + Set<String> TITLE_TYPES = Set.of( |
| 124 | + IEObjectTypeNames.FORM_FIELD, |
| 125 | + IEObjectTypeNames.FORM_GROUP, |
| 126 | + IEObjectTypeNames.FORM_TABLE, |
| 127 | + IEObjectTypeNames.FORM_DECORATION, |
| 128 | + IEObjectTypeNames.FORM_COMMAND, |
| 129 | + "FormAttribute", //$NON-NLS-1$ |
| 130 | + "FormItemAddition", //$NON-NLS-1$ |
| 131 | + IEObjectTypeNames.FORM_BUTTON, |
| 132 | + IEObjectTypeNames.CLIENT_APPLICATION_FORM, |
| 133 | + "ConditionalAppearenceItem", //$NON-NLS-1$ |
| 134 | + "AppearenceSettingItem", //$NON-NLS-1$ |
| 135 | + "CollaborationSystemConversation", //$NON-NLS-1$ |
| 136 | + "DeliverableNotification", //$NON-NLS-1$ |
| 137 | + "RepresentableDocumentBatch", //$NON-NLS-1$ |
| 138 | + "HTMLDocument", //$NON-NLS-1$ |
| 139 | + "ValueTableColumn", //$NON-NLS-1$ |
| 140 | + "ValueTreeColumn", //$NON-NLS-1$ |
| 141 | + "DataCompositionAreaTemplateValueCollectionHeaderCell", //$NON-NLS-1$ |
| 142 | + IEObjectTypeNames.DATA_COMPOSITION_USER_FIELD_EXPRESSION, |
| 143 | + IEObjectTypeNames.DATA_COMPOSITION_USER_FIELD_CASE, |
| 144 | + IEObjectTypeNames.DATA_COMPOSITION_SELECTED_FIELD_GROUP, |
| 145 | + IEObjectTypeNames.DATA_COMPOSITION_SELECTED_FIELD, |
| 146 | + IEObjectTypeNames.DATA_COMPOSITION_FILTER_AVAILABLE_FIELD, |
| 147 | + "NestedDataCompositionSchema", //$NON-NLS-1$ |
| 148 | + "DataCompositionSchemaParameter", //$NON-NLS-1$ |
| 149 | + "DataCompositionSchemaNestedDataSet", //$NON-NLS-1$ |
| 150 | + "DataCompositionSchemaDataSetFieldFolder", //$NON-NLS-1$ |
| 151 | + "DataCompositionSchemaDataSetField", //$NON-NLS-1$ |
| 152 | + "DataCompositionSchemaCalculatedField", //$NON-NLS-1$ |
| 153 | + IEObjectTypeNames.DATA_ANALYSIS_PARAMETERS, |
| 154 | + "GanttChartPlotArea", //$NON-NLS-1$ |
| 155 | + "FileDialog" //$NON-NLS-1$ |
| 156 | + ); |
| 157 | + |
| 158 | + // Types that contains property ToolTip |
| 159 | + // TODO add all types with tooltip |
| 160 | + Set<String> TOOL_TIP_TYPES = Set.of( |
| 161 | + IEObjectTypeNames.FORM_FIELD, |
| 162 | + IEObjectTypeNames.FORM_GROUP, |
| 163 | + IEObjectTypeNames.FORM_TABLE, |
| 164 | + IEObjectTypeNames.FORM_DECORATION, |
| 165 | + IEObjectTypeNames.FORM_COMMAND, |
| 166 | + "FormItemAddition", //$NON-NLS-1$ |
| 167 | + "DateAppearence" //$NON-NLS-1$ |
| 168 | + ); |
| 169 | + |
| 170 | + // TODO add types of graphical scheme with Description |
| 171 | + |
| 172 | + // TODO add types of DCS with Presentation |
| 173 | + |
| 174 | + // Localizable property name, and collection of types |
| 175 | + dynamicProperties = Map.of( |
| 176 | + new CaseInsensitiveString("Подсказка"), TOOL_TIP_TYPES, //$NON-NLS-1$ |
| 177 | + new CaseInsensitiveString("ToolTip"), TOOL_TIP_TYPES, //$NON-NLS-1$ |
| 178 | + new CaseInsensitiveString("ПодсказкаВвода"), Set.of("FormFieldExtenstionForTextBox"), //$NON-NLS-1$ |
| 179 | + new CaseInsensitiveString("InputHint"), Set.of("FormFieldExtenstionForTextBox"), //$NON-NLS-1$ |
| 180 | + new CaseInsensitiveString("Заголовок"), TITLE_TYPES, //$NON-NLS-1$ |
| 181 | + new CaseInsensitiveString("Title"), TITLE_TYPES //$NON-NLS-1$ |
| 182 | + ); |
| 183 | + //@formatter:on |
| 184 | + |
| 185 | + } |
| 186 | + |
| 187 | +} |
0 commit comments