private void init() {
   setTitle("Synchronization Results");
   // Add a OK button
   JPanel southPane = new JPanel();
   southPane.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 8));
   JButton closeBtn = new JButton("Close");
   closeBtn.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           dispose();
         }
       });
   closeBtn.setMnemonic('C');
   closeBtn.setDefaultCapable(true);
   getRootPane().setDefaultButton(closeBtn);
   southPane.add(closeBtn);
   getContentPane().add(southPane, BorderLayout.SOUTH);
   // Initialize actions
   initUpdateFromDBAction();
   initCommitToDBAction();
   initShowComparisonAction();
   initClearRecordAction();
   // Add a toolbar
   JToolBar toolbar = new JToolBar();
   Insets insets = new Insets(0, 0, 0, 0);
   JButton updateFromDBBtn = toolbar.add(updateFromDBAction);
   updateFromDBBtn.setText((String) updateFromDBAction.getValue(Action.NAME));
   JButton commitToDBBtn = toolbar.add(commitToDBAction);
   commitToDBBtn.setText((String) commitToDBAction.getValue(Action.NAME));
   JButton showComparisonBtn = toolbar.add(showComparisonAction);
   showComparisonBtn.setText((String) showComparisonAction.getValue(Action.NAME));
   JButton clearRecordBtn = toolbar.add(clearRecordAction);
   clearRecordBtn.setText((String) clearRecordAction.getValue(Action.NAME));
   if (!GKApplicationUtilities.isMac()) {
     updateFromDBBtn.setMargin(insets);
     commitToDBBtn.setMargin(insets);
     showComparisonBtn.setMargin(insets);
     clearRecordBtn.setMargin(insets);
   }
   getContentPane().add(toolbar, BorderLayout.NORTH);
   setSize(600, 700);
   GKApplicationUtilities.center(this);
   setModal(true);
   isLocalHasUnexpIECommitAllowed =
       SynchronizationManager.getManager().isLocalHasUnexpIECommitAllowed();
 }
 private void initCommitToDBAction() {
   commitToDBAction =
       new AbstractAction(
           "Commit to DB", GKApplicationUtilities.createImageIcon(getClass(), "CommitToDB.gif")) {
         public void actionPerformed(ActionEvent e) {
           commitToDB();
         }
       };
   commitToDBAction.putValue(Action.SHORT_DESCRIPTION, "Commit to the database repository");
   commitToDBAction.setEnabled(false);
 }
 private void initClearRecordAction() {
   clearRecordAction =
       new AbstractAction(
           "Clear Record", GKApplicationUtilities.createImageIcon(getClass(), "ClearRecord.gif")) {
         public void actionPerformed(ActionEvent e) {
           clearDeleteRecord();
         }
       };
   clearRecordAction.putValue(Action.SHORT_DESCRIPTION, "Clear delete record");
   // Disable as default
   clearRecordAction.setEnabled(false);
 }
 private void initShowComparisonAction() {
   showComparisonAction =
       new AbstractAction(
           "Show Comparison",
           GKApplicationUtilities.createImageIcon(getClass(), "ShowComparison.gif")) {
         public void actionPerformed(ActionEvent e) {
           showComparison();
         }
       };
   showComparisonAction.putValue(
       Action.SHORT_DESCRIPTION, "Compare an instance in the local and database repositories");
   showComparisonAction.setEnabled(false);
 }
 public SyncListCellRenderer() {
   super();
   icon = GKApplicationUtilities.createImageIcon(getClass(), "Instance.gif");
   deleteInDBIcon = GKApplicationUtilities.createImageIcon(getClass(), "InstanceDeleteInDB.png");
   deleteIcon = GKApplicationUtilities.createImageIcon(getClass(), "InstanceDelete.png");
   newInstanceIcon = GKApplicationUtilities.createImageIcon(getClass(), "InstanceNew.png");
   newChangeIcon = GKApplicationUtilities.createImageIcon(getClass(), "InstanceNewChange.png");
   dbChangeIcon =
       GKApplicationUtilities.createImageIcon(getClass(), "InstanceNewChangeInDB.png");
   conflictIcon =
       GKApplicationUtilities.createImageIcon(getClass(), "InstanceChangeConflict.png");
 }
Ejemplo n.º 6
0
 /** Break the links of this complex to other shortcuts. */
 public void delinkToShortcuts() {
   if (shortcuts == null) return;
   // An empty shortcuts list maybe used by other shortcuts.
   shortcuts.remove(this);
   if (shortcuts.size() == 1) shortcuts.clear(); // Don't need to track it.
   shortcuts = null;
   // Use the following funny way to do a deep clone of attributes.
   try {
     attributes = (Map) GKApplicationUtilities.cloneViaIO(attributes);
   } catch (Exception e) {
     System.err.println("RenderableComplex.delinkToShortcuts(): " + e);
     e.printStackTrace();
   }
 }
Ejemplo n.º 7
0
 /**
  * Check if a list of instances should be escaped QA check.
  *
  * @param parentComponent
  * @return false for the operation is canceled.
  */
 public boolean checkIfEscapeNeeded(Component parentComponent) {
   if (!needEscapePermissioin) {
     needEscape = false;
     return true; // No need to check. QA should be run always for a local project.
   }
   needEscape = false; // Default should be false
   int reply =
       JOptionPane.showConfirmDialog(
           parentComponent,
           "Do you want to provide a file containing a list of instances that should be\n"
               + "escaped QA check? This file may have been generated from a previous QA.",
           "Escape QA?",
           JOptionPane.YES_NO_CANCEL_OPTION);
   if (reply == JOptionPane.CANCEL_OPTION) {
     return false;
   }
   if (reply == JOptionPane.NO_OPTION) return true;
   // Need to get a file
   Properties prop = GKApplicationUtilities.getApplicationProperties();
   JFileChooser fileChooser = GKApplicationUtilities.createFileChooser(prop);
   reply = fileChooser.showOpenDialog(parentComponent);
   if (reply != JFileChooser.APPROVE_OPTION) {
     return false;
   }
   GKApplicationUtilities.storeCurrentDir(fileChooser, prop);
   File file = fileChooser.getSelectedFile();
   try {
     openEscapeList(file);
   } catch (IOException e) {
     System.err.println("QAEscapeHelper.checkifEscapeNeeded(): " + e);
     e.printStackTrace();
     JOptionPane.showMessageDialog(
         parentComponent,
         "Cannot parse DB_IDs from the provided file: " + e,
         "Error in Opening",
         JOptionPane.ERROR_MESSAGE);
     return false;
   }
   // Ask to provide a date time
   String value =
       JOptionPane.showInputDialog(
           parentComponent,
           "Please enter a date cutoff here in the format \"YYYY-MM-DD\". All instances\n"
               + "that have been edited after this cutoff date will be checked even if they\n"
               + "are listed in the escaped file.",
           "Cutoff Date?",
           JOptionPane.QUESTION_MESSAGE);
   if (value == null || value.trim().length() == 0) return false;
   if (value != null) {
     DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
     try {
       cutoffDate = df.parse(value);
     } catch (ParseException e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           parentComponent,
           "Cannot read the entered date. Please make sure your format is correct: YYYY-MM-DD",
           "Error in Date",
           JOptionPane.ERROR_MESSAGE);
       return false;
     }
   }
   needEscape = true;
   return needEscape;
 }
  private void showComparison() {
    // Find the instance that can be used for comparision. This instance
    // should be chosen from changedList or localHasUnexpInstance
    GKInstance instance = null;
    if (changedList != null) { // Check changedList first
      List selection = changedList.getSelection();
      if (selection.size() > 0) instance = (GKInstance) selection.get(0);
    }
    if (instance == null && localHasMoreIEList != null) {
      List selection = localHasMoreIEList.getSelection();
      if (selection.size() > 0) instance = (GKInstance) selection.get(0);
    }
    if (instance == null) return;
    final InstanceComparisonPane comparisonPane = new InstanceComparisonPane();
    // Fine tune comparison pane for making comparisons with
    // database
    comparisonPane.setSaveDialogHideUnusedButtons(true);
    comparisonPane.setSaveDialogSaveAsNewBtnFirst(false);
    comparisonPane.setSaveDialogSaveAsNewBtnTitle(
        "Create new local instance and put merge into that");
    comparisonPane.setSaveDialogReplaceFirstBtnTitle(
        "Overwrite existing instance with merge (recommended)");
    comparisonPane.setCloseAfterSaving(true);
    try {
      String clsName = instance.getSchemClass().getName();
      Long instanceId = instance.getDBID();
      final GKInstance localCopy = fileAdaptor.fetchInstance(clsName, instanceId);
      dbAdaptor.setUseCache(false);
      // final GKInstance dbCopy = dbAdaptor.fetchInstance(clsName, instanceId);
      // The class type might be changed locally or remotely. So not clsName should be used
      // to fetch database instance. Otherwise, null exception will be thrown. The same thing
      // is done also in creating synchronization result.
      final GKInstance dbCopy = dbAdaptor.fetchInstance(instanceId);
      dbAdaptor.setUseCache(true);
      comparisonPane.setInstances(localCopy, dbCopy);
      String title =
          "Comparing Instances \""
              + instance.getDisplayName()
              + "\" in the local and DB repositories";
      JDialog parentDialog = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, centerPane);
      final JDialog dialog = new JDialog(parentDialog, title);
      // Try to update the list automatically
      dialog.addWindowListener(
          new WindowAdapter() {
            public void windowClosed(WindowEvent e) {
              handleMergeResult(localCopy, dbCopy, comparisonPane);
              // To prevent double calling. It is called again when parentDialog is closed.
              dialog.removeWindowListener(this);
            }
          });
      dialog.getContentPane().add(comparisonPane, BorderLayout.CENTER);
      dialog.setModal(true);
      dialog.setSize(800, 600);
      GKApplicationUtilities.center(dialog);
      dialog.setVisible(true);

      // Update synchronization dialog panels depending on user
      // choice.
      if (comparisonPane.getSaveMergeOption() == InstanceComparisonPane.SAVE_AS_NEW) {
        GKInstance merged = comparisonPane.getMerged();

        if (newList == null) {
          List list = new ArrayList();
          list.add(merged);
          newList = initInstanceListPane(list, "Instances created locally: " + list.size());
        } else newList.addInstance(merged);
      } else if (comparisonPane.getSaveMergeOption() == InstanceComparisonPane.OVERWRITE_FIRST) {
        dbAdaptor.setUseCache(false);
        GKInstance remoteCopy = dbAdaptor.fetchInstance(instance.getDBID());
        dbAdaptor.setUseCache(true);
        if (remoteCopy != null) {
          InstanceComparer comparer = new InstanceComparer();
          int reply = comparer.compare(instance, remoteCopy);
          if (reply == InstanceComparer.LOCAL_HAS_MORE_IE) {
            if (localHasMoreIEList == null) {
              List list = new ArrayList();
              list.add(instance);
              localHasMoreIEList =
                  initInstanceListPane(
                      list, "Local instances having unexpected InstanceEdits: " + list.size());
            } else localHasMoreIEList.addInstance(instance);
          } else if (reply == InstanceComparer.IS_IDENTICAL) {
            // Merge has made local and database copies
            // identical - don't need to check in anymore
            changedList.deleteInstance(instance);
          } else if (reply != InstanceComparer.NEW_CHANGE_IN_LOCAL) {
            // Merge has produced a conflict
            typeMap.put(mapCompareResultToString(reply), instance);
          } else
            // The user should now be allowed to commit this
            // instance, because it will now have changed.
            commitToDBAction.setEnabled(true);

          JOptionPane.showMessageDialog(
              parentDialog,
              "Merge successful, you will need to check the merged instance into the database.\n\n",
              "Merge OK",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } catch (Exception e1) {
      System.err.println("Synchronization.createDisplayMapPane(): " + e1);
      e1.printStackTrace();
      JOptionPane.showMessageDialog(
          this,
          "Error in comparing: " + instance.toString(),
          "Error in Comparing",
          JOptionPane.ERROR_MESSAGE);
    }
  }