Lines 559-579
Link Here
|
559 |
text = Analyzer.convertLSToLF(text); |
559 |
text = Analyzer.convertLSToLF(text); |
560 |
|
560 |
|
561 |
// Perform the insert |
561 |
// Perform the insert |
562 |
boolean notifyMod = false; |
562 |
boolean notifyMod = notifyModifyCheckStart(offset, "insertString() vetoed"); // NOI18N |
563 |
|
|
|
564 |
NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get(); |
565 |
if (notifyModifyStatus == null) { // not in atomic lock |
566 |
notifyModifyStatus = new NotifyModifyStatus (this); |
567 |
STATUS.set (notifyModifyStatus); |
568 |
notifyModify(notifyModifyStatus); |
569 |
notifyMod = true; |
570 |
} |
571 |
if (notifyModifyStatus.isModificationVetoed()) { |
572 |
if (notifyMod) { |
573 |
STATUS.set (null); |
574 |
} |
575 |
throw new BadLocationException("insertString() vetoed.", offset); |
576 |
} |
577 |
boolean modFinished = false; // Whether modification succeeded |
563 |
boolean modFinished = false; // Whether modification succeeded |
578 |
extWriteLock(); |
564 |
extWriteLock(); |
579 |
try { |
565 |
try { |
Lines 635-644
Link Here
|
635 |
extWriteUnlock(); |
621 |
extWriteUnlock(); |
636 |
// Notify no mod done if notified mod but mod did not succeeded |
622 |
// Notify no mod done if notified mod but mod did not succeeded |
637 |
if (notifyMod) { |
623 |
if (notifyMod) { |
638 |
STATUS.set (null); |
624 |
notifyModifyCheckEnd(modFinished); |
639 |
if (!modFinished) { |
|
|
640 |
notifyUnmodify(notifyModifyStatus); |
641 |
} |
642 |
} |
625 |
} |
643 |
} |
626 |
} |
644 |
} |
627 |
} |
Lines 646-665
Link Here
|
646 |
/** Removes portion of a document */ |
629 |
/** Removes portion of a document */ |
647 |
public void remove(int offset, int len) throws BadLocationException { |
630 |
public void remove(int offset, int len) throws BadLocationException { |
648 |
if (len > 0) { |
631 |
if (len > 0) { |
649 |
boolean notifyMod = false; |
632 |
boolean notifyMod = notifyModifyCheckStart(offset, "remove() vetoed"); // NOI18N |
650 |
NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get(); |
|
|
651 |
if (notifyModifyStatus == null) { // not in atomic lock |
652 |
notifyModifyStatus = new NotifyModifyStatus (this); |
653 |
STATUS.set (notifyModifyStatus); |
654 |
notifyModify(notifyModifyStatus); |
655 |
notifyMod = true; |
656 |
} |
657 |
if (notifyModifyStatus.isModificationVetoed()) { |
658 |
if (notifyMod) { |
659 |
STATUS.set (null); |
660 |
} |
661 |
throw new BadLocationException("remove() vetoed.", offset); |
662 |
} |
663 |
boolean modFinished = false; // Whether modification succeeded |
633 |
boolean modFinished = false; // Whether modification succeeded |
664 |
extWriteLock(); |
634 |
extWriteLock(); |
665 |
try { |
635 |
try { |
Lines 716-730
Link Here
|
716 |
extWriteUnlock(); |
686 |
extWriteUnlock(); |
717 |
// Notify no mod done if notified mod but mod did not succeeded |
687 |
// Notify no mod done if notified mod but mod did not succeeded |
718 |
if (notifyMod) { |
688 |
if (notifyMod) { |
719 |
STATUS.set (null); |
689 |
notifyModifyCheckEnd(modFinished); |
720 |
if (!modFinished) { |
|
|
721 |
notifyUnmodify(notifyModifyStatus); |
722 |
} |
723 |
} |
690 |
} |
724 |
} |
691 |
} |
725 |
} |
692 |
} |
726 |
} |
693 |
} |
727 |
|
694 |
|
|
|
695 |
/** |
696 |
* Check notify modify status and initialize it if necessary |
697 |
* before the actual modification is going to be done. |
698 |
* <br> |
699 |
* This method is invoked internally by this document implementation |
700 |
* and from the document event implementation as well during undo/redo. |
701 |
* |
702 |
* @param offset >=0 offset at which the modification has been done. |
703 |
* @param vetoExceptionText text to be used for exception in case |
704 |
* the modification has been vetoed. |
705 |
* @return whether the modification had to be notified or not. |
706 |
* In case it had to be notified the {@link #notifyModifyCheckEnd(boolean)} |
707 |
* has to be called. |
708 |
*/ |
709 |
boolean notifyModifyCheckStart(int offset, String vetoExceptionText) throws BadLocationException { |
710 |
NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get(); |
711 |
boolean notifyMod; |
712 |
if (notifyModifyStatus == null) { // not in atomic lock |
713 |
notifyModifyStatus = new NotifyModifyStatus (this); |
714 |
STATUS.set (notifyModifyStatus); |
715 |
notifyModify(notifyModifyStatus); |
716 |
notifyMod = true; |
717 |
} else { |
718 |
notifyMod = false; |
719 |
} |
720 |
|
721 |
if (notifyModifyStatus.isModificationVetoed()) { |
722 |
if (notifyMod) { |
723 |
STATUS.set (null); |
724 |
} |
725 |
throw new BadLocationException(vetoExceptionText, offset); |
726 |
} |
727 |
return notifyMod; |
728 |
} |
729 |
|
730 |
/** |
731 |
* Check notify modify status after the modification has been done. |
732 |
* <br> |
733 |
* This method is invoked internally by this document implementation |
734 |
* and from the document event implementation as well during undo/redo. |
735 |
* <br> |
736 |
* It should only be called if the {@link #notifyModifyCheckStart(int, String)} |
737 |
* has returned <code>true</code>. |
738 |
* |
739 |
* @param modFinished whether the actual modification of the document succeeded. |
740 |
*/ |
741 |
void notifyModifyCheckEnd(boolean modFinished) { |
742 |
NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get(); |
743 |
STATUS.set (null); |
744 |
if (!modFinished) { |
745 |
notifyUnmodify(notifyModifyStatus); |
746 |
} |
747 |
} |
748 |
|
728 |
/** This method is called automatically before the document |
749 |
/** This method is called automatically before the document |
729 |
* insertion occurs and can be used to revoke the insertion before it occurs |
750 |
* insertion occurs and can be used to revoke the insertion before it occurs |
730 |
* by throwing the <tt>BadLocationException</tt>. |
751 |
* by throwing the <tt>BadLocationException</tt>. |
Lines 1245-1251
Link Here
|
1245 |
atomicUnlockImpl(false); |
1266 |
atomicUnlockImpl(false); |
1246 |
} |
1267 |
} |
1247 |
|
1268 |
|
1248 |
public final void atomicUnlockImpl(boolean inUndoOrRedo) { |
1269 |
private final void atomicUnlockImpl(boolean inUndoOrRedo) { |
1249 |
boolean modsDone = false; |
1270 |
boolean modsDone = false; |
1250 |
boolean lastAtomic = false; |
1271 |
boolean lastAtomic = false; |
1251 |
synchronized (this) { |
1272 |
synchronized (this) { |