+ Improve Line.show to have better control over its open/visibility behavior. Previous version of Line.show + mixes open and visibility behavior into one parameter. New version separates this into 2 parameters. It is + possible to use any combination of these 2 parameters without need to add new constants for previous version. + 2 enum types ShowOpenType and ShowVisibilityType are added. +
++ XXX no answer for arch-overall +
++ XXX no answer for arch-quality +
++ XXX no answer for arch-time +
++ XXX no answer for arch-usecases +
++ XXX no answer for compat-deprecation +
++ XXX no answer for deploy-dependencies +
++ XXX no answer for exec-ant-tasks +
++ XXX no answer for exec-threading +
++ XXX no answer for perf-spi +
++ XXX no answer for resources-preferences +
++ XXX no answer for security-grant +
++ XXX no answer for security-policy +
+show
+ * @deprecated Deprecated since 6.21. Use {@link ShowOpenType#SHOW_OPEN_TYPE_NONE}
+ * and {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_NONE} instead.
*/
public final static int SHOW_TRY_SHOW = 0;
/** Opens the editor if necessary and shows the line.
* @see #show(int) show
+ * @deprecated Deprecated since 6.21. Use {@link ShowOpenType#SHOW_OPEN_TYPE_OPEN}
+ * and {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_NONE} instead.
*/
public final static int SHOW_SHOW = 1;
/** Opens the editor if necessary, shows the line, and takes the focus.
* @see #show(int) show
+ * @deprecated Deprecated since 6.21. Use {@link ShowOpenType#SHOW_OPEN_TYPE_OPEN}
+ * and {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FOCUS} instead.
*/
public final static int SHOW_GOTO = 2;
@@ -88,6 +94,8 @@
* @see #show(int) show
* @see org.openide.windows.TopComponent#toFront()
* @since 5.8
+ * @deprecated Deprecated since 6.21. Use {@link ShowOpenType#SHOW_OPEN_TYPE_OPEN}
+ * and {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FRONT} instead.
*/
public final static int SHOW_TOFRONT = 3;
@@ -98,16 +106,65 @@
* and marks it for editor reusal.
* @see #show(int) show
* @since org.openide.text 6.14
+ * @deprecated Deprecated since 6.21. Use {@link ShowOpenType#SHOW_OPEN_TYPE_REUSE}
+ * and {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FOCUS} instead.
*/
public final static int SHOW_REUSE = 4;
/** Focuses or opens given editor, marking it as reusable editor if it
- * was not opened before. Similar to {@link #SHOW_REUSE) but ignores
+ * was not opened before. Similar to {@link #SHOW_REUSE} but ignores
* currently reusable editor.
* @see #show(int) show
* @since org.openide.text 6.14
+ * @deprecated Deprecated since 6.21. Use {@link ShowOpenType#SHOW_OPEN_REUSE_NEW}
+ * and {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FOCUS} instead.
*/
public final static int SHOW_REUSE_NEW = 5;
+
+ /** ShowOpenType and ShowVisibilityType is replacement for constants SHOW_TRY_SHOW, SHOW_SHOW,
+ * SHOW_GOTO, SHOW_TOFRONT, SHOW_REUSE, SHOW_REUSE_NEW. It is to provide full control
+ * over show method behavior without need to add new constant for missing flag combination.
+ *
+ * show
+ * @see ShowVisibilityType ShowVisibilityType
+ * @since org.openide.text 6.21
+ *
+ */
+ public enum ShowOpenType {
+ /** shows the line only if the editor is open */
+ SHOW_OPEN_TYPE_NONE,
+ /** opens editor if necessary (editor was not opened) and shows the line */
+ SHOW_OPEN_TYPE_OPEN,
+ /** replaces editor marked for reuse (last editor opened using SHOW_OPEN_TYPE_REUSE
+ * or SHOW_OPEN_TYPE_REUSE_NEW) and opens editor if necessary, if editor is being opened (editor was not opened)
+ * marks it for reuse, shows the line */
+ SHOW_OPEN_TYPE_REUSE,
+ /** ignores editor marked for reuse (resets reference to editor marked for reuse),
+ * opens editor if necessary, if editor is being opened (editor was not opened)
+ * marks it for reuse, shows the line */
+ SHOW_OPEN_TYPE_REUSE_NEW
+ };
+
+ /** ShowOpenType and ShowVisibilityType is replacement for constants SHOW_TRY_SHOW, SHOW_SHOW,
+ * SHOW_GOTO, SHOW_TOFRONT, SHOW_REUSE, SHOW_REUSE_NEW. It is to provide full control
+ * over show method behavior without need to add new constant for missing flag combination.
+ *
+ * @since org.openide.text 6.21
+ * @see #show(ShowOpenType, ShowVisibilityType) show
+ * @see ShowOpenType ShowOpenType
+ */
+ public enum ShowVisibilityType {
+ /** no action */
+ SHOW_VISIBILITY_TYPE_NONE,
+ /** fronts editor component to become visible */
+ SHOW_VISIBILITY_TYPE_FRONT,
+ /** front editor component to become visible and activates/focuses it. It does
+ * the same as SHOW_VISIBILITY_TYPE_FRONT plus activates/focuses editor */
+ SHOW_VISIBILITY_TYPE_FOCUS
+ };
/** Instance of null implementation of Line.Part */
static final private Line.Part nullPart = new Line.NullPart();
@@ -187,16 +244,46 @@
/** Show the line.
* @param kind one of {@link #SHOW_TRY_SHOW}, {@link #SHOW_SHOW}, or {@link #SHOW_GOTO}
* @param column the column of this line which should be selected (starting at 0)
+ * @deprecated Deprecated since 6.21. Use {@link #show(ShowOpenType, ShowVisibilityType, int)} instead.
*/
+ @Deprecated
public abstract void show(int kind, int column);
/** Shows the line (at the first column).
* @param kind one of {@link #SHOW_TRY_SHOW}, {@link #SHOW_SHOW}, {@link #SHOW_GOTO},
* {@link #SHOW_REUSE} or {@link #SHOW_REUSE_NEW}
* @see #show(int, int)
+ * @deprecated Deprecated since 6.21. Use {@link #show(ShowOpenType, ShowVisibilityType)} instead.
*/
+ @Deprecated
public void show(int kind) {
show(kind, 0);
+ }
+
+ /** Show the line.
+ * @param openType one of {@link ShowOpenType#SHOW_OPEN_TYPE_NONE},
+ * {@link ShowOpenType#SHOW_OPEN_TYPE_OPEN},
+ * {@link ShowOpenType#SHOW_OPEN_TYPE_REUSE}
+ * or {@link ShowOpenType#SHOW_OPEN_TYPE_REUSE_NEW}
+ * @param visibilityType one of {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_NONE},
+ * {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FRONT}
+ * or {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FOCUS}
+ * @param column the column of this line which should be selected (starting at 0)
+ * @since org.openide.text 6.21
+ */
+ public abstract void show(ShowOpenType openType, ShowVisibilityType visibilityType, int column);
+
+ /** Shows the line (at the first column).
+ * @param openType one of {@link ShowOpenType#SHOW_OPEN_TYPE_NONE}, {@link ShowOpenType#SHOW_OPEN_TYPE_OPEN},
+ * {@link ShowOpenType#SHOW_OPEN_TYPE_REUSE} or {@link ShowOpenType#SHOW_OPEN_TYPE_REUSE_NEW}
+ * @param visibilityType one of {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_NONE},
+ * {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FRONT}
+ * or {@link ShowVisibilityType#SHOW_VISIBILITY_TYPE_FOCUS}
+ * @see #show(ShowOpenType, ShowVisibilityType, int)
+ * @since org.openide.text 6.21
+ */
+ public void show(ShowOpenType openType, ShowVisibilityType visibilityType) {
+ show(openType, visibilityType, 0);
}
/** Set or clear a (debugger) breakpoint at this line.
diff -r bd56db0c90b6 openide.text/test/unit/src/org/openide/text/CloneableEditorSupportPaneTest.java
--- a/openide.text/test/unit/src/org/openide/text/CloneableEditorSupportPaneTest.java Fri Jul 04 10:43:39 2008 +0200
+++ b/openide.text/test/unit/src/org/openide/text/CloneableEditorSupportPaneTest.java Fri Jul 11 19:18:15 2008 +0200
@@ -116,8 +116,23 @@
assertTrue(instance.activated);
}
+
+ /** Test with new Line.show API */
+ public void testGetOpenedPanes2 () throws Exception {
+ content = "Ahoj\nMyDoc";
+ javax.swing.text.Document doc = support.openDocument ();
+ support.open();
+ Line line = support.getLineSet().getCurrent(0);
+ line.show(Line.ShowOpenType.SHOW_OPEN_TYPE_OPEN, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE);
+ JEditorPane[] panes = support.getOpenedPanes();
+ assertNotNull(panes);
+ assertEquals(1, panes.length);
+ assertNotNull(instance);
+ assertTrue(instance.activated);
+
+ }
- public void testGetOpenedPanes2ForSeparatePane() throws Exception {
+ public void testGetOpenedPanes2ForSeparatePane() throws Exception {
content = "Ahoj\nMyDoc";
javax.swing.text.Document doc = support2.openDocument ();
support2.open();
@@ -127,10 +142,21 @@
assertNotNull(panes);
assertEquals(1, panes.length);
assertNotNull(instance2);
-
}
-
+ /** Test with new Line.show API */
+ public void testGetOpenedPanes2ForSeparatePane2() throws Exception {
+ content = "Ahoj\nMyDoc";
+ javax.swing.text.Document doc = support2.openDocument ();
+ support2.open();
+ Line line = support2.getLineSet().getCurrent(0);
+ line.show(Line.ShowOpenType.SHOW_OPEN_TYPE_OPEN, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE);
+ JEditorPane[] panes = support2.getOpenedPanes();
+ assertNotNull(panes);
+ assertEquals(1, panes.length);
+ assertNotNull(instance2);
+ }
+
public void testDocumentSaveCancelledByUser() throws Exception {
//register DialogDisplayer which "pushes" Yes option in the document save dialog
MockServices.setServices(DD.class);
diff -r bd56db0c90b6 openide.text/test/unit/src/org/openide/text/ReusableEditor2Test.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openide.text/test/unit/src/org/openide/text/ReusableEditor2Test.java Fri Jul 11 19:18:15 2008 +0200
@@ -0,0 +1,343 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+
+package org.openide.text;
+
+
+import java.beans.PropertyChangeListener;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.JEditorPane;
+import junit.framework.*;
+import org.netbeans.junit.*;
+import org.openide.util.Lookup;
+import org.openide.util.Mutex;
+import org.openide.util.lookup.*;
+
+
+/** Testing the behavior of editor reusal framework. It uses new Line.show API.
+ * The behavior was discussed thoroughly at issue 94607.
+ *
+ * @author Petr Nejedly, Marek Slama
+ */
+public class ReusableEditor2Test extends NbTestCase {
+ static {
+ System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false");
+ }
+ CES c1, c2, c3;
+
+ /**
+ * Test ctor
+ * @param testName
+ */
+ public ReusableEditor2Test(java.lang.String testName) {
+ super(testName);
+ }
+
+
+ /**
+ * Prepares few editors at the test dispoition.
+ */
+ protected void setUp () {
+ c1 = createSupport("c1");
+ c2 = createSupport("c2");
+ c3 = createSupport("c3");
+ }
+
+ /**
+ * Closes any precreated editors left open.
+ */
+ @Override
+ protected void tearDown() {
+ forceClose(c1);
+ forceClose(c2);
+ forceClose(c3);
+ }
+
+ /**
+ * Test that verifies ShowOpenType.SHOW_OPEN_TYPE_REUSE closes original tab (keeps only one)
+ * Scenario:
+ * 1. Open first file with ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 2. Open second file with ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 3. Verify first is closed
+ * 4. Open first file with ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 5. Verify second is closed
+ */
+ public void testReuse() {
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 1
+ openAndCheck(c2, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 2
+ assertClosed(c1); // 3
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 4
+ assertClosed(c2); // 5
+ }
+
+ /** Test that verifies ShowOpenType.SHOW_OPEN_TYPE_REUSE doesn't reuse modified, even saved tab
+ * 1. Open first file with ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 2. Modify it
+ * 3. Open second file with ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 4. Verify first still open
+ * 5. Modify second file
+ * 6. Unmodify second file
+ * 7. Open third file with ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 8. Verify second still open
+ */
+ public void testKeepTouched() {
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 1
+ c1.notifyModified(); // 2
+ openAndCheck(c2, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 3
+ assertOpened(c1); // 4
+ c2.notifyModified(); // 5
+ c2.notifyUnmodified(); // 6
+ openAndCheck(c3, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 7
+ assertOpened(c2); // 8
+ assertOpened(c1);
+ }
+
+ /** Test that verifies ShowOpenType.SHOW_OPEN_TYPE_REUSE don't consider non-reusable tabs.
+ * There are three things tested:
+ * A) Don't replace ordinary tabs
+ * B) Don't mark ordinary tabs as reusable if switched to
+ * C) Keep reusable tab mark even through (B)
+ *
+ * Scenario:
+ * 1. Open first file using ShowOpenType.SHOW_OPEN_TYPE_OPEN and ShowVisibilityType.SHOW_VISIBILITY_TYPE_FOCUS
+ * 2. Open second file using ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 3. Verify first still opened (A)
+ * 4. open first using ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 5. verify second still opened
+ * 6. open third file using ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 7. verify first still opened (B)
+ * 8. verify second closed (C)
+ */
+ public void testLeaveNonreusable() {
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_OPEN, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_FOCUS); // 1
+ openAndCheck(c2, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 2
+ assertOpened(c1); // 3
+
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 4
+ assertOpened(c2); // 5
+ openAndCheck(c3, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 6
+ assertOpened(c1); // 7
+
+ assertClosed(c2); // 8
+ }
+
+ /** Test that verifies ShowOpenType.SHOW_OPEN_TYPE_REUSE_NEW don't close existing reusable tab,
+ * but can be reused itself
+ *
+ * Scenario:
+ * 1. Open first file using ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 2. Open second file using ShowOpenType.SHOW_OPEN_TYPE_REUSE_NEW
+ * 3. Verify first still opened
+ * 4. Open third using ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 5. verify second closed
+ */
+ public void testReuseNewKeepsOld() {
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 1
+ openAndCheck(c2, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE_NEW, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 2
+ assertOpened(c1); // 3
+ openAndCheck(c3, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 4
+ assertClosed(c2); // 5
+ }
+
+ /**
+ * Test that specifies behaviour of ShowOpenType.SHOW_OPEN_TYPE_REUSE_NEW in case currently
+ * reusable tab is not the selected one.
+ *
+ * Scenario:
+ * 1. Open first file using ShowOpenType.SHOW_OPEN_TYPE_REUSE
+ * 2. Open second file using ShowOpenType.SHOW_OPEN_TYPE_OPEN + ShowVisibilityType.SHOW_VISIBILITY_TYPE_FOCUS
+ * 3. Open third file using ShowOpenType.SHOW_OPEN_TYPE_REUSE_NEW
+ * 4. Verify first still open.
+ */
+ public void testReuseNewKeepsOldEvenWhenNotFocused() {
+ openAndCheck(c1, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 1
+ openAndCheck(c2, Line.ShowOpenType.SHOW_OPEN_TYPE_OPEN, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_FOCUS); // 2
+ openAndCheck(c3, Line.ShowOpenType.SHOW_OPEN_TYPE_REUSE_NEW, Line.ShowVisibilityType.SHOW_VISIBILITY_TYPE_NONE); // 3
+ assertOpened(c1); // 4
+ }
+
+ private CES createSupport(String txt) {
+ Env env = new Env();
+ env.content = txt;
+ CES c = new CES(env, Lookups.singleton(txt));
+ env.support = c;
+ return c;
+ }
+
+ private void openAndCheck(final CES ces, final Line.ShowOpenType openType, final Line.ShowVisibilityType visibilityType) {
+ Mutex.EVENT.readAccess(new Mutex.Action