diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoringAction.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoringAction.java new file mode 100644 index 000000000000..a01e58c050f9 --- /dev/null +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoringAction.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.lsp.server.refactoring; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import org.netbeans.api.java.source.ElementHandle; +import org.netbeans.api.java.source.JavaSource; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; +import org.openide.filesystems.FileObject; +import org.openide.util.NbBundle.Messages; + +@ActionID( + category = "Refactoring", + id = "org.netbeans.modules.java.lsp.server.refactoring.ChangeMethodParametersRefactoringAction" +) +@ActionRegistration( + iconBase = "org/netbeans/modules/java/lsp/server/refactoring/newHTML.png", + displayName = "#CTL_ChangeMethodParametersRefactoringAction" +) +@ActionReference(path = "Menu/Refactoring", position = 1120) +@Messages("CTL_ChangeMethodParametersRefactoringAction=Change Method Parameters Refactoring") +public final class ChangeMethodParametersRefactoringAction implements ActionListener { + private final FileObject file; + + public ChangeMethodParametersRefactoringAction(FileObject file) { + this.file = file; + } + + @Override + public void actionPerformed(ActionEvent evt) { + JavaSource js = JavaSource.forFileObject(file); + if (js != null) { + try { + js.runUserActionTask(ci -> { + ci.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); + ExecutableElement method = null; + METHOD: for (Element type : ci.getTopLevelElements()) { + for (Element e : type.getEnclosedElements()) { + System.err.println("e: " + e); + if (e.getKind() == ElementKind.METHOD) { + method = (ExecutableElement) e; + break METHOD; + } + } + } + if (method != null) { + ElementHandle handle = ElementHandle.create(method); + Pages.showChangeMethodParametersUI(ci, null, file, handle, method); + } + }, true); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + } +} diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/newHTML.png b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/newHTML.png new file mode 100644 index 000000000000..608de64f86ce Binary files /dev/null and b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/newHTML.png differ diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ui/TestHtmlUI.html b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ui/TestHtmlUI.html new file mode 100644 index 000000000000..747fe464be71 --- /dev/null +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ui/TestHtmlUI.html @@ -0,0 +1,45 @@ + + + + TestHtmlUI + + + +
+ + + + + + + + \ No newline at end of file diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ui/TestHtmlUICntrl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ui/TestHtmlUICntrl.java new file mode 100644 index 000000000000..c33fb93b9068 --- /dev/null +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ui/TestHtmlUICntrl.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.lsp.server.refactoring.ui; + +import net.java.html.json.Model; +import net.java.html.json.Function; +import net.java.html.json.Property; +import net.java.html.json.ComputedProperty; +import org.netbeans.api.htmlui.OpenHTMLRegistration; +import org.netbeans.api.htmlui.HTMLDialog; +import org.openide.util.NbBundle; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; + +/** + * HTML page which displays a window and also a dialog. + */ +@Model(className = "TestHtmlUI", targetId = "", properties = { + @Property(name = "text", type = String.class) +}) +public final class TestHtmlUICntrl { + + @ComputedProperty + static String templateName() { + return "window"; + } + + @Function + static void showDialog(TestHtmlUI model) { + String reply = Pages.showTestHtmlUIDialog(model.getText()); + if ("OK".equals(reply)) { + model.setText("Happy World!"); + } else { + model.setText("Sad World!"); + } + } + + @ActionID( + category = "Tools", + id = "org.netbeans.modules.java.lsp.server.refactoring.ui.TestHtmlUI" + ) + @ActionReferences({ + @ActionReference(path = "Menu/Refactoring", position = 1125) + }) + @NbBundle.Messages("CTL_TestHtmlUI=Open HTML Hello World!") + @OpenHTMLRegistration( + url = "TestHtmlUI.html", + displayName = "#CTL_TestHtmlUI" + //, iconBase="SET/PATH/TO/ICON/HERE" + ) + public static TestHtmlUI onPageLoad() { + return new TestHtmlUI("Hello World!").applyBindings(); + } + + // + // dialog UI + // + @HTMLDialog(url = "TestHtmlUI.html") + static void showTestHtmlUIDialog(String t) { + new TestHtmlUIDialog(t, false).applyBindings(); + } + + @Model(className = "TestHtmlUIDialog", targetId = "", properties = { + @Property(name = "text", type = String.class), + @Property(name = "ok", type = boolean.class),}) + static final class DialogCntrl { + + @ComputedProperty + static String templateName() { + return "dialog"; + } + } +}