Пример #1
0
    public void execute() {
      if (!isEditable() || !isEnabled()) {
        return;
      }
      int position = lastClickPoint != null ? viewToModel(lastClickPoint) : getCaretPosition();
      lastClickPoint = null;
      Document document = getDocument();
      String selectedText = getSelectedText();

      try {
        if (selectedText != null && !CommonUtil.isEmpty(selectedText)) {
          String trimmed = selectedText.trim();
          if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
            StringBuffer buffer = new StringBuffer(selectedText);
            int pos = buffer.indexOf("<!--");
            buffer.delete(pos, pos + 4);
            pos = buffer.lastIndexOf("-->");
            buffer.delete(pos, pos + 3);
            replaceSelection(buffer.toString());
          } else {
            String newSelection = "<!--" + selectedText + "-->";
            replaceSelection(newSelection);
          }
        } else {
          final int docLen = document.getLength();
          int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n'));
          int toIndex = getText(fromIndex + 1, docLen - position).indexOf('\n');
          toIndex = toIndex < 0 ? docLen : fromIndex + toIndex;
          String textToComment = getText(fromIndex, toIndex - fromIndex + 1);

          if (textToComment.startsWith("\n")) {
            textToComment = textToComment.substring(1);
            fromIndex++;
          }
          if (textToComment.endsWith("\n")) {
            textToComment = textToComment.substring(0, textToComment.length() - 1);
            toIndex--;
          }
          String trimmed = textToComment.trim();
          if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
            int pos = textToComment.lastIndexOf("-->");
            document.remove(fromIndex + pos, 3);
            pos = textToComment.indexOf("<!--");
            document.remove(fromIndex + pos, 4);
          } else {
            document.insertString(Math.min(toIndex + 1, docLen), "-->", null);
            document.insertString(fromIndex, "<!--", null);
          }
        }
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }
Пример #2
0
  private void runQuery() {
    boolean inc = true;
    Document documentIn = null, documentOut = null;
    Set<String> queryKeys = query.getKeys();
    Set<String> projectionKeys = projection.getKeys();
    Iterator<Document> it = collection.documents.iterator();

    while (it.hasNext()) {
      inc = true;
      documentIn = it.next();

      for (String key : queryKeys)
        if (!documentIn.containsKey(key) || !documentIn.get(key).equals(query.get(key))) {
          inc = false;
          break;
        }

      if (!inc) continue;

      documentOut = documentIn;

      for (String key : projectionKeys) {
        if (documentOut.containsKey(key)) {
          System.out.println("projKey: (" + key.getClass() + ") " + key);
          System.out.println(
              "projVal: (" + projection.get(key).getClass() + ") " + projection.get(key));
          if ((projection.get(key) instanceof Long && (Long) projection.get(key) == 0)
              || (projection.get(key) instanceof Boolean && (Boolean) projection.get(key) == false))
            documentOut.remove(key);
        }
      }
      documents.add(documentOut);
    }
  }
Пример #3
0
 /**
  * Replaces the currently selected content with new content represented by the given StyledText.
  * If there is no selection this amounts to an insert of the given text. If there is no
  * replacement text this amounts to a removal of the current selection. The replacement text will
  * have the attributes currently defined for input at the point of insertion. If the document is
  * not editable, beep and return
  *
  * @param content the content to replace the selection with
  * @see StyledText#insert
  */
 public static void replaceSelection(Word word, StyledText content) {
   Document doc = word.workspace.getDocument();
   String text;
   Caret caret = word.workspace.getCaret();
   int insertPos = 0;
   int i;
   int contentSize;
   if (doc != null) {
     try {
       int p0 = Math.min(caret.getDot(), caret.getMark());
       int p1 = Math.max(caret.getDot(), caret.getMark());
       // if there is any selection
       if (p0 != p1) {
         doc.remove(p0, p1 - p0);
       }
       // insert the content
       if (content != null) {
         content.insert(doc, p0);
       }
     } catch (BadLocationException ble) {
       javax.swing.UIManager.getLookAndFeel().provideErrorFeedback(word.workspace);
       return;
     }
   }
 }
Пример #4
0
 void removeText() {
   if ((p0 != null) && (p1 != null) && (p0.getOffset() != p1.getOffset())) {
     try {
       Document doc = c.getDocument();
       doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset());
     } catch (BadLocationException e) {
     }
   }
 }
Пример #5
0
  public static void removeUsersAndDevices(String alias) throws NotesException {

    Session session = null;
    Database dbUnplugged = null;

    String alias1 = "/" + alias.toLowerCase();
    String alias2 = "/o=" + alias.toLowerCase();

    Logger.debug("Remove Unplugged users and devices for alias \"" + alias + "\"");

    Configuration config = Configuration.get();

    // open unplugged db
    session = Utils.getCurrentSession();
    dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

    // check if an app document for this app already exists and create it if not
    String q =
        "Form=\"User\":\"Device\" & ( @Contains(@LowerCase(UserName); \""
            + alias1
            + "\") | @Contains(@LowerCase(UserName); \""
            + alias2
            + "\") )";
    DocumentCollection dcApp = dbUnplugged.search(q);

    Logger.info("- finding users and devices with query: " + q);

    if (dcApp.getCount() == 0) {
      Logger.info("- No Unplugged users/ devices found");

    } else {

      Logger.info("- found " + dcApp.getCount() + " users and/or devices");

      Document doc = dcApp.getFirstDocument();
      while (null != doc) {

        Document t = dcApp.getNextDocument(doc);

        Logger.info(
            "- removing "
                + doc.getItemValueString("form")
                + " for "
                + doc.getItemValueString("UserName"));

        doc.remove(true);

        try {
          doc.recycle();
        } catch (Exception e) {

        }
        doc = t;
      }
    }
  }
  /** Resets the value of the JFormattedTextField to be <code>value</code>. */
  void resetValue(Object value) throws BadLocationException, ParseException {
    Document doc = getFormattedTextField().getDocument();
    String string = valueToString(value);

    try {
      ignoreDocumentMutate = true;
      doc.remove(0, doc.getLength());
      doc.insertString(0, string, null);
    } finally {
      ignoreDocumentMutate = false;
    }
    updateValue(value);
  }
Пример #7
0
    public void actionPerformed(ActionEvent e) {
      JTextComponent textComponent = getTextComponent(e);
      if (!textComponent.isEditable() || !textComponent.isEnabled()) {
        return;
      }

      try {
        final int position = getCaretPosition();
        final Document document = getDocument();
        int docLen = document.getLength();

        if (docLen == 0) {
          return;
        }

        int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n'));
        int toIndex = getText(fromIndex + 1, docLen - fromIndex - 1).indexOf('\n');
        toIndex = toIndex < 0 ? docLen : fromIndex + toIndex + 1;
        String text = getText(fromIndex, toIndex - fromIndex);
        if (text.startsWith("\n") || toIndex >= docLen) {
          document.remove(fromIndex, toIndex - fromIndex);
        } else {
          document.remove(fromIndex, toIndex - fromIndex + 1);
        }

        int newPosition = 0;
        if (fromIndex > 0) {
          newPosition = fromIndex + 1;
        }
        docLen = document.getLength();
        if (newPosition > docLen) {
          newPosition = getText().lastIndexOf('\n') + 1;
        }
        setCaretPosition(newPosition);
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }
Пример #8
0
 @Override
 protected void exportDone(JComponent source, Transferable data, int action) {
   if (action == TransferHandler.MOVE) {
     JTextPane aTextPane = (JTextPane) source;
     int sel_start = aTextPane.getSelectionStart();
     int sel_end = aTextPane.getSelectionEnd();
     Document doc = aTextPane.getDocument();
     try {
       doc.remove(sel_start, sel_end - sel_start);
     } catch (BadLocationException e) {
       Debug.error(me + "exportDone: Problem while trying to remove text\n%s", e.getMessage());
     }
   }
 }
Пример #9
0
 private void expandTab() throws BadLocationException {
   int pos = getCaretPosition();
   Document doc = getDocument();
   doc.remove(pos - 1, 1);
   doc.insertString(pos - 1, _tabString, null);
 }
Пример #10
0
  // removes the specified applications for the user from Unplugged
  @SuppressWarnings("unchecked")
  public static void deleteApplication(String userName, Vector<String> appPaths) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docUser = null;
    View vwUsers = null;
    Name nmUser = null;
    Document docApp = null;

    try {

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      nmUser = sessionAsSigner.createName(userName);

      // get all application documents for this user
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & @IsMember(\"" + userName + "\"; UserName)");

      Document docTemp = null;

      int numRemoved = 0;

      // update app documents
      docApp = dcApp.getFirstDocument();
      while (null != docApp) {

        String path = docApp.getItemValueString("Path");

        if (appPaths.contains(path)) {
          // remove application
          Vector<String> appUsers = docApp.getItemValue("UserName");

          Logger.debug(nmUser.getCanonical() + " is a user for " + path + " - removing");

          appUsers.remove(nmUser.getCanonical());
          docApp.replaceItemValue("UserName", appUsers);
          docApp.computeWithForm(true, true);
          docApp.save();

          numRemoved++;
        }

        docTemp = dcApp.getNextDocument(docApp);
        docApp.recycle();
        docApp = docTemp;
      }

      if (numRemoved == dcApp.getCount()) { // user removed from all apps - remove user config

        Logger.info(
            "Unplugged user "
                + nmUser.getCanonical()
                + " removed from all applications - remove user config");

        // check for user account
        vwUsers = dbUnplugged.getView(USERS_VIEW);
        docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true);

        if (docUser != null) {
          docUser.remove(true);
          Logger.info("removed Unplugged user " + nmUser.getCanonical());
        }
      }

    } catch (Exception e) {
      Logger.error(e);
    } finally {

      Utils.recycle(docUser, nmUser, dbUnplugged, sessionAsSigner);
    }
  }