@Override
 public void propertyChange(PropertyChangeEvent event) {
   super.propertyChange(event);
   if (event.getSource().equals(checkbox)) {
     boolean useDefault = ((Boolean) event.getNewValue()).booleanValue();
     editor.setEnabled(!useDefault, getFieldEditorParent());
   }
 }
  @Override
  public void propertyChange(final PropertyChangeEvent event) {
    super.propertyChange(event);
    final Object source = event.getSource();

    if (source == this.projectComboList) {
      this.workingJavaProject = (String) event.getNewValue();
    }
  }
 @Override
 public void propertyChange(PropertyChangeEvent event) {
   if (event.getSource() == disableResolvers) {
     updateFieldEnablement(disableResolvers.getBooleanValue());
   } else if (event.getSource() == resolutionScope) {
     updateScopeDescription((String) event.getNewValue());
   }
   super.propertyChange(event);
 }
  /** {@inheritDoc} */
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    super.propertyChange(event);
    isDirty = true;
    setAutoDownloadEnabled(fieldEnableAutoDownload.getBooleanValue());

    // We need to do this check, when some property change, to refresh the valid state
    fieldDownloadPath.isValid();
  }
  /**
   * @see
   *     org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent event) {

    if (event.getProperty().equals(FieldEditor.IS_VALID)) {
      boolean newValue = ((Boolean) event.getNewValue()).booleanValue();
      // If the new value is true then we must check all field editors.
      // If it is false, then the page is invalid in any case.
      if (newValue) {
        // if (fClientComPortEditor != null && event.getSource() != fClientComPortEditor) {
        // // fClientComPortEditor.refreshValidState();
        // }
        checkState();
      } else {
        super.propertyChange(event);
      }

    } else {
      super.propertyChange(event);
    }
  }
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    super.propertyChange(event);
    if (event.getProperty().equals(FieldEditor.VALUE)) {
      checkState();
    }

    if (event.getSource() == localTemplateEditor) {
      Activator.getDefault()
          .getIReportTemplateDirectoryService()
          .setDirectory((String) event.getNewValue());
    }
  }
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    super.propertyChange(event);

    if (event.getSource() != versionsEditor) {
      checkState();
      return;
    }

    shouldUseGradleHome =
        event.getNewValue().equals(GradlePluginConstants.USE_GRADLE_HOME_VERSION_VALUE);
    gradleHomeField.setEmptyStringAllowed(!shouldUseGradleHome);
    checkState();
  }
  @Override
  public void propertyChange(final PropertyChangeEvent event) {
    super.propertyChange(event);
    final Object source = event.getSource();
    if (source == this.repositoryName) {
      final String newValue = (String) event.getNewValue();
      this.currentValueOfRepoName = newValue;
      /*this.repositoryBaseLocation.setStringValue(this.currentValueOfRepoName.toLowerCase() + COLON + FORWARD_SLASH + FORWARD_SLASH
      + LOCAL_HOST);*/
    }

    // this.currentValueOfRepoLoc = this.repositoryLocation.getStringValue(); -- uncomment this
    // after enabling browse in Rep Dialog
    // this.currentValueOfRepoUrl = this.repositoryUrl.getStringValue();
    this.currentValueOfUserName = this.userName.getStringValue();
    this.currentValueOfPassWord = this.passWord.getStringValue();
    if (isEmpty(this.currentValueOfUserName) || isEmpty(this.currentValueOfPassWord)) {
      this.addButton.setEnabled(false);
      this.editButton.setEnabled(false);
    } else {
      this.addButton.setEnabled(true);
      this.editButton.setEnabled(true);
    }
    if (source == this.enableAutoCheckin) {
      enableFields((Boolean) event.getNewValue());
      /*final IEvaluationService service = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
      service.requestEvaluation("org.fastcode.menus.versioncontrol");*/
    }

    /*if (source == this.repositoryUrl) {
    	final String prj = this.preferenceStore.getString(P_REPOSITORY_PROJECT);
    	if (isEmpty(prj)) {
    		resetProjectName();
    		if (!resetProjectName()) {
    			//return false; - to check this line
    		}
    	}

    }*/
  }
 public void propertyChange(PropertyChangeEvent event) {
   super.propertyChange(event);
 }
  /** @param event */
  @Override
  public void propertyChange(final PropertyChangeEvent event) {
    super.propertyChange(event);
    final Object source = event.getSource();
    final Object newValue = event.getNewValue();
    this.classSelected = false;
    this.fileSelected = false;
    this.pkgSelected = false;
    this.fldrSelected = false;
    this.enumSelected = false;
    final GlobalSettings globalSettings = GlobalSettings.getInstance();

    for (int i = 0; i < this.TEMPLATES_LIST.length; i++) {
      this.prefValueOf1stTemplateItem =
          getPreferenceStore()
              .getString(
                  getTemplatePreferenceKey(
                      this.templatePreferenceParts[i].templateName,
                      P_TEMPLATE_FIRST_TEMPLATE_ITEM));
      this.prefValueOf2ndTempalteItem =
          getPreferenceStore()
              .getString(
                  getTemplatePreferenceKey(
                      this.templatePreferenceParts[i].templateName,
                      P_TEMPLATE_SECOND_TEMPLATE_ITEM));
      if (source == this.templatePreferenceParts[i].enableTemplateCheckBox) {
        final boolean enbale = (Boolean) newValue;
        enableFields(this.templatePreferenceParts[i], enbale);
        break;
      } else if (source == this.templatePreferenceParts[i].allowMultipleVariationCheckBox) {
        this.templatePreferenceParts[i].templateVariationField.setEmptyStringAllowed(
            !(Boolean) newValue);
        if (FALSE_STR.equalsIgnoreCase(
            globalSettings.getPropertyValue(DEFAULT_TEMPLATE_VARIATION_FIELD, TRUE_STR))) {
          this.templatePreferenceParts[i].templateVariationFieldNameField.setEmptyStringAllowed(
              !(Boolean) newValue);
        }
        break;
      } else if (source == this.templatePreferenceParts[i].templateVariationField) {
        if (FALSE_STR.equalsIgnoreCase(
            globalSettings.getPropertyValue(DEFAULT_TEMPLATE_VARIATION_FIELD, TRUE_STR))) {
          this.templatePreferenceParts[i].templateVariationFieldNameField.setEmptyStringAllowed(
              isEmpty((String) newValue));
        }
        break;
      } else if (source == this.templatePreferenceParts[i].templateVariationFieldNameField) {
        final boolean isErr =
            ((String) newValue).endsWith(" ") || ((String) newValue).endsWith("\t");
        setErrorMessage(isErr ? "Variation Field cannot end with whitespace" : null);
        this.templatePreferenceParts[i].templateVariationField.setEmptyStringAllowed(
            isEmpty((String) newValue));
        break;
      } else if (source == this.templatePreferenceParts[i].firstTemplateRadioButton) {
        setErrorMessage(null);
        this.currentValueOf1stTemplateItem = (String) newValue;
        enableTemplateItems(this.templatePreferenceParts[i], newValue);

        validateSecondTemplateItem(this.currentValueOf2ndTemplateItem);
        break;
      } else if (source == this.templatePreferenceParts[i].secondTemplateRadioButton) {
        this.currentValueOf2ndTemplateItem = (String) newValue;

        if (newValue.equals(SECOND_TEMPLATE.field.getValue())
            || newValue.equals(SECOND_TEMPLATE.both.getValue())
            || newValue.equals(SECOND_TEMPLATE.custom.getValue())) {
          this.templatePreferenceParts[i].getterSetterRadioButton.setEnabled(
              true, getFieldEditorParent());
        } else if (newValue.equals(SECOND_TEMPLATE.method.getValue())
            || newValue.equals(SECOND_TEMPLATE.none.getValue())) {
          getPreferenceStore()
              .setValue(
                  getTemplatePreferenceKey(
                      this.templatePreferenceParts[i].templateName, P_TEMPLATE_GETTER_SETTER),
                  GETTER_SETTER.NONE.getValue());
          this.templatePreferenceParts[i].getterSetterRadioButton.setEnabled(
              false, getFieldEditorParent());
        }
        if (isEmpty(this.currentValueOf1stTemplateItem)) {
          this.currentValueOf1stTemplateItem = this.prefValueOf1stTemplateItem;
        }
        this.classSelected =
            this.currentValueOf1stTemplateItem.equals(FIRST_TEMPLATE.Class.getValue());
        this.fileSelected =
            this.currentValueOf1stTemplateItem.equals(FIRST_TEMPLATE.File.getValue());
        this.pkgSelected =
            this.currentValueOf1stTemplateItem.equals(FIRST_TEMPLATE.Package.getValue());
        this.fldrSelected =
            this.currentValueOf1stTemplateItem.equals(FIRST_TEMPLATE.Folder.getValue());
        this.enumSelected =
            this.currentValueOf1stTemplateItem.equals(FIRST_TEMPLATE.Enumeration.getValue());
        validateSecondTemplateItem(newValue);
        break;
      } else if (source == this.templatePreferenceParts[i].additionalParametersField) {
        if (!isEmpty(newValue.toString())) {
          try {
            parseAdditonalParam(newValue.toString());
          } catch (final FastCodeException ex) {
            // throw new Exception(ex);
          }
          /*final String addtnlParams[] = newValue.toString().split("\\s+");
          final Map<String, String> addtnParamMap = new HashMap<String, String>();
          for (final String params : addtnlParams) {
          	if (params.contains(COLON)) {
          		final String parseParam[] = params.split(COLON);
          		if (parseParam.length == 2) {
          			final String type = parseParam[1].trim().toLowerCase();
          			if (isEmpty(type)
          					|| !(type.equalsIgnoreCase(FIRST_TEMPLATE.Class.getValue())
          							|| type.equalsIgnoreCase(FIRST_TEMPLATE.File.getValue())
          							|| type.equalsIgnoreCase(FIRST_TEMPLATE.Package.getValue())
          							|| type.equalsIgnoreCase(FIRST_TEMPLATE.Folder.getValue())
          							|| type.equalsIgnoreCase(RETURN_TYPES.JAVAPROJECT.getValue())
          							|| type.equalsIgnoreCase(RETURN_TYPES.PROJECT.getValue())
          							|| type.equalsIgnoreCase(RETURN_TYPES.LOCALVAR.getValue()) || type
          								.equalsIgnoreCase(RETURN_TYPES.BOOLEAN.getValue()))) {
          				setErrorMessage("Additional Parameter type can be only class/file/package/folder/project/javaProject/localvar/boolean.");
          			} else {
          				setErrorMessage(null);
          			}
          			if (addtnParamMap.containsKey(parseParam[0])) {
          				setErrorMessage("Duplicate place holder name " + parseParam[0]);
          			}
          			addtnParamMap.put(parseParam[0], type);
          		} else if (parseParam.length == 1) {
          			setErrorMessage("Additional Parameter must have type class/file/package/folder/project/javaProject/localvar/boolean.");
          		}
          	}
          }*/
        }
      }
    }
  }
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    super.propertyChange(event);
    if (event != null && event.getSource() == diagStructFieldEditor) {
      if (event.getNewValue().equals(Boolean.TRUE)) {
        if (MessageDialog.openConfirm(
            getShell(),
            "Strukturierte Diagnosen",
            "Bisher erfasste Text Diagnosen werden automatisch in strukturierte umgewandelt.\n"
                + "Wollen Sie wirklich von nun an strukturierte Diagnosen verwenden?")) {
          ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
          try {
            progressDialog.run(
                true,
                true,
                new IRunnableWithProgress() {
                  public void run(IProgressMonitor monitor)
                      throws InvocationTargetException, InterruptedException {
                    Query<Patient> query = new Query<>(Patient.class);
                    List<Patient> patients = query.execute();
                    monitor.beginTask("Strukturierte Diagnosen erzeugen", patients.size());
                    IFindingsService findingsService = FindingsServiceComponent.getService();
                    IMigratorService migratorService = MigratorServiceComponent.getService();
                    for (Patient patient : patients) {
                      String diagnosen = patient.getDiagnosen();
                      List<IFinding> existing =
                          getExistingDiagnoses(patient.getId(), findingsService);
                      // only migrate if there is a diagnosis and no structured diagnosis already
                      // there
                      if (diagnosen != null && !diagnosen.isEmpty() && existing.isEmpty()) {
                        migratorService.migratePatientsFindings(patient.getId(), ICondition.class);
                      }
                      monitor.worked(1);
                      if (monitor.isCanceled()) {
                        break;
                      }
                    }
                    monitor.done();
                    Display.getDefault()
                        .asyncExec(
                            new Runnable() {
                              @Override
                              public void run() {
                                MessageDialog.openInformation(
                                    getShell(),
                                    "Strukturierte Diagnosen",
                                    "Strukturierte Diagnosen erfolgreich erzeugt. Bitte starten sie Elexis neu um mit den strukturierten Diagnosen zu arbeiten.");
                              }
                            });
                  }

                  private List<IFinding> getExistingDiagnoses(
                      String patientId, IFindingsService findingsService) {
                    return findingsService
                        .getPatientsFindings(patientId, ICondition.class)
                        .stream()
                        .filter(
                            condition ->
                                ((ICondition) condition).getCategory()
                                    == ConditionCategory.DIAGNOSIS)
                        .collect(Collectors.toList());
                  };
                });
          } catch (InvocationTargetException | InterruptedException e) {
            MessageDialog.openError(
                getShell(),
                "Diagnosen konvertieren",
                "Fehler beim erzeugen der strukturierten Diagnosen.");
            getLogger().error("Error creating structured diagnosis", e);
          }
        } else {
          getPreferenceStore().setValue(SettingsConstants.DIAGNOSE_SETTINGS_USE_STRUCTURED, false);
          // refresh later, on immediate refresh wasSelected of FieldEditor gets overwritten
          getShell()
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    @Override
                    public void run() {
                      diagStructFieldEditor.load();
                    }
                  });
        }
      } else {
        if (MessageDialog.openConfirm(
            getShell(),
            "Strukturierte Diagnosen",
            "Bisher erfasste strukturierte Diagnosen werden nicht in Text umgewandelt.\n"
                + "Wollen Sie wirklich von nun an Text Diagnosen verwenden?")) {
          MessageDialog.openInformation(
              getShell(),
              "Text Diagnosen",
              "Bitte starten sie Elexis neu um mit den Text Diagnosen zu arbeiten.");
        } else {
          getPreferenceStore().setValue(SettingsConstants.DIAGNOSE_SETTINGS_USE_STRUCTURED, true);
          // refresh later, on immediate refresh wasSelected of FieldEditor gets overwritten
          getShell()
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    @Override
                    public void run() {
                      diagStructFieldEditor.load();
                    }
                  });
        }
      }
    }
  }