org.tizen.nativecpp.setting_1.0.0.201311042022

   okButton = createButton(parent, 0, IDialogConstants.OK_LABEL, true);
    createButton(parent, 1, IDialogConstants.CANCEL_LABEL, false);
  }
  
  protected Control createDialogArea(Composite parent)
  {
    container = ((Composite)super.createDialogArea(parent));
    
    GridLayout gridLayout = new GridLayout();
    numColumns = 2;
    container.setLayout(gridLayout);
    
    Label typeLabel = new Label(container, 0);
    typeLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    typeLabel.setText("Type:");
    
    typeField = new Combo(container, 8);
    typeField.setLayoutData(new GridData(4, 
      2, false, false));
    
    typeField.add("bool");
    typeField.add("expandlist");
    typeField.add("group");
    typeField.add("integer");
    typeField.add("label");
    typeField.add("launch");
    typeField.add("string");
    
    typeField.setVisibleItemCount(3);
    
    typeField.select(3);
    elementType = ElementType.integer;
    type = typeField.getText();
    
    typeField.addSelectionListener(new TypeSelectionListener(null));
    
    Label idLabel = new Label(container, 0);
    idLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    idLabel.setText("Id:");
    
    idField = new Text(container, 2048);
    idField.setLayoutData(new GridData(4, 2, 
      true, false));
    
    Label titleLabel = new Label(container, 0);
    titleField = new Text(container, 2048);
    
    titleLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    titleLabel.setText("Title:");
    titleLabel.setSize(50, getSizey);
    titleField.setLayoutData(new GridData(4, 2, 
      true, false));
    
    makeMinControls();
    makeMaxControls();
    makeValueControls();
    
    errorMessageIcon = new Label(container, 0);
    GridData gd = new GridData(3, 2, false, false);
    verticalSpan = 10;
    
    errorMessageIcon.setLayoutData(gd);
    errorMessageIcon.setImage(null);
    
    errorMessageLabel = new Label(container, 64);
    errorMessageLabel.setText("");
    
    gd = new GridData(4, 2, false, false);
    verticalSpan = 10;
    widthHint = 280;
    
    errorMessageLabel.setLayoutData(gd);
    Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0);
    errorMessageLabel.setForeground(color);
    
    initContent();
    
    return container;
  }
  
  private class TypeSelectionListener
    implements SelectionListener
  {
    private TypeSelectionListener() {}
    
    public void widgetSelected(SelectionEvent e)
    {
      type = typeField.getText();
      elementType = ElementUtil.checkType(type);
      if (type.equals("expandlist"))
      {
        Shell shell = getShell();
        if (dialogDefaultSize == null) {
          dialogDefaultSize = shell.getSize();
        }
        AddSettingChildElementDialog.this.disposeControl(true, true, true, true);
        if (fieldSize == null) {
          fieldSize = idField.getSize();
        }
        AddSettingChildElementDialog.this.clearTextField();
        AddSettingChildElementDialog.this.clearErrorList();
        
        errorMessageIcon.moveBelow(titleField);
        errorMessageLabel.moveBelow(errorMessageIcon);
        
        Point size = new Point(dialogDefaultSize.x, dialogDefaultSize.y - 
          2 * fieldSize.y);
        
        container.layout();
        
        shell = getShell();
        shell.setSize(size);
      }
      else if (type.equals("integer"))
      {
        Shell shell = getShell();
        
        AddSettingChildElementDialog.this.disposeControl(false, true, false, true);
        if (dialogDefaultSize == null) {
          dialogDefaultSize = shell.getSize();
        }
        if ((minField.isDisposed()) && (minLabel.isDisposed())) {
          AddSettingChildElementDialog.this.makeMinControls();
        }
        if ((maxField.isDisposed()) && (maxLabel.isDisposed())) {
          AddSettingChildElementDialog.this.makeMaxControls();
        }
        if ((valueField.isDisposed()) && (valueLabel.isDisposed())) {
          AddSettingChildElementDialog.this.makeValueControls();
        }
        minLabel.setText("Min:");
        maxLabel.setText("Max:");
        
        valueLabel.moveBelow(maxField);
        valueField.moveBelow(valueLabel);
        
        AddSettingChildElementDialog.this.clearTextField();
        AddSettingChildElementDialog.this.clearErrorList();
        
        errorMessageIcon.moveBelow(valueField);
        errorMessageLabel.moveBelow(errorMessageIcon);
        
        container.layout();
        shell.setSize(dialogDefaultSize);
      }
      else if (type.equals("string"))
      {
        Shell shell = getShell();
        
        AddSettingChildElementDialog.this.disposeControl(false, true, false, true);
        if (dialogDefaultSize == null) {
          dialogDefaultSize = shell.getSize();
        }
        if ((minField.isDisposed()) && (minLabel.isDisposed())) {
          AddSettingChildElementDialog.this.makeMinControls();
        }
        if ((maxField.isDisposed()) && (maxLabel.isDisposed())) {
          AddSettingChildElementDialog.this.makeMaxControls();
        }
        if ((valueField.isDisposed()) && (valueLabel.isDisposed())) {
          AddSettingChildElementDialog.this.makeValueControls();
        }
        minLabel.setText("MinLength:");
        maxLabel.setText("MaxLength:");
        
        valueLabel.moveBelow(maxField);
        valueField.moveBelow(valueLabel);
        
        AddSettingChildElementDialog.this.clearTextField();
        AddSettingChildElementDialog.this.clearErrorList();
        
        errorMessageIcon.moveBelow(valueField);
        errorMessageLabel.moveBelow(errorMessageIcon);
        
        container.layout();
        
        Point size = new Point(dialogDefaultSize.x + (minLabel.getSize().x - valueLabel.getSize().x), dialogDefaultSize.y);
        
        shell.setSize(size);
      }
      else if (type.equals("bool"))
      {
        Shell shell = getShell();
        if (dialogDefaultSize == null) {
          dialogDefaultSize = shell.getSize();
        }
        AddSettingChildElementDialog.this.disposeControl(true, false, true, true);
        if (fieldSize == null) {
          fieldSize = idField.getSize();
        }
        if ((boolValueField == null) || ((boolValueField.isDisposed()) && (valueLabel2.isDisposed()))) {
          AddSettingChildElementDialog.this.makeBoolCombo();
        }
        AddSettingChildElementDialog.this.clearTextField();
        AddSettingChildElementDialog.this.clearErrorList();
        
        errorMessageIcon.moveBelow(boolValueField);
        errorMessageLabel.moveBelow(errorMessageIcon);
        
        Point size = new Point(dialogDefaultSize.x, dialogDefaultSize.y - 
          2 * fieldSize.y);
        
        container.layout();
        
        shell = getShell();
        shell.setSize(size);
      }
      else if (type.equals("launch"))
      {
        Shell shell = getShell();
        if (dialogDefaultSize == null) {
          dialogDefaultSize = shell.getSize();
        }
        if (fieldSize == null) {
          fieldSize = idField.getSize();
        }
        AddSettingChildElementDialog.this.disposeControl(true, true, true, false);
        if ((appIdField.isDisposed()) && (appIdLabel.isDisposed()) && (operationLabel.isDisposed()) && (operationField.isDisposed()))
        {
          AddSettingChildElementDialog.this.makeAppIdControls();
          AddSettingChildElementDialog.this.makeOperationControls();
        }
        errorMessageIcon.moveBelow(operationField);
        errorMessageLabel.moveBelow(errorMessageIcon);
        
        AddSettingChildElementDialog.this.clearTextField();
        AddSettingChildElementDialog.this.clearErrorList();
        
        Point size = new Point(dialogDefaultSize.x + (operationLabel.getSize().x - appIdLabel.getSize().x), 
          dialogDefaultSize.y - fieldSize.y);
        container.layout();
        shell.setSize(size);
      }
      else
      {
        Shell shell = getShell();
        if (dialogDefaultSize == null) {
          dialogDefaultSize = shell.getSize();
        }
        AddSettingChildElementDialog.this.disposeControl(true, true, true, true);
        if (fieldSize == null) {
          fieldSize = idField.getSize();
        }
        AddSettingChildElementDialog.this.clearTextField();
        AddSettingChildElementDialog.this.clearErrorList();
        
        Point size = new Point(dialogDefaultSize.x, dialogDefaultSize.y - 
          3 * fieldSize.y);
        
        container.layout();
        
        shell = getShell();
        shell.setSize(size);
      }
      min = null;
      max = null;
    }
    
    public void widgetDefaultSelected(SelectionEvent e)
    {
      widgetSelected(e);
    }
  }
  
  private void initContent()
  {
    makeAppIdControls();
    makeOperationControls();
    appIdLabel.dispose();
    appIdField.dispose();
    operationLabel.dispose();
    operationField.dispose();
    
    idField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingChildElementDialog.this.updateIDErrorMessage();
      }
    });
    titleField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingChildElementDialog.this.updateTitleErrorMessage();
      }
    });
  }
  
  private void makeValueControls()
  {
    valueLabel = new Label(container, 0);
    valueField = new Text(container, 2048);
    
    valueLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    valueLabel.setText("Value:");
    
    valueField.setLayoutData(new GridData(4, 2, 
      true, false));
    
    valueField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingChildElementDialog.this.updateValueErrorMessage();
      }
    });
  }
  
  private void makeMinControls()
  {
    minLabel = new Label(container, 0);
    minField = new Text(container, 2048);
    
    minLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    minLabel.setText("Min:");
    
    minField.setLayoutData(new GridData(4, 2, 
      true, false));
    minField.setText(min != null ? min : "");
    minField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingChildElementDialog.this.updateMinErrorMessage();
      }
    });
  }
  
  private void makeMaxControls()
  {
    maxLabel = new Label(container, 0);
    maxField = new Text(container, 2048);
    
    maxLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    maxLabel.setText("Max:");
    
    maxField.setLayoutData(new GridData(4, 2, 
      true, false));
    maxField.setText(max != null ? max : "");
    maxField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingChildElementDialog.this.updateMaxErrorMessage();
      }
    });
  }
  
  private void makeBoolCombo()
  {
    valueLabel2 = new Label(container, 0);
    valueLabel2.setLayoutData(new GridData(3, 
      2, false, false));
    valueLabel2.setText("Value:");
    
    boolValueField = new Combo(container, 8);
    
    boolValueField.setLayoutData(new GridData(4, 
      2, false, false));
    
    boolValueField.add("true");
    boolValueField.add("false");
    boolValueField.select(0);
  }
  
  private void makeAppIdControls()
  {
    appIdLabel = new Label(container, 0);
    appIdField = new Text(container, 2048);
    
    appIdLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    appIdLabel.setText("AppId:");
    
    appIdField.setLayoutData(new GridData(4, 2, 
      true, false));
    appIdField.setText(appId != null ? appId : "");
  }
  
  private void makeOperationControls()
  {
    operationLabel = new Label(container, 0);
    operationField = new Text(container, 2048);
    
    operationLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    operationLabel.setText("Operation:");
    
    operationField.setLayoutData(new GridData(4, 2, 
      true, false));
    operationField.setText(operation != null ? operation : "");
  }
  
  private void updateIDErrorMessage()
  {
    String errorMessage = null;
    String id = idField.getText();
    if (id.length() > 0)
    {
      errorMessage = ValueValidation.checkIDformat(id, elementType);
      if (errorMessage == null) {
        errorMessage = ValueValidation.checkDuplicate(id, fIdList, null);
      }
      if (errorMessage == null) {
        errorMessage = ValueValidation.checkString(id);
      }
    }
    errorList[0] = errorMessage;
    printErrorMessage(errorMessage, 0);
  }
  
  private void updateTitleErrorMessage()
  {
    String errorMessage = null;
    String title = titleField.getText();
    if (title.length() > 0) {
      errorMessage = ValueValidation.checkString(title);
    }
    errorList[1] = errorMessage;
    printErrorMessage(errorMessage, 1);
  }
  
  private void updateMinErrorMessage()
  {
    String errorMessage = null;
    String max = maxField.getText();
    String min = minField.getText();
    String value = valueField.getText();
    if (min.length() > 0)
    {
      errorMessage = checkMinMaxCommon(min);
      if (errorMessage == null)
      {
        int minInt = Integer.parseInt(min);
        if ((max.length() > 0) && 
          (checkMinMaxCommon(max) == null))
        {
          int maxInt = Integer.parseInt(max);
          errorMessage = ValueValidation.checkMinIntegerRange(maxInt, minInt, elementType);
          if (errorMessage == null)
          {
            errorList[4] = ValueValidation.checkMaxIntegerRange(minInt, maxInt, elementType);
            if ((value != null) && (!value.isEmpty())) {
              if (elementType.equals(ElementType.integer))
              {
                if (ValueValidation.checkInteger(value) == null) {
                  errorList[2] = ValueValidation.checkCustomIntegerRange(minInt, maxInt, Integer.parseInt(value));
                }
              }
              else if (ValueValidation.checkString(value) == null) {
                errorList[2] = ValueValidation.checkCustomStringRange(minInt, maxInt, value);
              }
            }
          }
        }
      }
    }
    else
    {
      if (max.length() > 0) {
        errorList[4] = checkMinMaxCommon(max);
      }
      if ((value != null) && (!value.isEmpty())) {
        if (elementType.equals(ElementType.integer)) {
          errorList[2] = ValueValidation.checkInteger(value);
        } else {
          errorList[2] = ValueValidation.checkString(value);
        }
      }
    }
    errorList[3] = errorMessage;
    printErrorMessage(errorMessage, 3);
  }
  
  private void updateMaxErrorMessage()
  {
    String errorMessage = null;
    String max = maxField.getText();
    String min = minField.getText();
    String value = valueField.getText();
    if (max.length() > 0)
    {
      errorMessage = checkMinMaxCommon(max);
      if (errorMessage == null)
      {
        int maxInt = Integer.parseInt(max);
        if ((min.length() > 0) && 
          (checkMinMaxCommon(min) == null))
        {
          int minInt = Integer.parseInt(min);
          errorMessage = ValueValidation.checkMaxIntegerRange(minInt, maxInt, elementType);
          if (errorMessage == null)
          {
            errorList[3] = ValueValidation.checkMinIntegerRange(maxInt, minInt, elementType);
            if ((value != null) && (!value.isEmpty())) {
              if (elementType.equals(ElementType.integer))
              {
                if (ValueValidation.checkInteger(value) == null) {
                  errorList[2] = ValueValidation.checkCustomIntegerRange(minInt, maxInt, Integer.parseInt(value));
                }
              }
              else if (ValueValidation.checkString(value) == null) {
                errorList[2] = ValueValidation.checkCustomStringRange(minInt, maxInt, value);
              }
            }
          }
        }
      }
    }
    else
    {
      if (min.length() > 0) {
        errorList[3] = checkMinMaxCommon(min);
      }
      if ((value != null) && (!value.isEmpty())) {
        if (elementType.equals(ElementType.integer)) {
          errorList[2] = ValueValidation.checkInteger(value);
        } else {
          errorList[2] = ValueValidation.checkString(value);
        }
      }
    }
    errorList[4] = errorMessage;
    printErrorMessage(errorMessage, 4);
  }
  
  private void updateValueErrorMessage()
  {
    String errorMessage = null;
    String value = valueField.getText();
    if (value.length() > 0) {
      switch (elementType)
      {
      case button: 
        errorMessage = ValueValidation.checkString(value);
        break;
      case link: 
        errorMessage = ValueValidation.checkStringValue(value);
        if (errorMessage == null)
        {
          this.min = minField.getText();
          this.max = maxField.getText();
          if ((this.min != null) && (!this.min.isEmpty()) && (errorList[3] == null)) {
            if ((this.max != null) && (!this.max.isEmpty()) && (errorList[4] == null))
            {
              int min = Integer.parseInt(this.min);
              int max = Integer.parseInt(this.max);
              if (errorMessage == null) {
                errorMessage = ValueValidation.checkCustomStringRange(min, max, value);
              }
            }
          }
        }
        break;
      case group: 
        errorMessage = ValueValidation.checkInteger(value);
        
        this.min = minField.getText();
        this.max = maxField.getText();
        if ((this.min != null) && (this.min.length() > 0) && (errorList[3] == null)) {
          if ((this.max != null) && (this.max.length() > 0) && (errorList[4] == null))
          {
            int min = Integer.parseInt(this.min);
            int max = Integer.parseInt(this.max);
            if (errorMessage == null) {
              errorMessage = ValueValidation.checkCustomIntegerRange(min, max, Integer.parseInt(value));
            }
          }
        }
        break;
      default: 
        errorMessageLabel.setText("Unexpected Error");
      }
    }
    errorList[2] = errorMessage;
    
    printErrorMessage(errorMessage, 2);
  }
  
  private String checkMinMaxCommon(String value)
  {
    String errorMessage = null;
    if (value.length() > 0)
    {
      errorMessage = ValueValidation.checkInteger(value);
      if (errorMessage == null)
      {
        int intValue = Integer.parseInt(value);
        if (elementType.equals(ElementType.string)) {
          errorMessage = ValueValidation.checkStringRange(intValue);
        } else {
          errorMessage = ValueValidation.checkIntegerRange(intValue);
        }
      }
    }
    return errorMessage;
  }
  
  private void printErrorMessage(String errorMessage, int field)
  {
    Image image = null;
    if (errorMessage != null)
    {
      image = ElementUtil.ERROR_IMG;
      errorMessageLabel.setText(errorMessage);
      errorMessageIcon.setImage(image);
      errorMessageLabel.getParent().layout();
      okButton.setEnabled(false);
    }
    else
    {
      for (int i = 0; i < 5; i++) {
        if (i != field) {
          if (errorList[i] != null)
          {
            image = ElementUtil.ERROR_IMG;
            errorMessageLabel.setText(errorList[i]);
            errorMessageIcon.setImage(image);
            errorMessageLabel.getParent().layout();
            okButton.setEnabled(false);
            return;
          }
        }
      }
      errorMessageLabel.setText("");
      errorMessageIcon.setImage(image);
      errorMessageLabel.getParent().layout();
      okButton.setEnabled(true);
    }
  }
  
  private void disposeControl(boolean value1, boolean boolValue, boolean min, boolean appId)
  {
    if ((value1) && 
      (!valueField.isDisposed()) && (!valueLabel.isDisposed()))
    {
      valueLabel.dispose();
      valueField.dispose();
    }
    if ((boolValue) && 
      (boolValueField != null) && (!boolValueField.isDisposed()) && (!valueLabel2.isDisposed()))
    {
      boolValueField.dispose();
      valueLabel2.dispose();
    }
    if (min)
    {
      if ((!minField.isDisposed()) && (!minLabel.isDisposed()))
      {
        minLabel.dispose();
        minField.dispose();
      }
      if ((!maxField.isDisposed()) && (!maxLabel.isDisposed()))
      {
        maxLabel.dispose();
        maxField.dispose();
      }
    }
    if (appId)
    {
      if ((!appIdField.isDisposed()) && (!appIdLabel.isDisposed()))
      {
        appIdLabel.dispose();
        appIdField.dispose();
      }
      if ((!operationField.isDisposed()) && (!operationLabel.isDisposed()))
      {
        operationLabel.dispose();
        operationField.dispose();
      }
    }
  }
  
  private void setErrorMessage(String errorMessage, Image image)
  {
    errorMessageLabel.setText(errorMessage);
    errorMessageIcon.setImage(image);
    errorMessageLabel.getParent().layout();
  }
  
  private void clearTextField()
  {
    idField.setText("");
    titleField.setText("");
    if (!valueField.isDisposed()) {
      valueField.setText("");
    }
    if ((!minField.isDisposed()) && (!maxField.isDisposed()))
    {
      minField.setText("");
      maxField.setText("");
    }
    if ((!appIdField.isDisposed()) && (!operationField.isDisposed()))
    {
      appIdField.setText("");
      operationField.setText("");
    }
    errorMessageIcon.setImage(null);
    errorMessageLabel.setText("");
  }
  
  private void clearErrorList()
  {
    for (int i = 0; i < 5; i++) {
      errorList[i] = null;
    }
  }
  
  protected void configureShell(Shell newShell)
  {
    super.configureShell(newShell);
    newShell.setText("Adding Setting ChildElement");
  }
  
  private String changeValidInt(String value)
  {
    int intValue = Integer.parseInt(value);
    return Integer.toString(intValue);
  }
  
  protected boolean isResizable()
  {
    return true;
  }
  
  public String getId()
  {
    return id;
  }
  
  public String getTitle()
  {
    return title;
  }
  
  public String getType()
  {
    return type;
  }
  
  public String getValue()
  {
    return value;
  }
  
  public String getMin()
  {
    return min;
  }
  
  public String getMax()
  {
    return max;
  }
  
  public String getAppId()
  {
    return appId;
  }
  
  public String getOperation()
  {
    return operation;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.setting.dialog.AddSettingChildElementDialog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.setting.dialog;

import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;

class AddSettingElementDialog$1
  implements ModifyListener
{
  AddSettingElementDialog$1(AddSettingElementDialog paramAddSettingElementDialog) {}
  
  public void modifyText(ModifyEvent e)
  {
    AddSettingElementDialog.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.setting.dialog.AddSettingElementDialog.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.setting.dialog;

import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;

class AddSettingElementDialog$2
  implements ModifyListener
{
  AddSettingElementDialog$2(AddSettingElementDialog paramAddSettingElementDialog) {}
  
  public void modifyText(ModifyEvent e)
  {
    AddSettingElementDialog.access$1(this$0);
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.setting.dialog.AddSettingElementDialog.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.setting.dialog;

import java.util.List;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.tizen.nativecpp.setting.model.ElementType;
import org.tizen.nativecpp.setting.util.ElementUtil;
import org.tizen.nativecpp.setting.util.ValueValidation;

public class AddSettingElementDialog
  extends Dialog
{
  private String id;
  private String title;
  private String main;
  private Text idField;
  private Text titleField;
  private Combo mainField;
  private Button okButton;
  private Label errorMessageLabel;
  private Label errorMessageIcon;
  private List<String> fIdList;
  private String[] errorList = new String[2];
  private final String DIALOG_TITLE = "Adding Setting Element";
  private final int WIDTH = 280;
  private final int VERTICAL_SPAN = 10;
  
  public AddSettingElementDialog(Shell parentShell, List<String> list)
  {
    super(parentShell);
    setShellStyle(2144);
    fIdList = list;
  }
  
  protected void buttonPressed(int buttonId)
  {
    if (buttonId == 0)
    {
      for (int i = 0; i < 2; i++) {
        if (errorList[i] != null)
        {
          setErrorMessage(errorList[i], ElementUtil.ERROR_IMG);
          okButton.setEnabled(false);
          return;
        }
      }
      id = idField.getText().trim();
      main = mainField.getText().trim();
      title = titleField.getText().trim();
      
      String errorMessage = null;
      if (id.length() <= 0) {
        errorMessage = "The ID must not be empty.";
      } else if (title.length() <= 0) {
        errorMessage = "The title  must not be empty.";
      }
      if (errorMessage != null)
      {
        setErrorMessage(errorMessage, ElementUtil.ERROR_IMG);
        okButton.setEnabled(false);
      }
      else
      {
        super.buttonPressed(buttonId);
      }
    }
    else
    {
      super.buttonPressed(buttonId);
    }
  }
  
  protected void createButtonsForButtonBar(Composite parent)
  {
    okButton = createButton(parent, 0, IDialogConstants.OK_LABEL, true);
    createButton(parent, 1, IDialogConstants.CANCEL_LABEL, false);
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite container = (Composite)super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout();
    numColumns = 2;
    container.setLayout(gridLayout);
    
    Label idLabel = new Label(container, 0);
    idLabel.setLayoutData(new GridData(3, 
      2, false, false));
    idLabel.setText("Id:");
    
    idField = new Text(container, 2048);
    idField.setLayoutData(new GridData(4, 
      2, true, false));
    
    Label mainLabel = new Label(container, 0);
    mainLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    mainLabel.setText("main:");
    
    mainField = new Combo(container, 8);
    mainField.setLayoutData(new GridData(4, 
      2, true, false));
    mainField.add("true");
    
    mainField.select(0);
    
    Label titleLabel = new Label(container, 0);
    titleLabel.setLayoutData(new GridData(3, 2, 
      false, false));
    titleLabel.setText("Title:");
    
    titleField = new Text(container, 2048);
    titleField.setLayoutData(new GridData(4, 
      2, true, false));
    
    errorMessageIcon = new Label(container, 0);
    GridData gd = new GridData(3, 2, false, false);
    verticalSpan = 10;
    
    errorMessageIcon.setLayoutData(gd);
    errorMessageIcon.setImage(null);
    
    errorMessageLabel = new Label(container, 64);
    errorMessageLabel.setText("");
    
    gd = new GridData(4, 2, false, false);
    verticalSpan = 10;
    widthHint = 280;
    
    errorMessageLabel.setLayoutData(gd);
    errorMessageLabel.setFont(JFaceResources.getFontRegistry().get("org.eclipse.jface.bannerfont"));
    Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0);
    errorMessageLabel.setForeground(color);
    
    initContent();
    
    return container;
  }
  
  private void initContent()
  {
    idField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingElementDialog.this.updateIDErrorMessage();
      }
    });
    titleField.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        AddSettingElementDialog.this.updateTitleErrorMessage();
      }
    });
  }
  
  private void updateIDErrorMessage()
  {
    String errorMessage = null;
    String id = idField.getText();
    if (id.length() > 0)
    {
      errorMessage = ValueValidation.checkIDformat(id, ElementType.setting);
      if (errorMessage == null)
      {
        errorMessage = ValueValidation.checkString(id);
        if (errorMessage == null) {
          errorMessage = ValueValidation.checkDuplicate(id, fIdList, null);
        }
      }
      errorList[0] = errorMessage;
    }
    if (errorMessage != null)
    {
      setErrorMessage(errorMessage, ElementUtil.ERROR_IMG);
      okButton.setEnabled(false);
    }
    else if (errorList[1] != null)
    {
      setErrorMessage(errorList[1], ElementUtil.ERROR_IMG);
      okButton.setEnabled(false);
    }
    else
    {
      setErrorMessage("", null);
      okButton.setEnabled(true);
    }
  }
  
  private void updateTitleErrorMessage()
  {
    String errorMessage = null;
    String title = titleField.getText();
    if (title.length() > 0)
    {
      errorMessage = ValueValidation.checkString(title);
      errorList[1] = errorMessage;
    }
    if (errorMessage != null)
    {
      setErrorMessage(errorMessage, ElementUtil.ERROR_IMG);
      okButton.setEnabled(false);
    }
    else if (errorList[0] != null)
    {
      setErrorMessage(errorList[0], ElementUtil.ERROR_IMG);
      okButton.setEnabled(false);
    }
    else
    {
      setErrorMessage("", null);
      okButton.setEnabled(true);
    }
  }
  
  private void setErrorMessage(String errorMessage, Image image)
  {
    errorMessageLabel.setText(errorMessage);
    errorMessageIcon.setImage(image);
    errorMessageLabel.getParent().layout();
  }
  
  protected void configureShell(Shell newShell)
  {
    super.configureShell(newShell);
    newShell.setText("Adding Setting Element");
  }
  
  protected boolean isResizable()
  {
    return true;
  }
  
  public String getId()
  {
    return id;
  }
  
  public String getTitle()
  {
    return title;
  }
  
  public String getMain()
  {
    return main;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.setting.dialog.AddSettingElementDialog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.setting.document;

import java.util.List;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.tizen.nativecpp.setting.SettingPlugin;
import org.tizen.nativecpp.setting.model.ElementType;
import org.tizen.nativecpp.setting.model.SettingModel;
import org.tizen.nativecpp.setting.model.TreeNode;

public class EditingDocument
{
  private IDocument fDocument;
  private SettingModel fSettingModel;
  private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter;
  
  public EditingDocument(IDocument document, SettingModel settingModel)
  {
    fDocument = document;
    fSettingModel = settingModel;
    fFindReplaceDocumentAdapter = new FindReplaceDocumentAdapter(document);
  }
  
  public void remove(TreeNode selectedTreeNode)
  {
    String element = "";
    ElementType elementType = selectedTreeNode.getElementType();
    
    TreeNode treeNode = null;
    TreeNode parent = null;
    if (elementType == null)
    {
      treeNode = selectedTreeNode.getParent();
      elementType = treeNode.getElementType();
    }
    else
    {
      treeNode = selectedTreeNode;
    }
    boolean removeEndTagFlag = isToRemoveEndTag(treeNode);
    
    boolean isSeparator = false;
    IRegion region = null;
    
    int separatorNum = 0;
    if (treeNode.getElementType() == ElementType.separator)
    {
      parent = treeNode.getParent();
      int treeNodeIndex = parent.getChild().indexOf(treeNode);
      treeNode = (TreeNode)parent.getChild().get(treeNodeIndex - 1);
      isSeparator = true;
      if (treeNode.getElementType() == ElementType.separator)
      {
        separatorNum++;
        for (int i = treeNodeIndex - 2; i > 0; i--)
        {
          if (((TreeNode)parent.getChild().get(i)).getElementType() != ElementType.separator) {
            break;
          }
          separatorNum++;
        }
      }
    }
    int size = treeNode.getChild().size();
    for (int i = 0; i < size; i++) {
      if (((TreeNode)treeNode.getChild().get(i)).getName().equals("id")) {
        try
        {
          region = fFindReplaceDocumentAdapter.find(0, ((TreeNode)treeNode.getChild().get(i)).getValue(), true, true, true, false);
        }
        catch (BadLocationException e)
        {
          SettingPlugin.setErrorMessage("EditingDocument.remove() : Find()", e.getMessage(), e);
          e.printStackTrace();
        }
      }
    }
    if (isSeparator) {
      try
      {
        if (region == null)
        {
          region = fFindReplaceDocumentAdapter.find(0, ((TreeNode)parent.getChild().get(0)).getValue(), true, true, true, false);
          for (int i = 0; i > separatorNum; i++) {
            region = fFindReplaceDocumentAdapter.find(region.getOffset() + region.getLength(), "<separator/>", true, true, false, true);
          }
        }
        region = fFindReplaceDocumentAdapter.find(region.getOffset() + region.getLength(), "<separator/>", true, true, false, true);
      }
      catch (BadLocationException e)
      {
        SettingPlugin.setErrorMessage("EditingDocument.remove() : Find()", e.getMessage(), e);
        e.printStackTrace();
      }
    }
    region = getLineRegion(region);
    
    int offset = region.getOffset() - 1;
    int length = getGroupLength(elementType, region) + 1;
    if (removeEndTagFlag)
    {
      parent = treeNode.getParent();
      IRegion endTagRegion = null;
      if (parent == null) {
        endTagRegion = findEndTag(ElementType.settings, region);
      } else {
        endTagRegion = findEndTag(parent.getElementType(), region);
      }
      endTagRegion = getLineRegion(endTagRegion);
      element = "/>";
      offset--;
      length = length + endTagRegion.getLength() + 2;
    }
    try
    {
      fDocument.replace(offset, length, element);
    }
    catch (BadLocationException e)
    {
      SettingPlugin.setErrorMessage("EditingDocument.remove() : Replace()", e.getMessage(), e);
      e.printStackTrace();
    }
  }
  
  public void add(TreeNode selectedTreeNode, List<String> attrs, ElementType elementType, ElementType menuType)
  {
    String element = makeElementString(attrs, elementType);
    String endTag = null;
    
    int depth = 0;
    depth = getDepth(selectedTreeNode);
    for (int i = 0; i < depth; i++) {
      element = "  " + element;
    }
    endTag = addEndTag(selectedTreeNode, menuType, depth);
    element = element + endTag;
    
    TreeNode baseTreeNode = null;
    if (menuType.equals(ElementType.settings))
    {
      if (selectedTreeNode == null)
      {
        if (fSettingModel.getTreeList().size() <= 0)
        {
          element = "\n" + element;
          addSettingElement(element);
          return;
        }
        baseTreeNode = (TreeNode)fSettingModel.getTreeList().get(fSettingModel.getTreeList().size() - 1);
      }
      else
      {
        baseTreeNode = selectedTreeNode;
      }
    }
    else
    {
      ElementType selectedTreeNodeElementType = selectedTreeNode.getElementType();
      if (selectedTreeNodeElementType == null)
      {
        baseTreeNode = (TreeNode)selectedTreeNode.getParent().getChild().get(selectedTreeNode.getParent().getChild().size() - 1);
        if (baseTreeNode.getElementType() == null) {
          baseTreeNode = selectedTreeNode.getParent();
        }
      }
      else if ((!elementType.equals(ElementType.separator)) && (menuType == selectedTreeNodeElementType))
      {
        if (endTag.length() > 0) {
          baseTreeNode = selectedTreeNode;
        } else {
          baseTreeNode = (TreeNode)selectedTreeNode.getChild().get(selectedTreeNode.getChild().size() - 1);
        }
        element = "  " + element;
      }
      else
      {
        baseTreeNode = selectedTreeNode;
      }
    }
    element = "\n" + element;
    
    boolean isSeparator = false;
    IRegion baseRegion = null;
    if (baseTreeNode.getElementType().equals(ElementType.separator))
    {
      TreeNode parent = baseTreeNode.getParent();
      int baseIndex = parent.getChild().indexOf(baseTreeNode);
      baseTreeNode = (TreeNode)parent.getChild().get(baseIndex - 1);
      isSeparator = true;
    }
    int size = baseTreeNode.getChild().size();
    for (int i = 0; i < size; i++) {
      if (((TreeNode)baseTreeNode.getChild().get(i)).getName().equals("id")) {
        try
        {
          baseRegion = fFindReplaceDocumentAdapter.find(0, ((TreeNode)baseTreeNode.getChild().get(i)).getValue(), true, true, true, false);
        }
        catch (BadLocationException e)
        {
          SettingPlugin.setErrorMessage("EditingDocument.add() : Find", e.getMessage(), e);
          e.printStackTrace();
        }
      }
    }
    if (isSeparator) {
      try
      {
        baseRegion = fFindReplaceDocumentAdapter.find(baseRegion.getOffset() + baseRegion.getLength(), "<separator/>", true, true, false, true);
      }
      catch (BadLocationException e)
      {
        SettingPlugin.setErrorMessage("EditingDocument.remove() : Find()", e.getMessage(), e);
        e.printStackTrace();
      }
    } else {
      baseRegion = getLineRegion(baseRegion);
    }
    int lineOffset = baseRegion.getOffset();
    int lineLength = getGroupLength(baseTreeNode.getElementType(), baseRegion);
    int insertLength = 0;
    if (endTag.length() > 0)
    {
      lineLength -= 2;
      element = ">" + element;
      insertLength = 2;
    }
    try
    {
      fDocument.replace(lineOffset + lineLength, insertLength, element);
    }
    catch (BadLocationException e)
    {
      SettingPlugin.setErrorMessage("EditingDocument.add() : Replace()", e.getMessage(), e);
      e.printStackTrace();
    }
  }
  
  public void change(TreeNode selectedTreeNode, String newValue)
  {
    ElementType elementType = selectedTreeNode.getElementType();
    String selectedValue = selectedTreeNode.getValue().replaceAll("&", "&amp;");
    
    TreeNode treeNode = null;
    if (elementType == null)
    {
      treeNode = selectedTreeNode.getParent();
      elementType = treeNode.getElementType();
    }
    else
    {
      treeNode = selectedTreeNode;
    }
    IRegion region = null;
    
    int size = treeNode.getChild().size();
    for (int i = 0; i < size; i++) {
      if (((TreeNode)treeNode.getChild().get(i)).getName().equals("id")) {
        try
        {
          region = fFindReplaceDocumentAdapter.find(0, ((TreeNode)treeNode.getChild().get(i)).getValue(), true, true, true, false);
        }
        catch (BadLocationException e)
        {
          SettingPlugin.setErrorMessage("EditingDocument.change(): Find()", e.getMessage(), e);
          e.printStackTrace();
        }
      }
    }
    region = getLineRegion(region);
    try
    {
      region = fFindReplaceDocumentAdapter.find(region.getOffset(), selectedTreeNode.getName(), true, true, true, false);
      if ((selectedValue.isEmpty()) || (selectedValue.length() == 0))
      {
        region = fFindReplaceDocumentAdapter.find(region.getOffset(), "\"", true, true, false, true);
        newValue = "\"" + newValue;
      }
      else
1 2 3 4 5 6 7 8 9

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd