This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 249321
Collapse All | Expand All

(-)a/api.io/apichanges.xml (+47 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
<changes>
109
<changes>
110
    <change id="hyperlink.intent.support">
111
      <api name="io.spi"/>
112
      <summary>Add features for dealing with Intent based hyperlinks</summary>
113
      <version major="1" minor="1"/>
114
      <date day="12" month="12" year="2014"/>
115
      <author login="jhavlin"/>
116
      <compatibility addition="yes" binary="compatible" semantic="compatible" />
117
      <description>
118
          <p>
119
              As there are now two types of hyperlinks, which may be handled
120
              differently in some situations, we need some way to get info about
121
              the type and internals of hyperlinks.
122
          </p>
123
          <p>
124
              Added new enum <a href="@TOP@/org/netbeans/spi/io/support/HyperlinkType.html">HyperlinkType</a>
125
              and new methods into class <a href="@TOP@/org/netbeans/spi/io/support/Hyperlinks.html">Hyperlinks</a>:
126
          </p>
127
          <ul>
128
              <li><a href="@TOP@/org/netbeans/spi/io/support/Hyperlinks.html#getType(org.netbeans.api.io.Hyperlink)">Hyperlinks.getType(Hyperlink)</a></li>
129
              <li><a href="@TOP@/org/netbeans/spi/io/support/Hyperlinks.html#getIntent(org.netbeans.api.io.Hyperlink)">Hyperlinks.getIntent(Hyperlink)</a></li>
130
              <li><a href="@TOP@/org/netbeans/spi/io/support/Hyperlinks.html#getRunnable(org.netbeans.api.io.Hyperlink)">Hyperlinks.getRunnable(Hyperlink)</a></li>
131
          </ul>
132
      </description>
133
      <issue number="249321" />
134
    </change>
135
    <change id="hyperlink.intent">
136
      <api name="io.api"/>
137
      <summary>Support hyperlinks based on Intents</summary>
138
      <version major="1" minor="1"/>
139
      <date day="12" month="12" year="2014"/>
140
      <author login="jhavlin"/>
141
      <compatibility addition="yes" binary="compatible" semantic="compatible" />
142
      <description>
143
          <p>
144
              Besides hyperlinks based on Runnables, support also hyperlinks
145
              that are defined by an Intent instance.
146
          </p>
147
          <p>
148
              Added new static methods into class <a href="@TOP@/org/netbeans/api/io/Hyperlink.html">Hyperlink</a>:
149
          </p>
150
          <ul>
151
              <li><a href="@TOP@/org/netbeans/api/io/Hyperlink.html#from(org.netbeans.api.intent.Intent)">Hyperlink.from(Intent)</a></li>
152
              <li><a href="@TOP@/org/netbeans/api/io/Hyperlink.html#from(org.netbeans.api.intent.Intent, boolean)">Hyperlink.from(Intent, boolean)</a></li>
153
          </ul>
154
      </description>
155
      <issue number="249321" />
156
    </change>
110
    <change id="introduction.api">
157
    <change id="introduction.api">
111
      <api name="io.api"/>
158
      <api name="io.api"/>
112
      <summary>Introduce new I/O API</summary>
159
      <summary>Introduce new I/O API</summary>
(-)a/api.io/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
AutoUpdate-Show-In-Client: true
2
AutoUpdate-Show-In-Client: true
3
OpenIDE-Module: org.netbeans.api.io
3
OpenIDE-Module: org.netbeans.api.io
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/io/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/io/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.0
5
OpenIDE-Module-Specification-Version: 1.1
6
OpenIDE-Module-Recommends: org.netbeans.spi.io.InputOutputProvider
6
OpenIDE-Module-Recommends: org.netbeans.spi.io.InputOutputProvider
(-)a/api.io/nbproject/project.xml (+8 lines)
Lines 15-20 Link Here
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.api.intent</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <specification-version>1.0</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
18
                    <code-name-base>org.openide.util</code-name-base>
26
                    <code-name-base>org.openide.util</code-name-base>
19
                    <build-prerequisite/>
27
                    <build-prerequisite/>
20
                    <compile-dependency/>
28
                    <compile-dependency/>
(-)a/api.io/src/org/netbeans/api/io/Hyperlink.java (-1 / +50 lines)
Lines 42-47 Link Here
42
package org.netbeans.api.io;
42
package org.netbeans.api.io;
43
43
44
import org.netbeans.api.annotations.common.NonNull;
44
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.intent.Intent;
45
import org.netbeans.modules.io.HyperlinkAccessor;
46
import org.netbeans.modules.io.HyperlinkAccessor;
46
import org.openide.util.Parameters;
47
import org.openide.util.Parameters;
47
48
Lines 103-112 Link Here
103
    @NonNull
104
    @NonNull
104
    public static Hyperlink from(@NonNull Runnable runnable,
105
    public static Hyperlink from(@NonNull Runnable runnable,
105
            boolean important) {
106
            boolean important) {
106
        Parameters.notNull("runnable", runnable);
107
        Parameters.notNull("runnable", runnable);                       //NOI18N
107
        return new OnClickHyperlink(runnable, important);
108
        return new OnClickHyperlink(runnable, important);
108
    }
109
    }
109
110
111
    /**
112
     * Create a new hyperlink for specified {@link Intent}, which will be
113
     * executed when the line is clicked.
114
     *
115
     * @param intent The intent to execute on click.
116
     * @return The new hyperlink.
117
     */
118
    public static Hyperlink from(@NonNull Intent intent) {
119
        return from(intent, false);
120
    }
121
122
    /**
123
     * Create a new hyperlink for specified {@link Intent}, which will be
124
     * executed when the line is clicked.
125
     *
126
     * <div class="nonnormative">
127
     * <p>
128
     * Important hyperlinks can be printed in different color, or can have some
129
     * special behavior, e.g. automatic scrolling can be switched off to keep
130
     * the important hyperlink visible.
131
     * </p>
132
     * </div>
133
     *
134
     * @param intent The intent to execute on click.
135
     * @param important True if the hyperlink should be handled as an important
136
     * one, false if it is a standard one.
137
     * @return The new hyperlink.
138
     */
139
    public static Hyperlink from(@NonNull Intent intent, boolean important) {
140
        Parameters.notNull("intent", intent);                           //NOI18N
141
        return new IntentHyperlink(intent, important);
142
    }
143
110
    @SuppressWarnings("PackageVisibleInnerClass")
144
    @SuppressWarnings("PackageVisibleInnerClass")
111
    static class OnClickHyperlink extends Hyperlink {
145
    static class OnClickHyperlink extends Hyperlink {
112
146
Lines 121-124 Link Here
121
            return runnable;
155
            return runnable;
122
        }
156
        }
123
    }
157
    }
158
159
    @SuppressWarnings("PackageVisibleInnerClass")
160
    static class IntentHyperlink extends Hyperlink {
161
162
        private final Intent intent;
163
164
        public IntentHyperlink(Intent intent, boolean important) {
165
            super(important);
166
            this.intent = intent;
167
        }
168
169
        public Intent getIntent() {
170
            return intent;
171
        }
172
    }
124
}
173
}
(-)a/api.io/src/org/netbeans/api/io/HyperlinkAccessorImpl.java (-2 / +16 lines)
Lines 41-48 Link Here
41
 */
41
 */
42
package org.netbeans.api.io;
42
package org.netbeans.api.io;
43
43
44
import org.netbeans.api.intent.Intent;
44
import org.netbeans.modules.io.HyperlinkAccessor;
45
import org.netbeans.modules.io.HyperlinkAccessor;
45
import org.netbeans.modules.io.HyperlinkType;
46
import org.netbeans.spi.io.support.HyperlinkType;
46
47
47
/**
48
/**
48
 * Implementation of accessor that enables retrieving information about
49
 * Implementation of accessor that enables retrieving information about
Lines 56-61 Link Here
56
    public HyperlinkType getType(Hyperlink hyperlink) {
57
    public HyperlinkType getType(Hyperlink hyperlink) {
57
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
58
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
58
            return HyperlinkType.FROM_RUNNABLE;
59
            return HyperlinkType.FROM_RUNNABLE;
60
        } else if (hyperlink instanceof Hyperlink.IntentHyperlink) {
61
            return HyperlinkType.FROM_INTENT;
59
        } else {
62
        } else {
60
            throw new IllegalArgumentException("Unknown hyperlink.");   //NOI18N
63
            throw new IllegalArgumentException("Unknown hyperlink.");   //NOI18N
61
        }
64
        }
Lines 71-77 Link Here
71
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
74
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
72
            return ((Hyperlink.OnClickHyperlink) hyperlink).getRunnable();
75
            return ((Hyperlink.OnClickHyperlink) hyperlink).getRunnable();
73
        } else {
76
        } else {
74
            throw new IllegalArgumentException("Not an ON_CLICK link.");//NOI18N
77
            throw new IllegalArgumentException(
78
                    "Not an FROM_RUNNABLE link.");                      //NOI18N
79
        }
80
    }
81
82
    @Override
83
    public Intent getIntent(Hyperlink hyperlink) {
84
        if (hyperlink instanceof Hyperlink.IntentHyperlink) {
85
            return ((Hyperlink.IntentHyperlink) hyperlink).getIntent();
86
        } else {
87
            throw new IllegalArgumentException(
88
                    "Not a FROM_INTENT link");                          //NOI18N
75
        }
89
        }
76
    }
90
    }
77
}
91
}
(-)a/api.io/src/org/netbeans/modules/io/HyperlinkAccessor.java (+4 lines)
Lines 41-46 Link Here
41
 */
41
 */
42
package org.netbeans.modules.io;
42
package org.netbeans.modules.io;
43
43
44
import org.netbeans.api.intent.Intent;
45
import org.netbeans.spi.io.support.HyperlinkType;
44
import org.netbeans.api.io.Hyperlink;
46
import org.netbeans.api.io.Hyperlink;
45
47
46
/**
48
/**
Lines 82-85 Link Here
82
    public abstract boolean isImportant(Hyperlink hyperlink);
84
    public abstract boolean isImportant(Hyperlink hyperlink);
83
85
84
    public abstract Runnable getRunnable(Hyperlink hyperlink);
86
    public abstract Runnable getRunnable(Hyperlink hyperlink);
87
88
    public abstract Intent getIntent(Hyperlink hyperlink);
85
}
89
}
(-)a/api.io/src/org/netbeans/modules/io/HyperlinkType.java (-9 / +13 lines)
Lines 39-62 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
41
 */
42
package org.netbeans.modules.io;
42
package org.netbeans.spi.io.support;
43
43
44
import org.netbeans.spi.io.support.Hyperlinks;
44
import org.netbeans.api.intent.Intent;
45
import org.netbeans.api.io.Hyperlink;
45
46
46
/**
47
/**
47
 * Type of the hyperlink.
48
 * Type of the hyperlink.
48
 * <p>
49
 * <p>
49
 * Note: New items may be added in the future.
50
 * Note: New items may be added in the future.
50
 * </p>
51
 * </p>
51
 * <p>
52
 * Note: When more hyperlink types are added, this enum can be moved to package
53
 * org.netbeans.spi.io.support, and getType(), getRunnable() (for correct type)
54
 * methods can be added to {@link Hyperlinks} class. So that implementation can
55
 * work with specific hyperlink types differently. See bug 247404.
56
 * </p>
57
 *
52
 *
58
 * @author jhavlin
53
 * @author jhavlin
59
 */
54
 */
60
public enum HyperlinkType {
55
public enum HyperlinkType {
61
    FROM_RUNNABLE
56
    /**
57
     * Hyperlink created using {@link Hyperlink#from(java.lang.Runnable)} or
58
     * {@link Hyperlink#from(java.lang.Runnable, boolean)}.
59
     */
60
    FROM_RUNNABLE,
61
    /**
62
     * Hyperlink created using {@link Hyperlink#from(Intent)} or
63
     * {@link Hyperlink#from(Intent, boolean)}.
64
     */
65
    FROM_INTENT
62
}
66
}
(-)a/api.io/src/org/netbeans/spi/io/support/Hyperlinks.java (-3 / +23 lines)
Lines 41-48 Link Here
41
 */
41
 */
42
package org.netbeans.spi.io.support;
42
package org.netbeans.spi.io.support;
43
43
44
import org.netbeans.modules.io.HyperlinkType;
45
import org.netbeans.api.annotations.common.NonNull;
44
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.intent.Intent;
46
import org.netbeans.api.io.Hyperlink;
46
import org.netbeans.api.io.Hyperlink;
47
import org.netbeans.modules.io.HyperlinkAccessor;
47
import org.netbeans.modules.io.HyperlinkAccessor;
48
48
Lines 63-69 Link Here
63
     * @return The type of the hyperlink.
63
     * @return The type of the hyperlink.
64
     */
64
     */
65
    @NonNull
65
    @NonNull
66
    static HyperlinkType getType(@NonNull Hyperlink hyperlink) {
66
    public static HyperlinkType getType(@NonNull Hyperlink hyperlink) {
67
        return HyperlinkAccessor.getDefault().getType(hyperlink);
67
        return HyperlinkAccessor.getDefault().getType(hyperlink);
68
    }
68
    }
69
69
Lines 100-110 Link Here
100
     * @see HyperlinkType
100
     * @see HyperlinkType
101
     */
101
     */
102
    @NonNull
102
    @NonNull
103
    static Runnable getRunnable(@NonNull Hyperlink hyperlink) {
103
    public static Runnable getRunnable(@NonNull Hyperlink hyperlink) {
104
        return HyperlinkAccessor.getDefault().getRunnable(hyperlink);
104
        return HyperlinkAccessor.getDefault().getRunnable(hyperlink);
105
    }
105
    }
106
106
107
    /**
107
    /**
108
     * Get intent associated with a hyperlink of type
109
     * {@link HyperlinkType#FROM_INTENT}.
110
     *
111
     * @param hyperlink  The hyperlink to get intent from.
112
     *
113
     * @return An intent.
114
     * @throws IllegalArgumentException if type of the hyperlink is not
115
     * {@link HyperlinkType#FROM_INTENT}.
116
     * @see #getType(org.netbeans.api.io.Hyperlink)
117
     * @see HyperlinkType
118
     */
119
    @NonNull
120
    public static Intent getIntent(@NonNull Hyperlink hyperlink) {
121
        return HyperlinkAccessor.getDefault().getIntent(hyperlink);
122
    }
123
124
    /**
108
     * Invoke appropriate action for the hyperlink.
125
     * Invoke appropriate action for the hyperlink.
109
     *
126
     *
110
     * @param hyperlink Hyperlink to invoke.
127
     * @param hyperlink Hyperlink to invoke.
Lines 114-119 Link Here
114
            case FROM_RUNNABLE:
131
            case FROM_RUNNABLE:
115
                getRunnable(hyperlink).run();
132
                getRunnable(hyperlink).run();
116
                break;
133
                break;
134
            case FROM_INTENT:
135
                getIntent(hyperlink).execute(null);
136
                break;
117
            default:
137
            default:
118
                break;
138
                break;
119
        }
139
        }
(-)a/api.io/test/unit/src/org/netbeans/spi/io/support/HyperlinksTest.java (-1 / +11 lines)
Lines 41-50 Link Here
41
 */
41
 */
42
package org.netbeans.spi.io.support;
42
package org.netbeans.spi.io.support;
43
43
44
import java.net.URI;
45
import java.net.URISyntaxException;
44
import static org.junit.Assert.*;
46
import static org.junit.Assert.*;
45
import org.junit.Test;
47
import org.junit.Test;
48
import org.netbeans.api.intent.Intent;
46
import org.netbeans.api.io.Hyperlink;
49
import org.netbeans.api.io.Hyperlink;
47
import org.netbeans.modules.io.HyperlinkType;
48
50
49
/**
51
/**
50
 *
52
 *
Lines 79-82 Link Here
79
        }, true);
81
        }, true);
80
        assertTrue(Hyperlinks.isImportant(h));
82
        assertTrue(Hyperlinks.isImportant(h));
81
    }
83
    }
84
85
    @Test
86
    public void testIntentHyperlink() throws URISyntaxException {
87
        Intent i = new Intent(Intent.ACTION_EDIT, new URI("scheme://abc"));
88
        Hyperlink h = Hyperlink.from(i);
89
        assertEquals(HyperlinkType.FROM_INTENT, Hyperlinks.getType(h));
90
        assertEquals(i, Hyperlinks.getIntent(h));
91
    }
82
}
92
}

Return to bug 249321