dbalek commented on a change in pull request #3333:
URL: https://github.com/apache/netbeans/pull/3333#discussion_r758238887



##########
File path: 
ide/editor.completion/src/org/netbeans/spi/editor/completion/support/CompletionUtilities.java
##########
@@ -160,5 +164,152 @@ public static void renderHtml(ImageIcon icon, String 
leftHtmlText, String rightH
                 defaultFont, defaultColor, PatchedHtmlRenderer.STYLE_TRUNCATE, 
true, selected);
         }
     }
-    
+
+    /**
+     * Creates a builder for simple {@link CompletionItem} instances.
+     *
+     * @param insertText a text to be inserted into a document when selecting 
the item.
+     * @return newly created builder
+     *
+     * @since 1.60
+     */
+    public static CompletionItemBuilder newCompletionItemBuilder(String 
insertText) {
+        return new CompletionItemBuilder(insertText);
+    }
+
+    /**
+     * Builder for simple {@link CompletionItem} instances.
+     *
+     * @since 1.60
+     */
+    public static final class CompletionItemBuilder {
+
+        private String insertText;
+        private String insertTemplateText;
+        private int startOffset = -1;
+        private int endOffset = -1;
+        private String iconResource;
+        private String leftHtmlText;
+        private String rightHtmlText;
+        private int sortPriority = 10000;
+        private CharSequence sortText;
+        private BiConsumer<JTextComponent, Boolean> onSelectCallback;
+
+        private CompletionItemBuilder(String insertText) {
+            this.insertText = insertText;
+        }
+
+        /**
+         * A text to be inserted into a document when selecting the item.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder insertText(String insertText) {
+            this.insertText = insertText;
+            return this;
+        }
+
+        /**
+         * A text of the template to be inserted into a document when 
selecting the item.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder insertTemplate(String templateText) {
+            this.insertTemplateText = templateText;
+            return this;
+        }
+
+        /**
+         * Start offset of the region to be removed on the item's selection. 
If omitted,
+         * the caret offset would be used.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder startOffset(int offset) {
+            this.startOffset = offset;
+            return this;
+        }
+
+        /**
+         * Start offset of the region to be removed on the item's selection. 
If omitted,
+         * the caret offset would be used.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder endOffset(int offset) {
+            this.endOffset = offset;
+            return this;
+        }
+
+        /**
+         * Resource path of the icon. It may be null which means that no icon 
will be displayed.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder iconResource(String iconResource) {
+            this.iconResource = iconResource;
+            return this;
+        }
+
+        /**
+         * An html text that will be displayed on the left side of the item 
next to the icon.
+         * If omitted, insert text would be used instead.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder leftHtmlText(String leftHtmlText) {
+            this.leftHtmlText = leftHtmlText;
+            return this;
+        }
+
+        /**
+         * An html text that will be aligned to the right edge of the item.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder rightHtmlText(String rightHtmlText) {
+            this.rightHtmlText = rightHtmlText;
+            return this;
+        }
+
+        /**
+         * Item's priority. A lower value means a lower index of the item in 
the completion result list.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder sortPriority(int sortPriority) {
+            this.sortPriority = sortPriority;
+            return this;
+        }
+
+        /**
+         * A text used to sort items alphabetically. If omitted, insertText 
would be used instead.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder sortText(CharSequence sortText) {
+            this.sortText = sortText;
+            return this;
+        }
+
+        /**
+         * A callback to process the item insertion. Should be used for 
complex cases
+         * when a simple insertText insertion is not sufficient.
+         *
+         * @since 1.60
+         */
+        public CompletionItemBuilder onSelect(BiConsumer<JTextComponent, 
Boolean> callback) {

Review comment:
       Modified to allow for future evolution.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to