From a2b363340ed857b6704b3e1ef6581525f9a42f2a Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sun, 11 May 2025 11:50:26 +0200 Subject: [PATCH] migrate forms to use generated code --- .../ui/ServiceArgumentSelectionDialog.java | 63 +++++- .../action/ui/SymfonyCreateService.java | 205 ++++++++++++++---- .../ui/SymfonyJavascriptServiceNameForm.java | 109 +++++++++- 3 files changed, 323 insertions(+), 54 deletions(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java index 3c9247036..b307415ca 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java @@ -5,6 +5,9 @@ import com.intellij.openapi.ui.ComboBox; import com.intellij.ui.ToolbarDecorator; import com.intellij.ui.table.TableView; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.ui.ListTableModel; import com.jetbrains.php.lang.psi.elements.PhpClass; @@ -67,7 +70,7 @@ public void init() { this.closeButton.addActionListener(e -> onCancel()); this.getRootPane().registerKeyboardAction(e -> - onCancel(), + onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); @@ -97,15 +100,51 @@ private void createUIComponents() { this.tableView.setModelAndUpdateColumns(this.modelList); mainPanel.add(ToolbarDecorator.createDecorator(this.tableView) - .disableAddAction() - .disableDownAction() - .disableRemoveAction() - .disableUpDownActions() - .createPanel() + .disableAddAction() + .disableDownAction() + .disableRemoveAction() + .disableUpDownActions() + .createPanel() ); } + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + createUIComponents(); + panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(2, 3, new Insets(5, 5, 5, 5), -1, -1)); + generateButton = new JButton(); + generateButton.setText("Generate"); + panel1.add(generateButton, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + closeButton = new JButton(); + closeButton.setText("Close"); + panel1.add(closeButton, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + panel1.add(mainPanel, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return panel1; + } + private static class ServiceParameter { private final String classFqn; @@ -117,7 +156,7 @@ public ServiceParameter(String classFqn, Set possibleServices) { this.classFqn = classFqn; this.possibleServices = possibleServices; - if(!possibleServices.isEmpty()) { + if (!possibleServices.isEmpty()) { currentService = possibleServices.iterator().next(); } @@ -159,16 +198,16 @@ public NamespaceColumn() { public String valueOf(ServiceParameter modelParameter) { String classFqn = modelParameter.getClassFqn(); - if(StringUtils.isBlank(classFqn)) { + if (StringUtils.isBlank(classFqn)) { return "unknown"; } - if(classFqn.startsWith("\\")) { + if (classFqn.startsWith("\\")) { classFqn = classFqn.substring(1); } int i = classFqn.lastIndexOf("\\"); - if(i > 0) { + if (i > 0) { String ns = classFqn.substring(0, i); String clazz = classFqn.substring(i + 1); classFqn = String.format("%s [%s]", clazz, ns); @@ -191,7 +230,7 @@ public String valueOf(ServiceParameter modelParameter) { return modelParameter.getCurrentService(); } - public void setValue(ServiceParameter modelParameter, String value){ + public void setValue(ServiceParameter modelParameter, String value) { modelParameter.setCurrentService(value); tableView.getListTableModel().fireTableDataChanged(); } @@ -225,7 +264,7 @@ public Icon valueOf(ServiceParameter modelParameter) { return classInterface != null ? classInterface.getIcon() : null; } - public java.lang.Class getColumnClass() { + public Class getColumnClass() { return ImageIcon.class; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyCreateService.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyCreateService.java index da3230fdc..4c0d18b3e 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyCreateService.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyCreateService.java @@ -1,5 +1,6 @@ package fr.adrienbrault.idea.symfony2plugin.action.ui; +import com.intellij.concurrency.ThreadContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; @@ -14,6 +15,9 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.ui.ToolbarDecorator; import com.intellij.ui.table.TableView; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.ui.ListTableModel; import com.jetbrains.php.lang.psi.elements.*; @@ -37,7 +41,9 @@ import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.plaf.FontUIResource; import javax.swing.table.TableCellEditor; +import javax.swing.text.StyleContext; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; @@ -123,14 +129,14 @@ public void init() { } // overwrite language output on direct file context - if(this.psiFile instanceof YAMLFile) { + if (this.psiFile instanceof YAMLFile) { radioButtonOutYaml.setSelected(true); - } else if(this.psiFile instanceof XmlFile) { + } else if (this.psiFile instanceof XmlFile) { radioButtonOutXml.setSelected(true); } // lets use yaml as default - if(!radioButtonOutYaml.isSelected() && !radioButtonOutXml.isSelected()) { + if (!radioButtonOutYaml.isSelected() && !radioButtonOutXml.isSelected()) { radioButtonOutYaml.setSelected(true); } @@ -169,12 +175,12 @@ public void init() { }); this.buttonCopy.addActionListener(e -> { - if(StringUtils.isBlank(textAreaOutput.getText())) { + if (StringUtils.isBlank(textAreaOutput.getText())) { return; } StringSelection stringSelection = new StringSelection(textAreaOutput.getText()); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard (); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); }); @@ -207,7 +213,7 @@ public void changedUpdate(DocumentEvent e) { this.getRootPane().registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); // insert - if(this.psiFile instanceof XmlFile || this.psiFile instanceof YAMLFile) { + if (this.psiFile instanceof XmlFile || this.psiFile instanceof YAMLFile) { this.buttonInsert.setEnabled(true); this.buttonInsert.setVisible(true); @@ -215,9 +221,9 @@ public void changedUpdate(DocumentEvent e) { this.getRootPane().setDefaultButton(buttonInsert); this.buttonInsert.addActionListener(e -> { - if(psiFile instanceof XmlFile) { + if (psiFile instanceof XmlFile) { insertXmlServiceTag(); - } else if(psiFile instanceof YAMLFile) { + } else if (psiFile instanceof YAMLFile) { insertYamlServiceTag(); } }); @@ -230,14 +236,14 @@ public void changedUpdate(DocumentEvent e) { } private void initClassName() { - if(this.classInit != null) { + if (this.classInit != null) { classCompletionPanelWrapper.setClassName(StringUtils.stripStart(this.classInit, "\\")); return; } try { String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); - if(data != null && data.length() <= 255 && data.matches("[_A-Za-z0-9\\\\]+")) { + if (data != null && data.length() <= 255 && data.matches("[_A-Za-z0-9\\\\]+")) { classCompletionPanelWrapper.setClassName(data); } } catch (UnsupportedFlavorException | IOException ignored) { @@ -245,19 +251,19 @@ private void initClassName() { } private void insertYamlServiceTag() { - if(!(this.psiFile instanceof YAMLFile)) { + if (!(this.psiFile instanceof YAMLFile)) { return; } String text = createServiceAsText(ServiceBuilder.OutputType.Yaml, this.psiFile); YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(project, YAMLKeyValue.class, text); - if(fromText == null) { + if (fromText == null) { return; } PsiElement psiElement = YamlHelper.insertKeyIntoFile((YAMLFile) psiFile, fromText, "services"); - if(psiElement != null) { - navigateToElement(new TextRange[] {psiElement.getTextRange()}); + if (psiElement != null) { + navigateToElement(new TextRange[]{psiElement.getTextRange()}); } dispose(); @@ -266,7 +272,7 @@ private void insertYamlServiceTag() { private void insertXmlServiceTag() { final XmlTag rootTag = ((XmlFile) SymfonyCreateService.this.psiFile).getRootTag(); - if(rootTag == null) { + if (rootTag == null) { return; } @@ -276,7 +282,7 @@ private void insertXmlServiceTag() { XmlTag services = rootTag.findFirstSubTag("services"); XmlElementFactory instance = XmlElementFactory.getInstance(SymfonyCreateService.this.project); - if(services == null) { + if (services == null) { services = rootTag.addSubTag(instance.createTagFromText("", rootTag.getLanguage()), false); } @@ -291,7 +297,7 @@ private void insertXmlServiceTag() { } private void navigateToElement(TextRange[] textRange) { - if(editor != null && textRange[0] != null) { + if (editor != null && textRange[0] != null) { editor.getCaretModel().moveToOffset(textRange[0].getStartOffset() + 1); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } @@ -315,19 +321,19 @@ private String createServiceAsText(@NotNull ServiceBuilder.OutputType outputType private void generateServiceDefinition() { String className = classCompletionPanelWrapper.getClassName(); - if(StringUtils.isBlank(className)) { + if (StringUtils.isBlank(className)) { return; } - className = StringUtils.stripStart(className,"\\"); + className = StringUtils.stripStart(className, "\\"); // after cleanup class is empty - if(StringUtils.isBlank(className)) { + if (StringUtils.isBlank(className)) { return; } ServiceBuilder.OutputType outputType = ServiceBuilder.OutputType.XML; - if(radioButtonOutYaml.isSelected()) { + if (radioButtonOutYaml.isSelected()) { outputType = ServiceBuilder.OutputType.Yaml; } @@ -344,18 +350,18 @@ private void update() { private void updateTask() { String className = classCompletionPanelWrapper.getClassName(); - if(className.startsWith("\\")) { + if (className.startsWith("\\")) { className = className.substring(1); } - if(className.isEmpty()) { + if (className.isEmpty()) { return; } textFieldServiceName.setText(""); PhpClass phpClass = PhpElementsUtil.getClass(project, className); - if(phpClass == null) { + if (phpClass == null) { return; } @@ -363,12 +369,12 @@ private void updateTask() { List modelParameters = new ArrayList<>(); - for(Method method: phpClass.getMethods()) { - if(method.getModifier().isPublic()) { + for (Method method : phpClass.getMethods()) { + if (method.getModifier().isPublic()) { Parameter[] parameters = method.getParameters(); for (int i = 0; i < parameters.length; i++) { Set possibleServices = getPossibleServices(parameters[i]); - if(!possibleServices.isEmpty()) { + if (!possibleServices.isEmpty()) { modelParameters.add(new MethodParameter.MethodModelParameter(method, parameters[i], i, possibleServices, getServiceName(possibleServices))); } else { modelParameters.add(new MethodParameter.MethodModelParameter(method, parameters[i], i, serviceSetComplete)); @@ -386,7 +392,7 @@ private void updateTask() { .thenComparingInt(MethodParameter.MethodModelParameter::getIndex) ); - while(this.modelList.getRowCount() > 0) { + while (this.modelList.getRowCount() > 0) { this.modelList.removeRow(0); } @@ -396,7 +402,7 @@ private void updateTask() { @Nullable private String getServiceName(Set services) { - if(services.isEmpty()) { + if (services.isEmpty()) { return null; } @@ -404,6 +410,127 @@ private String getServiceName(Set services) { return services.iterator().next(); } + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 1, new Insets(5, 5, 5, 5), -1, -1)); + content = new JPanel(); + content.setLayout(new BorderLayout(0, 0)); + panel1.add(content, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(1, 5, new Insets(5, 0, 0, 0), -1, -1)); + content.add(panel2, BorderLayout.SOUTH); + buttonCopy = new JButton(); + buttonCopy.setActionCommand("To Clipboard"); + buttonCopy.setText("To Clipboard"); + panel2.add(buttonCopy, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel2.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + closeButton = new JButton(); + closeButton.setText("Close"); + panel2.add(closeButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonSettings = new JButton(); + buttonSettings.setText("Settings"); + panel2.add(buttonSettings, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonInsert = new JButton(); + buttonInsert.setText("Insert"); + panel2.add(buttonInsert, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1)); + content.add(panel3, BorderLayout.NORTH); + final JLabel label1 = new JLabel(); + label1.setText("Class:"); + panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + generateButton = new JButton(); + generateButton.setText("Generate"); + panel3.add(generateButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panelFoo = new JPanel(); + panelFoo.setLayout(new GridBagLayout()); + panel3.add(panelFoo, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + final JPanel panel4 = new JPanel(); + panel4.setLayout(new BorderLayout(0, 0)); + content.add(panel4, BorderLayout.CENTER); + tableViewPanel = new JPanel(); + tableViewPanel.setLayout(new BorderLayout(0, 0)); + panel4.add(tableViewPanel, BorderLayout.CENTER); + final JPanel panel5 = new JPanel(); + panel5.setLayout(new GridLayoutManager(2, 1, new Insets(5, 0, 0, 0), -1, -1)); + panel4.add(panel5, BorderLayout.SOUTH); + final JPanel panel6 = new JPanel(); + panel6.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel5.add(panel6, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JPanel panel7 = new JPanel(); + panel7.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1)); + panel6.add(panel7, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + radioButtonOutXml = new JRadioButton(); + radioButtonOutXml.setText("XML"); + panel7.add(radioButtonOutXml, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + radioButtonOutYaml = new JRadioButton(); + radioButtonOutYaml.setText("Yaml"); + panel7.add(radioButtonOutYaml, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + textFieldServiceName = new JTextField(); + panel7.add(textFieldServiceName, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + checkBoxSymfonyIdClass = new JCheckBox(); + checkBoxSymfonyIdClass.setText("Class as id (Symfony 3.3)"); + panel6.add(checkBoxSymfonyIdClass, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JScrollPane scrollPane1 = new JScrollPane(); + panel5.add(scrollPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + textAreaOutput = new JTextArea(); + textAreaOutput.setEditable(false); + Font textAreaOutputFont = this.$$$getFont$$$("Courier New", -1, -1, textAreaOutput.getFont()); + if (textAreaOutputFont != null) textAreaOutput.setFont(textAreaOutputFont); + textAreaOutput.setLineWrap(true); + textAreaOutput.setRows(7); + textAreaOutput.setText(""); + scrollPane1.setViewportView(textAreaOutput); + ButtonGroup buttonGroup; + buttonGroup = new ButtonGroup(); + buttonGroup.add(radioButtonOutYaml); + buttonGroup.add(radioButtonOutXml); + } + + /** + * @noinspection ALL + */ + private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) { + if (currentFont == null) return null; + String resultName; + if (fontName == null) { + resultName = currentFont.getName(); + } else { + Font testFont = new Font(fontName, Font.PLAIN, 10); + if (testFont.canDisplay('a') && testFont.canDisplay('1')) { + resultName = fontName; + } else { + resultName = currentFont.getName(); + } + } + Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); + boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); + Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); + return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return panel1; + } + private class IsServiceColumn extends ColumnInfo { public IsServiceColumn() { @@ -416,7 +543,7 @@ public Boolean valueOf(MethodParameter.MethodModelParameter modelParameter) { return modelParameter.isPossibleService(); } - public void setValue(MethodParameter.MethodModelParameter modelParameter, Boolean value){ + public void setValue(MethodParameter.MethodModelParameter modelParameter, Boolean value) { modelParameter.setPossibleService(value); tableView.getListTableModel().fireTableDataChanged(); } @@ -448,7 +575,7 @@ public String valueOf(MethodParameter.MethodModelParameter modelParameter) { return modelParameter.getCurrentService(); } - public void setValue(MethodParameter.MethodModelParameter modelParameter, String value){ + public void setValue(MethodParameter.MethodModelParameter modelParameter, String value) { modelParameter.setCurrentService(value); tableView.getListTableModel().fireTableDataChanged(); } @@ -494,7 +621,7 @@ public Icon valueOf(MethodParameter.MethodModelParameter modelParameter) { return modelParameter.getMethod().getIcon(); } - public java.lang.Class getColumnClass() { + public Class getColumnClass() { return ImageIcon.class; } @@ -521,12 +648,12 @@ public String valueOf(MethodParameter.MethodModelParameter modelParameter) { private Set getPossibleServices(Parameter parameter) { PhpPsiElement phpPsiElement = parameter.getFirstPsiChild(); - if(!(phpPsiElement instanceof ClassReference)) { + if (!(phpPsiElement instanceof ClassReference)) { return Collections.emptySet(); } String type = ((ClassReference) phpPsiElement).getFQN(); - if(type == null) { + if (type == null) { return Collections.emptySet(); } @@ -537,11 +664,11 @@ public static class ContainerServicePriorityNameComparator implements Comparator @Override public int compare(ContainerService o1, ContainerService o2) { - if(ServiceContainerUtil.isLowerPriority(o1.getName()) && ServiceContainerUtil.isLowerPriority(o2.getName())) { + if (ServiceContainerUtil.isLowerPriority(o1.getName()) && ServiceContainerUtil.isLowerPriority(o2.getName())) { return 0; } - if(ServiceContainerUtil.isLowerPriority(o1.getName())) { + if (ServiceContainerUtil.isLowerPriority(o1.getName())) { return 1; } @@ -553,7 +680,7 @@ public static class ContainerServicePriorityWeakComparator implements Comparator @Override public int compare(ContainerService o1, ContainerService o2) { - if(o1.isWeak() == o2.isWeak()) { + if (o1.isWeak() == o2.isWeak()) { return 0; } @@ -569,14 +696,14 @@ private static SymfonyCreateService prepare(@Nullable Component component, @NotN service.setMinimumSize(new Dimension(550, 250)); - if(component != null) { + if (component != null) { service.setLocationRelativeTo(component); } // https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html#read-access // fix: "Thread context was already set: com.intellij.openapi.actionSystem.ex.ActionContextElement" // https://intellij-support.jetbrains.com/hc/en-us/community/posts/14397678486418--Thread-context-was-already-set-CoroutineName-commit-workflow-when-showing-window-during-commit-check?page=1#community_comment_15082225353874 - try (var ignored = com.intellij.concurrency.ThreadContext.resetThreadContext()) { + try (var ignored = ThreadContext.resetThreadContext()) { service.setVisible(true); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyJavascriptServiceNameForm.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyJavascriptServiceNameForm.java index 4aef33a71..923148219 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyJavascriptServiceNameForm.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyJavascriptServiceNameForm.java @@ -1,6 +1,9 @@ package fr.adrienbrault.idea.symfony2plugin.action.ui; import com.intellij.openapi.project.Project; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; import fr.adrienbrault.idea.symfony2plugin.Settings; import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; import fr.adrienbrault.idea.symfony2plugin.action.generator.naming.JavascriptServiceNameStrategy; @@ -9,10 +12,13 @@ import javax.script.ScriptException; import javax.swing.*; +import javax.swing.plaf.FontUIResource; +import javax.swing.text.StyleContext; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.Locale; /** * @author Daniel Espendiller @@ -58,7 +64,7 @@ public void windowClosing(WindowEvent e) { buttonTest.addActionListener(e -> { try { Object eval = JavascriptServiceNameStrategy.run(project, textClass.getText(), textJavascript.getText()); - if(!(eval instanceof String)) { + if (!(eval instanceof String)) { textResult.setText("Error: invalid string response"); return; } @@ -83,7 +89,7 @@ public void windowClosing(WindowEvent e) { "return className.replace(/\\\\/g, '.').toLowerCase();")); String jsText = Settings.getInstance(project).serviceJsNameStrategy; - if(StringUtils.isNotBlank(jsText)) { + if (StringUtils.isNotBlank(jsText)) { textJavascript.setText(jsText); } @@ -92,7 +98,7 @@ public void windowClosing(WindowEvent e) { private void onSave() { String text = textJavascript.getText(); - if(StringUtils.isBlank(text)) { + if (StringUtils.isBlank(text)) { text = null; } @@ -115,4 +121,101 @@ public static void create(@NotNull Component c, @NotNull Project project, @NotNu dialog.setVisible(true); } + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(3, 1, new Insets(10, 10, 10, 10), -1, -1)); + contentPane.setMinimumSize(new Dimension(500, 500)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 4, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); + panel1.add(panel2, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + buttonOK = new JButton(); + buttonOK.setText("Save"); + panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonCancel = new JButton(); + buttonCancel.setText("Cancel"); + panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonTest = new JButton(); + buttonTest.setText("Test"); + panel1.add(buttonTest, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonExample = new JButton(); + buttonExample.setText("Example"); + panel1.add(buttonExample, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + textClass = new JTextField(); + panel3.add(textClass, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("PhpClass Name:"); + panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("Javascript:"); + panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + textResult = new JTextField(); + textResult.setEditable(false); + textResult.setEnabled(false); + panel3.add(textResult, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JScrollPane scrollPane1 = new JScrollPane(); + panel3.add(scrollPane1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + textJavascript = new JTextArea(); + textJavascript.setFocusable(true); + Font textJavascriptFont = this.$$$getFont$$$("Courier New", -1, -1, textJavascript.getFont()); + if (textJavascriptFont != null) textJavascript.setFont(textJavascriptFont); + textJavascript.putClientProperty("html.disable", Boolean.TRUE); + scrollPane1.setViewportView(textJavascript); + final JLabel label3 = new JLabel(); + Font label3Font = this.$$$getFont$$$(null, Font.ITALIC, -1, label3.getFont()); + if (label3Font != null) label3.setFont(label3Font); + label3.setText("Provide value by 'return'; empty textfield will clear name strategy to project default"); + contentPane.add(label3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + } + + /** + * @noinspection ALL + */ + private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) { + if (currentFont == null) return null; + String resultName; + if (fontName == null) { + resultName = currentFont.getName(); + } else { + Font testFont = new Font(fontName, Font.PLAIN, 10); + if (testFont.canDisplay('a') && testFont.canDisplay('1')) { + resultName = fontName; + } else { + resultName = currentFont.getName(); + } + } + Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); + boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); + Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); + return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } + }