コード例 #1
0
ファイル: ResourceEditDialog.java プロジェクト: lukehan/birt
  protected void addSelection() {
    String key = keyText.getText();
    String val = valueText.getText();
    if (key != null && key.trim().length() > 0) {
      boolean isContained = false;
      for (int i = 0; i < globalLinkedProperties.size(); i++) {
        GlobalProperty property = (GlobalProperty) globalLinkedProperties.get(i);
        if (key.equals(property.key) && !property.isDeleted) {
          property.value = val;
          isContained = true;
          break;
        }
      }

      if (!isContained) {
        // if the file is read-only then change is not allowed.
        if (propFileName[0] == null) {
          return;
        } else {
          File f = new File(propFileName[0]);
          if (!(f.exists() && f.isFile())) {
            MessageDialog.openError(
                getShell(),
                Messages.getString("ResourceEditDialog.NotFile.Title"), // $NON-NLS-1$
                Messages.getFormattedString(
                    "ResourceEditDialog.NotFile.Message", //$NON-NLS-1$
                    new Object[] {propFileName}));
            return;
          } else if (!f.canWrite()) {
            MessageDialog.openError(
                getShell(),
                Messages.getString("ResourceEditDialog.ReadOnlyEncounter.Title"), // $NON-NLS-1$
                Messages.getFormattedString(
                    "ResourceEditDialog.ReadOnlyEncounter.Message", //$NON-NLS-1$
                    new Object[] {propFileName}));
            return;
          }

          GlobalProperty property = new GlobalProperty();
          property.key = key;
          property.value = val;
          property.holder = contents[0];
          property.isDeleted = false;
          property.holderFile = propFileName[0];

          globalLinkedProperties.add(property);
        }
      }

      viewer.refresh();
      listChanged = true;
      updateSelection();

    } else {
      MessageDialog.openWarning(
          getShell(),
          Messages.getString("ResourceEditDialog.text.AddWarningTitle"), // $NON-NLS-1$
          Messages.getString("ResourceEditDialog.text.AddWarningMsg")); // $NON-NLS-1$
    }
  }
コード例 #2
0
ファイル: ResourceEditDialog.java プロジェクト: lukehan/birt
  /** Loads the key/value from message file. */
  private void loadMessage() {
    if (this.resourceURLs != null && this.resourceURLs.length > 0) {
      if (contents == null) contents = new LinkedProperties[resourceURLs.length];
      if (propFileName == null) propFileName = new String[resourceURLs.length];
      LinkedHashMap<String, GlobalProperty> propertyMap =
          new LinkedHashMap<String, GlobalProperty>();
      for (int i = 0; i < resourceURLs.length; i++) {
        contents[i] = new LinkedProperties();
        try {
          if (this.resourceURLs[i] != null) {
            InputStream in = this.resourceURLs[i].openStream();
            contents[i].load(in);
            in.close();
            propFileName[i] = DEUtil.getFilePathFormURL(resourceURLs[i]);

            Iterator iter = contents[i].keySet().iterator();
            if (iter != null) {
              while (iter.hasNext()) {
                String key = (String) iter.next();
                if (!propertyMap.containsKey(key)) {
                  GlobalProperty property = new GlobalProperty();
                  property.key = key;
                  property.value = contents[i].getProperty(key);
                  property.holder = contents[i];
                  property.isDeleted = false;
                  property.holderFile = propFileName[i];
                  propertyMap.put(key, property);
                }
              }
            }
          }
        } catch (Exception e) {
          ExceptionHandler.handle(e);
        }
      }

      for (Iterator iter = propertyMap.keySet().iterator(); iter.hasNext(); ) {
        globalLinkedProperties.add(propertyMap.get(iter.next()));
      }
    }
  }