0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.uml.ui.controls.editcontrol;
0043:
0044: import java.awt.Color;
0045: import java.awt.Font;
0046: import java.util.StringTokenizer;
0047: import java.util.Vector;
0048:
0049: import org.netbeans.modules.uml.core.configstringframework.ConfigStringHelper;
0050: import org.netbeans.modules.uml.core.configstringframework.IConfigStringTranslator;
0051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0052: import org.netbeans.modules.uml.core.support.umlutils.IDataFormatter;
0053: import org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinition;
0054: import org.netbeans.modules.uml.core.support.umlutils.IPropertyElement;
0055: import org.netbeans.modules.uml.core.support.umlutils.IPropertyElementManager;
0056: import org.netbeans.modules.uml.ui.support.ProductHelper;
0057:
0058: /**
0059: * @author sumitabhk
0060: *
0061: */
0062: public class EditControlField implements IEditControlField {
0063: // temporary, contains the name of the property definition we wrap
0064: private String m_Name = "";
0065:
0066: private Color m_TextColor = null;
0067: private boolean m_Modified = false;
0068: private boolean m_Selected = false;
0069: private boolean m_Enabled = true;
0070: private boolean m_Deleted = false;
0071: private Font m_Font = null;
0072: private String m_Text = "";
0073: private String m_sDefaultText = "";
0074: private String m_inertSeparators = "";
0075: private char m_inertStart = 0;
0076: private char m_inertEnd = 0;
0077: private boolean m_separatorNavigable = true;
0078: private boolean m_VisibilityOverride = false; // override to force visibility off in spite of the visiblity rule
0079:
0080: private int m_FieldStartPos = 0;
0081: private int m_FieldEndPos = 0;
0082: private int m_TextStartPos = 0;
0083: private int m_TextEndPos = 0;
0084:
0085: private String m_ToolTip = "";
0086:
0087: // back pointer to the translator that contains this text field
0088: private ITranslator m_OwnerTranslator = null;
0089: // text fields can, instead of managing their text, instead manage a translator that contains more text fields
0090: private ITranslator m_Translator = null;
0091:
0092: // field appearance is controlled by a propertydefinition
0093: private IPropertyDefinition m_PropertyDefinition = null;
0094:
0095: // field data is managed by a propertyelement
0096: private IPropertyElement m_PropertyElement = null;
0097:
0098: private int m_Multiplicity = 1;
0099: private boolean m_bRequired = false;
0100: private boolean m_bDefault = false;
0101: private String m_Visibility = "notEmpty"; // visibility rule, e.g. "true", "notEmpty"
0102: private String m_Delimitor = "";
0103: private String m_LeadSep = "";
0104: private String m_TrailSep = "";
0105:
0106: private int /*TextFieldEditKind*/m_EditKind = 0;
0107:
0108: /**
0109: *
0110: */
0111: public EditControlField() {
0112: super ();
0113: }
0114:
0115: /**
0116: * Returns the full text contained by this TextField.
0117: *
0118: * @param[out] pVal The text
0119: *
0120: * @return HRESULT
0121: */
0122: public String getText() {
0123: String retText = "";
0124: if (m_Translator != null) {
0125: retText = m_Translator.getCurrent();
0126: } else {
0127: retText = m_Text;
0128: }
0129: return retText;
0130: }
0131:
0132: /**
0133: * Sets the text for this textfield.
0134: *
0135: * @param[in] newVal The new text string
0136: *
0137: * @return HRESULT
0138: *
0139: * @warning If this field is a proxy for a Translator, nothing occurs.
0140: * The proxy Translator is responsible for handling its own textfields.
0141: */
0142: public void setText(String newVal) {
0143: boolean modified = newVal.equals(m_Text) ? false : true;
0144: setModified(modified);
0145: m_Text = newVal;
0146:
0147: // force recalc of our position based on new text size
0148: setTextPos(m_TextStartPos);
0149: setFieldPos(m_FieldStartPos);
0150: }
0151:
0152: /**
0153: * Returns the font used for rendering this textfield.
0154: *
0155: * @param[out] pVal A FontDisp object describing the font
0156: *
0157: * @return HRESULT
0158: */
0159: public Font getFont() {
0160: return m_Font;
0161: }
0162:
0163: /**
0164: * Sets the font used for rendering this textfield.
0165: *
0166: * @param[in] newVal A FontDisp object describing the font
0167: *
0168: * @return HRESULT
0169: */
0170: public void setFont(Font newVal) {
0171: m_Font = newVal;
0172: }
0173:
0174: /**
0175: * Is this field selected? If so it rendered in the current selected color scheme.
0176: *
0177: * @param[out] bSelected TRUE or FALSE
0178: *
0179: * @return HRESULT
0180: */
0181: public boolean getSelected() {
0182: return m_Selected;
0183: }
0184:
0185: /**
0186: * Is this field selected? If so it rendered in the current selected color scheme.
0187: *
0188: * @param[in] bSelected TRUE or FALSE
0189: *
0190: * @return HRESULT
0191: */
0192: public void setSelected(boolean newVal) {
0193: m_Selected = newVal;
0194: }
0195:
0196: /**
0197: * Is this field Enabled? An enabled field is not necessarily visible, depending
0198: * on its visibility rules. However a disabled field is never visible.
0199: *
0200: * @param[out] bEnabled TRUE or FALSE
0201: *
0202: * @return HRESULT
0203: */
0204: public boolean getEnabled() {
0205: return m_Enabled;
0206: }
0207:
0208: /**
0209: * Is this field Enabled? An enabled field is not necessarily visible, depending
0210: * on its visibility rules. However a disabled field is never visible.
0211: *
0212: * @param[in] bEnabled TRUE or FALSE
0213: *
0214: * @return HRESULT
0215: */
0216: public void setEnabled(boolean newVal) {
0217: m_Enabled = newVal;
0218:
0219: if (m_Translator != null) {
0220: m_Translator.enableFields(newVal);
0221: }
0222: }
0223:
0224: /**
0225: * The field's text color.
0226: *
0227: * @param[out] pVal The current RGB color value
0228: *
0229: * @return HRESULT
0230: */
0231: public Color getTextColor() {
0232: return m_TextColor;
0233: }
0234:
0235: /**
0236: * The field's text color.
0237: *
0238: * @param[in] newVal The new RGB color value
0239: *
0240: * @return HRESULT
0241: */
0242: public void setTextColor(Color newVal) {
0243: m_TextColor = newVal;
0244: }
0245:
0246: /**
0247: * A helper function to initialize a TextField with one
0248: * function call. The modified flag is set to false.
0249: *
0250: * @param[in] sText The text value of this field
0251: * @param[in] Font The font in which to display the text
0252: * @param[in] textColor The color of the text
0253: *
0254: * @return HRESULT
0255: */
0256: public void init(String sText, Font font, Color textColor) {
0257: m_Text = sText;
0258: m_Font = font;
0259: m_TextColor = textColor;
0260: m_Modified = false;
0261: }
0262:
0263: /**
0264: * Returns the default text. Default text is commonly used when no user-defined
0265: * text has been entered, for example "un-named". The Default text is
0266: * not displayed unless SetDefaultText() has been called.
0267: *
0268: * @param[out] pVal The current value of this textfield's default text
0269: *
0270: * @return HRESULT
0271: */
0272: public String getDefaultText() {
0273: return m_sDefaultText;
0274: }
0275:
0276: /**
0277: * Sets the default text. Default text is commonly used when no user-defined
0278: * text has been entered, for example "un-named". The Default text
0279: * is not displayed unless SetDefaultText() has been called.
0280: *
0281: * @param[in] pVal The new value of this textfield's default text
0282: *
0283: * @return HRESULT
0284: */
0285: public void setDefaultText(String newVal) {
0286: m_sDefaultText = "";
0287: if (newVal != null && newVal.length() > 0) {
0288: m_sDefaultText = newVal;
0289: }
0290: }
0291:
0292: /**
0293: * Is this field visible? DOES NOT SEARCH SUB_FIELDS!
0294: *
0295: * @param[out] bVisible TRUE or FALSE
0296: *
0297: * @return HRESULT
0298: */
0299: public boolean getVisible() {
0300: // DO NOT SEARCH SUB_FIELDS! CALLER MUST ITERATE THROUGH SUB_FIELDS THEMSELVES!
0301: return isVisible();
0302: }
0303:
0304: /**
0305: * Forces the field to be visible.
0306: *
0307: * @param[in] bVisible TRUE or FALSE
0308: *
0309: * @return HRESULT
0310: */
0311: public void setVisible(boolean bVisible) {
0312: // if this field contains sub-fields you must set their visibility individually
0313: if (bVisible) {
0314: m_VisibilityOverride = true;
0315: m_Deleted = false;
0316: m_Enabled = true;
0317: setModified(true);
0318:
0319: // populate the field now that it's visible
0320: if (m_Text.length() == 0) {
0321: setDefaultText();
0322: }
0323:
0324: // HACK!!! We don't want every field's subfields to be set to visible because it could cause a nasty
0325: // recursion. However, we need multiplicity to activate (and mark modified) its subfields
0326: if (m_Name.equals("Multiplicity")) {
0327: if (m_Translator != null) {
0328: Vector subFields = m_Translator.getTextFields();
0329: if (subFields != null) {
0330: int count = subFields.size();
0331: for (int i = 0; i < count; i++) {
0332: IEditControlField field = (IEditControlField) subFields
0333: .elementAt(i);
0334: field.setVisible(true);
0335: }
0336: }
0337: }
0338: }
0339: } else {
0340: m_VisibilityOverride = false;
0341: }
0342: }
0343:
0344: /**
0345: * Is this field both visible and NOT deleted?
0346: *
0347: * @param[out] bVisible TRUE or FALSE
0348: *
0349: * @return HRESULT
0350: */
0351: public boolean getVisible2() {
0352: return isVisibleNotDeleted();
0353: }
0354:
0355: /**
0356: * Is this field visible and not deleted?
0357: *
0358: * @return TRUE if the field should be visible
0359: */
0360: private boolean isVisibleNotDeleted() {
0361: boolean bVisible = false;
0362: boolean deleted = getDeleted();
0363: if (!deleted) {
0364: bVisible = isVisible();
0365: }
0366: return bVisible;
0367: }
0368:
0369: /**
0370: * Is this field visible? Returns TRUE if
0371: *
0372: * 1. Visibility has been expressed set (via put_Visibility(TRUE))
0373: * 2. This field does not contain a translator but no data has been set (PropertyElement is NULL)
0374: * 3. The visibility rules are met, e.g.
0375: * if "true" then the field is always visible
0376: * if "notEmpty" then the field is visible if there is a value in its data or if
0377: * its translator returns a value
0378: * if "previousNotEmpty" then the field is visible if the preceeding field is visible
0379: *
0380: * @return TRUE if the field should be visible
0381: */
0382: private boolean isVisible() {
0383: boolean bVisible = false;
0384:
0385: // visibilityOverride is set programmatically to show a field that might not
0386: // otherwise be visible (eg it is empty)
0387: if (m_VisibilityOverride) {
0388: bVisible = true;
0389: bVisible = !(m_Visibility.equals("false"));
0390: } else {
0391: // if no data then the field can't be visible
0392: // can't use the propertyelement test b/c we may be looking at a field that hasn't been
0393: // initialized
0394: if (m_Enabled) {
0395: // process visibility rules
0396:
0397: // always true?
0398: bVisible = (m_Visibility.equals("true"));
0399:
0400: String text = getText();
0401:
0402: // visible contingent on our value
0403: if (!bVisible && m_Visibility.equals("notEmpty")) {
0404: // visible if "notEmpty" and our data has a value
0405: bVisible = (text.length() > 0);
0406: }
0407:
0408: if (m_Visibility.equals("previousNotEmpty")) {
0409: // here we have a visibility rule that is based on whether the preceeding field
0410: // contains text. Call the translator to get the preceeding field
0411: if (m_OwnerTranslator != null) {
0412: IEditControlField prevField = m_OwnerTranslator
0413: .getPreviousField(this );
0414: if (prevField != null) {
0415: String prevText = prevField.getText();
0416: bVisible = (prevText.length() > 0);
0417:
0418: if (m_Text.length() == 0) {
0419: setDefaultText();
0420: }
0421: }
0422: }
0423: }
0424: }
0425: }
0426:
0427: return bVisible;
0428: }
0429:
0430: /**
0431: * Forces the field to be visible AND sets its default text if the current field text is empty.
0432: *
0433: * @param[in] bVisible TRUE or FALSE
0434: *
0435: * @return HRESULT
0436: */
0437: public void setVisible2(boolean bVisible) {
0438: // if this field contains sub-fields you must set their visibility individually
0439: setVisible(bVisible);
0440: }
0441:
0442: /**
0443: * Returns the relative offsets of the beginning and end of
0444: * the text represented by this textfield. The
0445: * offsets are 0-base, relative to the 1st visible
0446: * character in the edit control. If the field is not visible nEndPos == nStartPos.
0447: *
0448: * @param[out] The starting position
0449: * @param[out] The ending position
0450: *
0451: * @return HRESULT
0452: */
0453: public int getTextPos(int nStartPos) {
0454: // TODO Auto-generated method stub
0455: return 0;
0456: }
0457:
0458: public int getTextStartPos() {
0459: int retPos = 0;
0460: if (m_Translator != null) {
0461: retPos = m_Translator.getTextStartPos();
0462: } else {
0463: retPos = m_TextStartPos;
0464: }
0465: return retPos;
0466: }
0467:
0468: public int getTextEndPos() {
0469: int retPos = 0;
0470: if (m_Translator != null) {
0471: retPos = m_Translator.getTextEndPos();
0472: } else {
0473: retPos = m_TextEndPos;
0474: }
0475: return retPos;
0476: }
0477:
0478: public int getLastTextStartPos() {
0479: int retPos = 0;
0480: if (m_Translator != null) {
0481: retPos = m_Translator.getLastTextStartPos();
0482: } else {
0483: retPos = m_TextStartPos;
0484: }
0485: return retPos;
0486: }
0487:
0488: /**
0489: * Sets the relative offsets for the beginning and end of the text
0490: * represented by this textfield. Call this function when
0491: * re-ordering fields, or after characters have been added or
0492: * removed from previous fields. If the field is not visible,
0493: * the field's length is set to zero.
0494: *
0495: * @param[in] The new starting offset
0496: *
0497: * @return HRESULT
0498: */
0499: public long setTextPos(int nStartPos) {
0500: if (m_Translator != null) {
0501: m_Translator.setFieldPos(nStartPos);
0502: } else {
0503: m_TextStartPos = nStartPos;
0504: if (isVisibleNotDeleted()) {
0505: int textOff = 0;
0506: if (m_Text != null) {
0507: textOff = m_Text.length();
0508: }
0509: m_TextEndPos = nStartPos + textOff;
0510: } else {
0511: m_TextEndPos = nStartPos;
0512: }
0513: }
0514: return 0;
0515: }
0516:
0517: /* (non-Javadoc)
0518: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getFieldPos(int)
0519: */
0520: public int getFieldPos(int nStartPos) {
0521: // TODO Auto-generated method stub
0522: return 0;
0523: }
0524:
0525: public int getFieldStartPos() {
0526: return m_FieldStartPos;
0527: }
0528:
0529: public int getFieldEndPos() {
0530: return m_FieldEndPos;
0531: }
0532:
0533: /**
0534: * Sets the relative offsets for the beginning and end of the text
0535: * represented by this textfield. Call this function when
0536: * re-ordering fields, or after characters have been added or
0537: * removed from previous fields. If the field is not visible,
0538: * the field's length is set to zero.
0539: *
0540: * @param[in] The new starting offset
0541: *
0542: * @return HRESULT
0543: */
0544: public long setFieldPos(int nStartPos) {
0545: m_FieldStartPos = nStartPos;
0546: if (m_Translator != null) {
0547: if (isVisible()) {
0548: int leadOff = 0;
0549: int trailOff = 0;
0550: if (m_LeadSep != null) {
0551: leadOff = m_LeadSep.length();
0552: }
0553: if (m_TrailSep != null) {
0554: trailOff = m_TrailSep.length();
0555: }
0556: m_Translator.setFieldPos(nStartPos + leadOff);
0557: int nStart = m_Translator.getFieldStartPos();
0558: int nEnd = m_Translator.getFieldEndPos();
0559: m_FieldEndPos = nEnd + trailOff;
0560: } else {
0561: m_Translator.setFieldPos(nStartPos);
0562: m_FieldEndPos = nStartPos;
0563: }
0564: } else {
0565: if (isVisibleNotDeleted()) {
0566: int leadOff = 0;
0567: int textOff = 0;
0568: int trailOff = 0;
0569: if (m_LeadSep != null) {
0570: leadOff = m_LeadSep.length();
0571: }
0572: if (m_Text != null) {
0573: textOff = m_Text.length();
0574: }
0575: if (m_TrailSep != null) {
0576: trailOff = m_TrailSep.length();
0577: }
0578: m_FieldEndPos = nStartPos + leadOff + textOff
0579: + trailOff;
0580: setTextPos(nStartPos + leadOff);
0581: } else {
0582: m_FieldEndPos = nStartPos;
0583: setTextPos(nStartPos);
0584: }
0585: }
0586: return 0;
0587: }
0588:
0589: /**
0590: * Fills the field's value with the default text. Some fields
0591: * may, if empty, upon activation be asked to fill
0592: * themselves with their default value, for example
0593: * "un-named". The application calls this method to cause the
0594: * field to set its value to its default value. The field is not
0595: * repositioned based on the new text length.
0596: *
0597: * @return HRESULT
0598: */
0599: public long setDefaultText() {
0600: if (!m_Text.equals(m_sDefaultText)) {
0601: m_Text = m_sDefaultText;
0602: setModified(true);
0603: }
0604: return 0;
0605: }
0606:
0607: /**
0608: * Returns the translator hosted by this text field. A text
0609: * field normally wraps text, however in some cases it is
0610: * desireable for the text field to contain a translator,
0611: * which in turn hosts a number of "sub" text fields.
0612: *
0613: * @param[out] pTranslator The Translator, if one has been set
0614: *
0615: * @return HRESULT
0616: */
0617: public ITranslator getTranslator() {
0618: return m_Translator;
0619: }
0620:
0621: /**
0622: * Sets the translator hosted by this text field. A text field
0623: * normally wraps text, however in some cases it is
0624: * desireable for the text field to contain a translator, which
0625: * in turn hosts a number of "sub" text fields.
0626: *
0627: * @param[in] pTranslator The Translator to delegate all text activity to
0628: *
0629: * @return HRESULT
0630: */
0631: public void setTranslator(ITranslator pTranslator) {
0632: m_Translator = pTranslator;
0633: }
0634:
0635: /**
0636: * Returns the translator that contains this text field. All text fields
0637: * are owned by a translator, which provides navigation and other
0638: * services to the edit control by manipulating its fields.
0639: *
0640: * @param[out] pTranslator The Owner Translator.
0641: *
0642: * @return HRESULT
0643: */
0644: public ITranslator getOwnerTranslator() {
0645: return m_OwnerTranslator;
0646: }
0647:
0648: /**
0649: * Sets the translator that contains this text field.
0650: *
0651: * @param[in] pTranslator The Translator that owns this textfield.
0652: *
0653: * @return HRESULT
0654: */
0655: public void setOwnerTranslator(ITranslator pTranslator) {
0656: m_OwnerTranslator = pTranslator;
0657: }
0658:
0659: /**
0660: *
0661: * Has this field's text been modified?
0662: *
0663: * @param bModified[out]
0664: *
0665: * @return HRESULT
0666: *
0667: */
0668: public boolean getModified() {
0669: boolean pModified = false;
0670: if (m_Translator != null) {
0671: pModified = m_Translator.getModified();
0672: } else {
0673: pModified = m_Modified;
0674: }
0675: return pModified;
0676: }
0677:
0678: /**
0679: *
0680: * Force's this field's modified status.
0681: *
0682: * @param bModified[in] The new modified value.
0683: *
0684: * @return HRESULT
0685: *
0686: */
0687: public void setModified(boolean bModified) {
0688: m_Modified = bModified;
0689:
0690: // notify parent only if we are becoming modified
0691: if (m_OwnerTranslator != null && m_Modified) {
0692: m_OwnerTranslator.setModified(bModified);
0693: }
0694: }
0695:
0696: /**
0697: *
0698: * The value of this text field's tooltip.
0699: *
0700: * @param pVal[out] Tooltip.
0701: *
0702: * @return HRESULT
0703: *
0704: */
0705: public String getToolTipText() {
0706: return m_ToolTip;
0707: }
0708:
0709: /**
0710: *
0711: * The value of this text field's tooltip.
0712: *
0713: * @param pVal[in] Tooltip.
0714: *
0715: * @return HRESULT
0716: *
0717: */
0718: public void setToolTipText(String newVal) {
0719: if (m_Translator == null) {
0720: m_ToolTip = newVal;
0721: }
0722: }
0723:
0724: /* (non-Javadoc)
0725: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getMultiplicity()
0726: */
0727: public boolean getMultiplicity() {
0728: boolean retVal = false;
0729: if (m_Multiplicity != 0) {
0730: retVal = true;
0731: }
0732: return retVal;
0733: }
0734:
0735: /* (non-Javadoc)
0736: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setMultiplicity(boolean)
0737: */
0738: public void setMultiplicity(boolean newVal) {
0739: if (newVal) {
0740: m_Multiplicity = -1;
0741: } else {
0742: m_Multiplicity = 1;
0743: }
0744: }
0745:
0746: /* (non-Javadoc)
0747: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getRequired()
0748: */
0749: public boolean getRequired() {
0750: return m_bRequired;
0751: }
0752:
0753: /* (non-Javadoc)
0754: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setRequired(boolean)
0755: */
0756: public void setRequired(boolean newVal) {
0757: m_bRequired = newVal;
0758: }
0759:
0760: /* (non-Javadoc)
0761: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getDefault()
0762: */
0763: public boolean getDefault() {
0764: return m_bDefault;
0765: }
0766:
0767: /* (non-Javadoc)
0768: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setDefault(boolean)
0769: */
0770: public void setDefault(boolean newVal) {
0771: m_bDefault = newVal;
0772: }
0773:
0774: /* (non-Javadoc)
0775: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getVisibility()
0776: */
0777: public String getVisibility() {
0778: return m_Visibility;
0779: }
0780:
0781: /* (non-Javadoc)
0782: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setVisibility(java.lang.String)
0783: */
0784: public void setVisibility(String newVal) {
0785: m_Visibility = newVal;
0786: }
0787:
0788: /* (non-Javadoc)
0789: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getLeadSeparator()
0790: */
0791: public String getLeadSeparator() {
0792: return m_LeadSep;
0793: }
0794:
0795: /* (non-Javadoc)
0796: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setLeadSeparator(java.lang.String)
0797: */
0798: public void setLeadSeparator(String newVal) {
0799: m_LeadSep = newVal;
0800: }
0801:
0802: /* (non-Javadoc)
0803: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getTrailSeparator()
0804: */
0805: public String getTrailSeparator() {
0806: return m_TrailSep;
0807: }
0808:
0809: /* (non-Javadoc)
0810: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setTrailSeparator(java.lang.String)
0811: */
0812: public void setTrailSeparator(String newVal) {
0813: m_TrailSep = newVal;
0814: }
0815:
0816: /* (non-Javadoc)
0817: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getDelimitor()
0818: */
0819: public String getDelimitor() {
0820: return m_Delimitor;
0821: }
0822:
0823: /* (non-Javadoc)
0824: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setDelimitor(java.lang.String)
0825: */
0826: public void setDelimitor(String newVal) {
0827: m_Delimitor = newVal;
0828: }
0829:
0830: /* (non-Javadoc)
0831: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getPropertyElement()
0832: */
0833: public IPropertyElement getPropertyElement() {
0834: return m_PropertyElement;
0835: }
0836:
0837: /* (non-Javadoc)
0838: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setPropertyElement(org.netbeans.modules.uml.core.support.umlutils.IPropertyElement)
0839: */
0840: public void setPropertyElement(IPropertyElement pEle) {
0841: m_PropertyElement = pEle;
0842: m_Deleted = false;
0843:
0844: // enable by virtue that we have a propelement, but setting the definition
0845: // below might disable
0846: m_Enabled = true;
0847:
0848: // read the property element's data
0849: if (pEle != null) {
0850: // apply formatting to this value
0851: IPropertyDefinition pDef = null;
0852: if (m_PropertyDefinition == null) {
0853: pDef = m_PropertyElement.getPropertyDefinition();
0854: if (pDef != null) {
0855: setPropertyDefinition(pDef);
0856: }
0857: }
0858:
0859: // fetch the data value if any
0860: String sValue = pEle.getValue();
0861: if (sValue != null && sValue.length() > 0) {
0862: if (pDef != null) {
0863: String validVals = pDef.getValidValues();
0864: if (validVals != null) {
0865: int pos = validVals.indexOf("|");
0866: if (pos >= 0) {
0867: StringTokenizer tokenizer = new StringTokenizer(
0868: validVals, "|");
0869: int count = tokenizer.countTokens();
0870: try {
0871: int val = Integer.valueOf(sValue)
0872: .intValue();
0873: int index = 0;
0874: while (tokenizer.hasMoreTokens()) {
0875: String token = tokenizer
0876: .nextToken();
0877: if (index == val) {
0878: IConfigStringTranslator translator = ConfigStringHelper
0879: .instance()
0880: .getTranslator();
0881: sValue = translator.translate(
0882: pDef, token);
0883: break;
0884: }
0885: index++;
0886: }
0887: } catch (NumberFormatException e) {
0888: }
0889: }
0890: }
0891: }
0892: m_Text = sValue;
0893:
0894: // enable if there's a value. We might need to enable regardless since we have data
0895: // NOTE this doesn't work b/c we might be a container for subelements, thus our
0896: // value might be empty but we need to be enabled anyway.
0897: m_Enabled = true;
0898: }
0899:
0900: // enable since we have data
0901: m_Enabled = true;
0902:
0903: // At this point we are done with a normal text field. But for fields that contain subfields
0904: // we need to process each subfield. A subfield PropertyDefinition should already exist for
0905: // these fields.
0906:
0907: // if we have subelements, nest them within a new translator (created during put_PropertyDefinition())
0908: Vector subEles = pEle.getSubElements();
0909: if (subEles != null) {
0910: int count = subEles.size();
0911: if (count > 0) {
0912: // we have a nested field situation here, our "text" doesn't mean anything
0913: m_Text = "";
0914:
0915: // m_pTranslator is for holding the sub-definitions
0916: if (m_Translator != null) {
0917: Object obj = m_PropertyElement.getElement();
0918: if (obj instanceof IElement) {
0919: IElement pME = (IElement) obj;
0920: m_Translator.setElement(pME);
0921: }
0922:
0923: for (int i = 0; i < count; i++) {
0924: IPropertyElement subEle = (IPropertyElement) subEles
0925: .elementAt(i);
0926: m_Translator.addField(subEle, false);
0927: }
0928:
0929: // retrieve our built up text for determination of visibility status
0930: //sText = m_Translator.getCurrent();
0931: }
0932: }
0933: }
0934: }
0935: }
0936:
0937: /* (non-Javadoc)
0938: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setPropertyElement2(org.netbeans.modules.uml.core.support.umlutils.IPropertyElement)
0939: */
0940: public void setPropertyElement2(IPropertyElement pEle) {
0941: m_PropertyElement = pEle;
0942:
0943: // read the property element's data
0944: if (m_PropertyElement != null) {
0945: // enable if there's a value. We might need to enable regardless since we have data
0946: m_Enabled = true;
0947:
0948: // At this point we are done with a normal text field. But for fields that contain subfields
0949: // we need to process each subfield. A subfield PropertyDefinition should already exist for
0950: // these fields.
0951:
0952: // if we have subelements, nest them within a new translator (created during put_PropertyDefinition())
0953: Vector subEles = m_PropertyElement.getSubElements();
0954: if (subEles != null) {
0955: int count = subEles.size();
0956: if (count > 0) {
0957: // m_pTranslator is for holding the sub-definitions
0958: if (m_Translator != null) {
0959: m_Translator.updateFields(subEles);
0960: }
0961: }
0962: }
0963: }
0964: }
0965:
0966: /* (non-Javadoc)
0967: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getPropertyDefinition()
0968: */
0969: public IPropertyDefinition getPropertyDefinition() {
0970: return m_PropertyDefinition;
0971: }
0972:
0973: /* (non-Javadoc)
0974: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#setPropertyDefinition(org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinition)
0975: */
0976: public void setPropertyDefinition(IPropertyDefinition pDef) {
0977: m_PropertyDefinition = pDef;
0978:
0979: // read the property element's data
0980: if (pDef != null) {
0981: String sName = pDef.getName();
0982: m_Name = sName;
0983:
0984: String sRequired = pDef.getFromAttrMap("required");
0985: String sDefault = pDef.getFromAttrMap("default");
0986: String sVisible = pDef.getFromAttrMap("visible");
0987: String sMultiplicity = pDef.getFromAttrMap("multiplicity");
0988: String sDelimitor = pDef.getFromAttrMap("delimitor");
0989: String sLead = pDef.getFromAttrMap("leadSeparator");
0990: String sTrail = pDef.getFromAttrMap("trailSeparator");
0991: String sTooltip = pDef.getFromAttrMap("toolTip");
0992: String sType = pDef.getFromAttrMap("controlType");
0993: String sEnabled = pDef.getFromAttrMap("enabled");
0994: String separatorNavigable = pDef
0995: .getFromAttrMap("separatorNavigable");
0996: String inertSeparators = pDef
0997: .getFromAttrMap("inertSeparators");
0998: String inertStart = pDef.getFromAttrMap("inertStart");
0999: String inertEnd = pDef.getFromAttrMap("inertEnd");
1000:
1001: // temporary until default values are worked out
1002: sName = pDef.getFromAttrMap("dummyDefaultValue");
1003: if (sName != null) {
1004: m_sDefaultText = sName;
1005: }
1006:
1007: if (pDef.isDefaultExisting()) {
1008: sName = pDef.getDefaultValue();
1009: m_sDefaultText = sName;
1010: }
1011: // don't set default text here otherwise the field might become visible
1012: // m_sText = m_sDefaultText;
1013:
1014: if (sMultiplicity != null) {
1015: try {
1016: m_Multiplicity = Integer.valueOf(sMultiplicity)
1017: .intValue();
1018: } catch (NumberFormatException e) {
1019: m_Multiplicity = 0;
1020: }
1021: }
1022:
1023: if (sRequired != null) {
1024: m_bRequired = (sRequired.equals("true"));
1025: }
1026:
1027: if (sEnabled != null) {
1028: m_Enabled = (sEnabled.equals("true"));
1029: }
1030:
1031: if (sDefault != null) {
1032: m_bDefault = (sDefault.equals("true"));
1033: }
1034:
1035: m_Delimitor = sDelimitor;
1036: m_LeadSep = sLead;
1037: m_TrailSep = sTrail;
1038: m_Visibility = sVisible;
1039: m_inertSeparators = inertSeparators;
1040: m_inertStart = (inertStart != null && inertStart.length() > 0) ? inertStart
1041: .charAt(0)
1042: : 0;
1043: m_inertEnd = (inertEnd != null && inertEnd.length() > 0) ? inertEnd
1044: .charAt(0)
1045: : 0;
1046:
1047: if (separatorNavigable != null) {
1048: m_separatorNavigable = !(separatorNavigable
1049: .equals("false"));
1050: }
1051:
1052: if (m_Visibility == null || m_Visibility.length() == 0) {
1053: m_Visibility = "notEmpty";
1054: }
1055:
1056: m_EditKind = ITextFieldEditKind.TFEK_DEFAULT;
1057: if (sType != null && sType.equals("read-only")) {
1058: m_EditKind = ITextFieldEditKind.TFEK_READONLY;
1059: } else if (sType != null && sType.equals("list")) {
1060: m_EditKind = ITextFieldEditKind.TFEK_LIST;
1061: } else if (sType != null && sType.equals("combo")) {
1062: m_EditKind = ITextFieldEditKind.TFEK_COMBO;
1063: }
1064:
1065: // need to convert tt to verbose text
1066: IConfigStringTranslator pTranslator = ConfigStringHelper
1067: .instance().getTranslator();
1068: String sValue = pTranslator.translate(pDef, sTooltip);
1069:
1070: m_ToolTip = "";
1071: if (sLead != null) {
1072: m_ToolTip = sLead;
1073: }
1074: if (sValue != null) {
1075: m_ToolTip += sValue;
1076: }
1077: if (m_Multiplicity != 1) {
1078: if (m_Delimitor != null) {
1079: m_ToolTip += m_Delimitor;
1080: m_ToolTip += "...";
1081: }
1082:
1083: if (m_Multiplicity > 1) {
1084: //String str = StringUtilities.Format( _T("[%d]"), m_nMultiplicity );
1085: m_ToolTip += "0.." + m_Multiplicity;
1086: }
1087: }
1088: if (sTrail != null) {
1089: m_ToolTip += sTrail;
1090: }
1091:
1092: // Check for subdefinitions, these will define nested fields
1093: Vector subDefs = pDef.getSubDefinitions();
1094: if (subDefs != null) {
1095: int count = subDefs.size();
1096: if (count > 0) {
1097: m_Translator = new TranslatorImpl();
1098: m_Translator.setParentField(this );
1099: for (int i = 0; i < count; i++) {
1100: IPropertyDefinition subDef = (IPropertyDefinition) subDefs
1101: .elementAt(i);
1102: m_Translator.addFieldDefinition(subDef, null);
1103: }
1104: }
1105: }
1106: }
1107: }
1108:
1109: /**
1110: *
1111: * Saves the textfield's value, if modified.
1112: *
1113: *
1114: * @return
1115: *
1116: */
1117: public boolean save() {
1118: boolean bCancel = false;
1119:
1120: boolean bDeleted = getDeleted2();
1121: boolean bModified = getModified();
1122:
1123: // here we determine what actions we're going to take
1124: // special case, what if it's not modified, required and empty?
1125: // if a propelem exists it should be whacked.
1126:
1127: // if it's modified, no propelem exists, but it's required and empty?
1128: // the propelem should not be invented.
1129: boolean bDelete = false;
1130: boolean bSave = true;
1131:
1132: // test if this field is tagged "required" but is empty
1133: String sText = getText();
1134: if (m_bRequired && (sText == null || sText.length() == 0)) {
1135: bDeleted = true;
1136: }
1137:
1138: // if it's deleted do we need to whack the property element
1139: if (bDeleted) {
1140: bSave = false;
1141: if (m_PropertyElement != null) {
1142: bDelete = true;
1143: }
1144: }
1145:
1146: // perform the save
1147: if (bDelete) {
1148: // caution here! this guy was tagged as "required" by the parent, he's empty so we whack the parent
1149: if (m_OwnerTranslator != null) {
1150: IEditControlField pField = m_OwnerTranslator
1151: .getParentField();
1152: if (pField != null) {
1153: IPropertyElement pOwner = pField
1154: .getPropertyElement();
1155: if (pOwner != null) {
1156: pOwner.remove();
1157: }
1158: }
1159: } else {
1160: // should never occur
1161: if (m_PropertyElement != null) {
1162: m_PropertyElement.remove();
1163: }
1164: }
1165: } else if (bModified && bSave) {
1166: // can we have a situation where we should save even when not modified?
1167:
1168: // test if ever saved before. This part creates a new property element for a
1169: // element that is new, e.g. a parameter, multiplicity range, etc.
1170: if (m_PropertyElement == null) {
1171: // new field, create a property element for it
1172: if (m_PropertyDefinition != null) {
1173: // never saved before, create a new propertyelement
1174: if (m_OwnerTranslator != null) {
1175: IDataFormatter pFormatter = ProductHelper
1176: .getDataFormatter();
1177: if (pFormatter != null) {
1178: IPropertyElementManager pManager = pFormatter
1179: .getElementManager();
1180: if (pManager != null) {
1181: String name = m_PropertyDefinition
1182: .getName();
1183:
1184: // this builds the property elements for this definition
1185: m_PropertyElement = pManager
1186: .buildTopPropertyElement(m_PropertyDefinition);
1187: if (m_PropertyElement != null) {
1188: // m_PropertyElement = pManager.buildElement(null, m_PropertyDefinition, null);
1189: // tell our new Property Element about its parent
1190: if (m_OwnerTranslator != null) {
1191: IEditControlField pField = m_OwnerTranslator
1192: .getParentField();
1193: if (pField != null) {
1194: IPropertyElement propEle = pField
1195: .getPropertyElement();
1196: if (propEle != null) {
1197: m_PropertyElement
1198: .setParent(propEle);
1199: }
1200: }
1201: }
1202:
1203: // calling Save() now will actually create model elements
1204: boolean saved = m_PropertyElement
1205: .save();
1206:
1207: // attach all placeholder property subdefinitions with their subelements
1208: setPropertyElement2(m_PropertyElement);
1209: }
1210: }
1211: }
1212: }
1213: }
1214: }
1215:
1216: // this part writes the new data
1217: if (m_Translator != null) {
1218: String str = "";
1219: IElement pEle = m_Translator.getElement();
1220: if (pEle != null) {
1221: str = pEle.getElementType();
1222: }
1223:
1224: m_Translator.saveFields();
1225: if (m_PropertyElement != null) {
1226: m_PropertyElement.save();
1227: }
1228: } else {
1229: if (m_PropertyElement != null) {
1230: String name = m_PropertyElement.getName();
1231: String value = m_PropertyElement.getValue();
1232: String newVal = m_Text;
1233:
1234: //if this is one of the property elements which have
1235: //to be one of the valid values, m_Text will be the display
1236: //value and not one of the values to store. So convert back
1237: if (m_PropertyDefinition != null) {
1238: String vals = m_PropertyDefinition
1239: .getValidValues();
1240: if (vals != null) {
1241: int pos = vals.indexOf("|");
1242: if (pos >= 0) {
1243: StringTokenizer tokenizer = new StringTokenizer(
1244: vals, "|");
1245: int index = 0;
1246: while (tokenizer.hasMoreTokens()) {
1247: String token = tokenizer
1248: .nextToken();
1249: IConfigStringTranslator trans = ConfigStringHelper
1250: .instance().getTranslator();
1251: String transToken = trans
1252: .translate(
1253: m_PropertyDefinition,
1254: token);
1255: if (transToken.equals(m_Text)) {
1256: newVal = token;
1257: break;
1258: }
1259: index++;
1260: }
1261: }
1262: }
1263: }
1264:
1265: if (!newVal.equals(value)) {
1266: value = newVal;
1267: if (value == null || value.length() == 0) {
1268: value = "";
1269: }
1270: m_PropertyElement.setValue(value);
1271: m_PropertyElement.save();
1272: }
1273: // HACK!!!
1274: // MultiplicityRanges needs to be able to understand what an empty value means.
1275: else if (name.equals("MultiplicityRanges")) {
1276: m_PropertyElement.setValue("*");
1277: m_PropertyElement.save();
1278: }
1279: }
1280: }
1281: }
1282:
1283: setModified(false);
1284:
1285: return bCancel;
1286: }
1287:
1288: /**
1289: *
1290: * Returns a list of valid values for a list or combo type edit kind. The list must be released by the
1291: * caller
1292: *
1293: * @param [out] A list of strings
1294: *
1295: * @return HRESULT
1296: *
1297: */
1298: public Vector getValidValues() {
1299: Vector list = new Vector();
1300: if (m_PropertyElement != null) {
1301: // apply formatting to this value
1302: IPropertyDefinition pDef = m_PropertyElement
1303: .getPropertyDefinition();
1304: if (pDef != null) {
1305: String validVals = pDef.getValidValues();
1306: if (validVals != null && validVals.indexOf("#") >= 0) {
1307: validVals = pDef.getValidValues2();
1308: }
1309:
1310: if (validVals.indexOf("|") >= 0) {
1311: StringTokenizer tokenizer = new StringTokenizer(
1312: validVals, "|");
1313: while (tokenizer.hasMoreTokens()) {
1314: String str = tokenizer.nextToken();
1315: list.add(str);
1316: }
1317: }
1318: }
1319: }
1320: return list;
1321: }
1322:
1323: /**
1324: *
1325: * Determines if the character matches the leading separator, thereby becoming a "shortcut" to this field.
1326: *
1327: * @param nChar [in] The character keycode.
1328: * @param bIsSeparator [out, retval] TRUE is the character is a separator.
1329: *
1330: * @return HRESULT
1331: *
1332: */
1333: public boolean isLeadSeparator(int nChar) {
1334: boolean bIsSeparator = false;
1335: if (m_LeadSep != null) {
1336: int pos = m_LeadSep.indexOf(nChar);
1337: if (pos >= 0) {
1338: bIsSeparator = true;
1339: }
1340: }
1341: return bIsSeparator;
1342: }
1343:
1344: /**
1345: *
1346: * Determines if the character matches the trailing separator, thereby becoming a "shortcut" to this field.
1347: *
1348: * @param nChar [in] The character keycode.
1349: * @param bIsSeparator [out, retval] TRUE is the character is a separator.
1350: *
1351: * @return HRESULT
1352: *
1353: */
1354: public boolean isTrailSeparator(int nChar) {
1355: boolean bIsSeparator = false;
1356: if (m_TrailSep != null) {
1357: int pos = m_TrailSep.indexOf(nChar);
1358: if (pos >= 0) {
1359: bIsSeparator = true;
1360: }
1361: }
1362: return bIsSeparator;
1363: }
1364:
1365: /**
1366: * Is the character a delimitor for repeating fields?
1367: *
1368: * @param nChar [in] The character to check.
1369: * @param bIsDelimitor [out,retval] TRUE if the field contains sub-fields and the
1370: * character is one of the delimitor characters.
1371: *
1372: * @return HRESULT
1373: */
1374: public boolean isDelimitor(int nChar) {
1375: boolean bIsDelimitor = false;
1376:
1377: // if a repeating field, check for the delimitor
1378: if (isVisibleNotDeleted() && m_Multiplicity != 1) {
1379: // could be tricky here, need to know where the caret is
1380: // <leadSep><1st Field><delim><2nd Field><delim><3rd Field><trailSep>
1381: if (m_Delimitor != null) {
1382: int pos = m_Delimitor.indexOf(nChar);
1383: if (pos >= 0) {
1384: bIsDelimitor = true;
1385: }
1386: }
1387: }
1388:
1389: return bIsDelimitor;
1390: }
1391:
1392: /**
1393: * Is this field deleted?
1394: *
1395: * @param[out] bDeleted TRUE or FALSE
1396: *
1397: * @return HRESULT
1398: */
1399: public boolean getDeleted() {
1400: return m_Deleted;
1401: }
1402:
1403: /**
1404: * Is this field deleted?
1405: *
1406: * @param[in] bDeleted TRUE or FALSE
1407: *
1408: * @return HRESULT
1409: */
1410: public void setDeleted(boolean value) {
1411: if (m_Translator != null) {
1412: m_Translator.setDeleted(value);
1413: } else {
1414: m_Deleted = value;
1415: if (m_Deleted) {
1416: setText("");
1417: }
1418: }
1419: }
1420:
1421: /**
1422: * Is this field and all sub-fields deleted?
1423: *
1424: * @param[out] bDeleted TRUE or FALSE
1425: *
1426: * @return HRESULT
1427: */
1428: public boolean getDeleted2() {
1429: boolean deleted = false;
1430: // can't call translator's get_deleted b/c we might be a container that
1431: // has no fields or all deleted fields, but that doesn't make us deleted.
1432: if (m_Translator != null) {
1433: deleted = m_Translator.getDeleted();
1434: } else {
1435: deleted = getDeleted();
1436: }
1437: return deleted;
1438: }
1439:
1440: /**
1441: * Updates the field according to its visibility and validation rules.
1442: *
1443: * @param[in] <Name Description>
1444: *
1445: * @return HRESULT
1446: */
1447: public long update() {
1448: if (m_Translator != null) {
1449: m_Translator.updateField(null);
1450: } else {
1451: m_VisibilityOverride = false;
1452: if (m_bRequired && m_Text.length() == 0) {
1453: setDeleted(true);
1454: }
1455: }
1456: return 0;
1457: }
1458:
1459: /**
1460: *
1461: * Retrieves this textfields edit kind, e.g. default (stringified text), list (a list of values) or combo
1462: *
1463: * @param [out] The TextFieldEditKind
1464: *
1465: * @return HRESULT
1466: *
1467: */
1468: public int getEditKind() {
1469: return m_EditKind;
1470: }
1471:
1472: /* (non-Javadoc)
1473: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#dump(java.lang.String)
1474: */
1475: public long dump(String sPad) {
1476: // TODO Auto-generated method stub
1477: return 0;
1478: }
1479:
1480: /* (non-Javadoc)
1481: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#getName()
1482: */
1483: public String getName() {
1484: return m_Name;
1485: }
1486:
1487: /* (non-Javadoc)
1488: * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlField#checkInertSeparator(int)
1489: */
1490: public boolean checkInertSeparator(int nChar, int absolutePosition) {
1491: boolean pInert = false;
1492: if (m_inertSeparators != null) {
1493: if (m_inertSeparators.equals("*")) {
1494: pInert = true;
1495: return pInert;
1496: }
1497:
1498: if (inInertBracket(absolutePosition)) {
1499: int pos = m_inertSeparators.indexOf(nChar);
1500: if (pos >= 0) {
1501: pInert = true;
1502: return pInert;
1503: }
1504: }
1505: }
1506:
1507: if (m_Translator != null) {
1508: IEditControlField subField = m_Translator.getCurrentField();
1509: if (subField != null) {
1510: pInert = subField.checkInertSeparator(nChar,
1511: absolutePosition);
1512: }
1513: }
1514: return pInert;
1515: }
1516:
1517: private boolean inInertBracket(int absolutePosition) {
1518: // no inert start/end char defined assume in bracket if inertSeparators is defined
1519: if (m_inertStart == 0 || m_inertEnd == 0) {
1520: return true;
1521: }
1522:
1523: int startCount = 0;
1524: int endCount = 0;
1525: int pos = absolutePosition - getFieldStartPos() - 1;
1526: char[] chars = m_Text.toCharArray();
1527: for (int i = pos - 1; i >= 0; i--) {
1528: char c = chars[i];
1529: if (c == m_inertStart) {
1530: startCount++;
1531: } else if (c == m_inertEnd) {
1532: endCount++;
1533: }
1534: }
1535: return (startCount - endCount) > 0;
1536: }
1537: }
|