예제 #1
0
  /**
   * Update the history store with the value of an an read, write or execute operation. Also, the
   * timestamp of the insertion is recorded. Also, the recorded history values are added to the
   * given json value.
   *
   * @param pJmxReq request for which an entry should be added in this history store
   * @param pJson the JSONObject to which to add the history.
   */
  public synchronized void updateAndAdd(JmxRequest pJmxReq, JSONObject pJson) {
    long timestamp = System.currentTimeMillis() / 1000;
    pJson.put(KEY_TIMESTAMP, timestamp);

    JmxRequest.Type type = pJmxReq.getType();
    if (type == EXEC || type == WRITE) {
      HistoryEntry entry = historyStore.get(new HistoryKey(pJmxReq));
      if (entry != null) {
        synchronized (entry) {
          // A history data to json object for the response
          pJson.put(KEY_HISTORY, entry.jsonifyValues());

          // Update history for next time
          if (type == EXEC) {
            entry.add(pJson.get(KEY_VALUE), timestamp);
          } else if (type == WRITE) {
            // The new value to set as string representation
            entry.add(pJmxReq.getValue(), timestamp);
          }
        }
      }
    } else if (type == READ) {
      updateReadHistory(pJmxReq, pJson, timestamp);
    }
  }
예제 #2
0
 /**
  * Set the global maximum limit for history entries
  *
  * @param pGlobalMaxEntries limit
  */
 public synchronized void setGlobalMaxEntries(int pGlobalMaxEntries) {
   globalMaxEntries = pGlobalMaxEntries;
   // Refresh all entries
   for (HistoryEntry entry : historyStore.values()) {
     entry.setMaxEntries(globalMaxEntries);
     entry.trim();
   }
 }
예제 #3
0
 private void addAttributeFromSingleValue(
     JSONObject pHistMap, String pAttrName, HistoryKey pKey, Object pValue, long pTimestamp) {
   HistoryEntry entry = getEntry(pKey, pValue, pTimestamp);
   if (entry != null) {
     synchronized (entry) {
       pHistMap.put(pAttrName, entry.jsonifyValues());
       entry.add(pValue, pTimestamp);
     }
   }
 }
 private void writeComposite(
     final Element res,
     final VirtualFile file,
     final EditorWithProviderComposite composite,
     final boolean pinned,
     final EditorWithProviderComposite selectedEditor) {
   final Element fileElement = new Element("file");
   fileElement.setAttribute("leaf-file-name", file.getName()); // TODO: all files
   final HistoryEntry entry = composite.currentStateAsHistoryEntry();
   entry.writeExternal(fileElement, getManager().getProject());
   fileElement.setAttribute("pinned", Boolean.toString(pinned));
   fileElement.setAttribute(
       "current", Boolean.toString(composite.equals(getManager().getLastSelected())));
   fileElement.setAttribute("current-in-tab", Boolean.toString(composite.equals(selectedEditor)));
   res.addContent(fileElement);
 }
예제 #5
0
 private HistoryEntry getEntry(HistoryKey pKey, Object pValue, long pTimestamp) {
   HistoryEntry entry = historyStore.get(pKey);
   if (entry != null) {
     return entry;
   }
   // Now try all known patterns and add lazily the key
   for (HistoryKey key : patterns.keySet()) {
     if (key.matches(pKey)) {
       entry = new HistoryEntry(patterns.get(key));
       entry.add(pValue, pTimestamp);
       historyStore.put(pKey, entry);
       return entry;
     }
   }
   return null;
 }
 private void logEntries(Collection<HistoryEntry> entries) {
   LocalHistory.LOG.log(Level.FINE, "LocalHistory returns {0} entries", entries.size()); // NOI18N
   if (LocalHistory.LOG.isLoggable(Level.FINEST)) {
     StringBuilder sb = new StringBuilder();
     Iterator<HistoryEntry> it = entries.iterator();
     while (it.hasNext()) {
       HistoryEntry entry = it.next();
       sb.append("["); // NOI18N
       sb.append(DateFormat.getDateTimeInstance().format(entry.getDateTime()));
       sb.append(",["); // NOI18N
       sb.append(toString(entry.getFiles()));
       sb.append("]]"); // NOI18N
       if (it.hasNext()) sb.append(","); // NOI18N
     }
     LocalHistory.LOG.finest(sb.toString());
   }
 }
예제 #7
0
  /**
   * Configure the history length for a specific entry. If the length is 0 disable history for this
   * key
   *
   * @param pKey history key
   * @param pMaxEntries number of maximal entries. If larger than globalMaxEntries, then
   *     globalMaxEntries is used instead.
   */
  public synchronized void configure(HistoryKey pKey, int pMaxEntries) {
    int maxEntries = pMaxEntries > globalMaxEntries ? globalMaxEntries : pMaxEntries;

    // Remove entries if set to 0
    if (pMaxEntries == 0) {
      removeEntries(pKey);
      return;
    }
    if (pKey.isMBeanPattern()) {
      patterns.put(pKey, maxEntries);
      // Trim all already stored keys
      for (HistoryKey key : historyStore.keySet()) {
        if (pKey.matches(key)) {
          HistoryEntry entry = historyStore.get(key);
          entry.setMaxEntries(maxEntries);
          entry.trim();
        }
      }
    } else {
      HistoryEntry entry = historyStore.get(pKey);
      if (entry != null) {
        entry.setMaxEntries(maxEntries);
        entry.trim();
      } else {
        entry = new HistoryEntry(maxEntries);
        historyStore.put(pKey, entry);
      }
    }
  }
    @Override
    protected JPanel processFiles(@NotNull List<Element> fileElements, final JPanel context) {
      final Ref<EditorWindow> windowRef = new Ref<EditorWindow>();
      UIUtil.invokeAndWaitIfNeeded(
          new Runnable() {
            @Override
            public void run() {
              windowRef.set(context == null ? createEditorWindow() : findWindowWith(context));
            }
          });
      final EditorWindow window = windowRef.get();
      LOG.assertTrue(window != null);
      VirtualFile focusedFile = null;

      for (int i = 0; i < fileElements.size(); i++) {
        final Element file = fileElements.get(i);
        if (i == 0) {
          EditorTabbedContainer tabbedPane = window.getTabbedPane();
          if (tabbedPane != null) {
            try {
              int limit =
                  Integer.parseInt(
                      file.getParentElement()
                          .getAttributeValue(
                              JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString(),
                              String.valueOf(JBTabsImpl.DEFAULT_MAX_TAB_WIDTH)));
              UIUtil.putClientProperty(
                  tabbedPane.getComponent(), JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY, limit);
            } catch (NumberFormatException e) {
              // ignore
            }
          }
        }
        try {
          final FileEditorManagerImpl fileEditorManager = getManager();
          Element historyElement = file.getChild(HistoryEntry.TAG);
          final HistoryEntry entry =
              HistoryEntry.createLight(fileEditorManager.getProject(), historyElement);
          final VirtualFile virtualFile = entry.getFile();
          if (virtualFile == null)
            throw new InvalidDataException("No file exists: " + entry.getFilePointer().getUrl());
          Document document =
              ApplicationManager.getApplication()
                  .runReadAction(
                      new Computable<Document>() {
                        @Override
                        public Document compute() {
                          return virtualFile.isValid()
                              ? FileDocumentManager.getInstance().getDocument(virtualFile)
                              : null;
                        }
                      });
          final boolean isCurrentInTab =
              Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue();
          Boolean pin = Boolean.valueOf(file.getAttributeValue(PINNED));
          fileEditorManager.openFileImpl4(
              window, virtualFile, entry, isCurrentInTab, isCurrentInTab, pin, i);
          if (isCurrentInTab) {
            focusedFile = virtualFile;
          }
          if (document != null) {
            // This is just to make sure document reference is kept on stack till this point
            // so that document is available for folding state deserialization in HistoryEntry
            // constructor
            // and that document will be created only once during file opening
            document.putUserData(DUMMY_KEY, null);
          }
          updateProgress();
        } catch (InvalidDataException e) {
          if (ApplicationManager.getApplication().isUnitTestMode()) {
            LOG.error(e);
          }
        }
      }
      if (focusedFile != null) {
        getManager().addSelectionRecord(focusedFile, window);
      }
      return window.myPanel;
    }