diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/AnalysisPanelProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/AnalysisPanelProvider.java index b21e9c5626a..97abc968b31 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/AnalysisPanelProvider.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/AnalysisPanelProvider.java @@ -27,15 +27,11 @@ import java.awt.event.MouseEvent; import java.io.IOException; import java.util.Objects; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTextArea; @@ -48,8 +44,6 @@ import org.apache.lucene.luke.app.desktop.components.dialog.documents.AddDocumentDialogOperator; import org.apache.lucene.luke.app.desktop.components.fragments.analysis.CustomAnalyzerPanelOperator; import org.apache.lucene.luke.app.desktop.components.fragments.analysis.CustomAnalyzerPanelProvider; -import org.apache.lucene.luke.app.desktop.components.fragments.analysis.PresetAnalyzerPanelOperator; -import org.apache.lucene.luke.app.desktop.components.fragments.analysis.PresetAnalyzerPanelProvider; import org.apache.lucene.luke.app.desktop.components.fragments.analysis.SimpleAnalyzeResultPanelOperator; import org.apache.lucene.luke.app.desktop.components.fragments.analysis.SimpleAnalyzeResultPanelProvider; import org.apache.lucene.luke.app.desktop.components.fragments.analysis.StepByStepAnalyzeResultPanelOperator; @@ -63,15 +57,10 @@ import org.apache.lucene.luke.models.analysis.Analysis; import org.apache.lucene.luke.models.analysis.AnalysisFactory; import org.apache.lucene.luke.models.analysis.CustomAnalyzerConfig; -import org.apache.lucene.util.NamedThreadFactory; /** Provider of the Analysis panel */ public final class AnalysisPanelProvider implements AnalysisTabOperator { - private static final String TYPE_PRESET = "preset"; - - private static final String TYPE_CUSTOM = "custom"; - private final ComponentOperatorRegistry operatorRegistry; private final AnalysisChainDialogFactory analysisChainDialogFactory; @@ -82,14 +71,8 @@ public final class AnalysisPanelProvider implements AnalysisTabOperator { private final JPanel mainPanel = new JPanel(); - private final JPanel preset; - private final JPanel custom; - private final JRadioButton presetRB = new JRadioButton(); - - private final JRadioButton customRB = new JRadioButton(); - private final JLabel analyzerNameLbl = new JLabel(); private final JLabel showChainLbl = new JLabel(); @@ -109,7 +92,6 @@ public final class AnalysisPanelProvider implements AnalysisTabOperator { private Analysis analysisModel; public AnalysisPanelProvider() throws IOException { - this.preset = new PresetAnalyzerPanelProvider().get(); this.custom = new CustomAnalyzerPanelProvider().get(); this.operatorRegistry = ComponentOperatorRegistry.getInstance(); @@ -126,20 +108,13 @@ public AnalysisPanelProvider() throws IOException { operatorRegistry.register(AnalysisTabOperator.class, this); operatorRegistry - .get(PresetAnalyzerPanelOperator.class) + .get(CustomAnalyzerPanelOperator.class) .ifPresent( operator -> { - // Scanning all Analyzer types will take time... - ExecutorService executorService = - Executors.newFixedThreadPool( - 1, new NamedThreadFactory("load-preset-analyzer-types")); - executorService.execute( - () -> { - operator.setPresetAnalyzers(analysisModel.getPresetAnalyzerTypes()); - operator.setSelectedAnalyzer(analysisModel.currentAnalyzer().getClass()); - }); - executorService.shutdown(); + operator.setAnalysisModel(analysisModel); + operator.resetAnalysisComponents(); }); + stepByStepCB.setVisible(true); } public JPanel get() { @@ -161,38 +136,11 @@ private JPanel initUpperPanel() { mainPanel.setLayout(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - mainPanel.add(initSwitcherPanel(), BorderLayout.PAGE_START); - mainPanel.add(preset, BorderLayout.CENTER); + mainPanel.add(custom, BorderLayout.CENTER); return mainPanel; } - private JPanel initSwitcherPanel() { - JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEADING)); - panel.setOpaque(false); - - presetRB.setText(MessageUtils.getLocalizedMessage("analysis.radio.preset")); - presetRB.setActionCommand(TYPE_PRESET); - presetRB.addActionListener(listeners::toggleMainPanel); - presetRB.setOpaque(false); - presetRB.setSelected(true); - - customRB.setText(MessageUtils.getLocalizedMessage("analysis.radio.custom")); - customRB.setActionCommand(TYPE_CUSTOM); - customRB.addActionListener(listeners::toggleMainPanel); - customRB.setOpaque(false); - customRB.setSelected(false); - - ButtonGroup group = new ButtonGroup(); - group.add(presetRB); - group.add(customRB); - - panel.add(presetRB); - panel.add(customRB); - - return panel; - } - private JPanel initLowerPanel() { JPanel inner1 = new JPanel(new BorderLayout()); inner1.setOpaque(false); @@ -236,7 +184,7 @@ public void mouseClicked(MouseEvent e) { stepByStepCB.setText(MessageUtils.getLocalizedMessage("analysis.checkbox.step_by_step")); stepByStepCB.setSelected(false); stepByStepCB.setOpaque(false); - stepByStepCB.setVisible(false); + stepByStepCB.setVisible(true); input.add(stepByStepCB); JButton clearBtn = new JButton(MessageUtils.getLocalizedMessage("button.clear")); @@ -265,38 +213,6 @@ public void mouseClicked(MouseEvent e) { } // control methods - - void toggleMainPanel(String command) { - if (command.equalsIgnoreCase(TYPE_PRESET)) { - mainPanel.remove(custom); - mainPanel.add(preset, BorderLayout.CENTER); - - operatorRegistry - .get(PresetAnalyzerPanelOperator.class) - .ifPresent( - operator -> { - operator.setPresetAnalyzers(analysisModel.getPresetAnalyzerTypes()); - operator.setSelectedAnalyzer(analysisModel.currentAnalyzer().getClass()); - }); - stepByStepCB.setSelected(false); - stepByStepCB.setVisible(false); - } else if (command.equalsIgnoreCase(TYPE_CUSTOM)) { - mainPanel.remove(preset); - mainPanel.add(custom, BorderLayout.CENTER); - - operatorRegistry - .get(CustomAnalyzerPanelOperator.class) - .ifPresent( - operator -> { - operator.setAnalysisModel(analysisModel); - operator.resetAnalysisComponents(); - }); - stepByStepCB.setVisible(true); - } - mainPanel.setVisible(false); - mainPanel.setVisible(true); - } - void executeAnalysis() { String text = inputArea.getText(); if (Objects.isNull(text) || text.isEmpty()) { @@ -392,10 +308,6 @@ public Analyzer getCurrentAnalyzer() { private class ListenerFunctions { - void toggleMainPanel(ActionEvent e) { - AnalysisPanelProvider.this.toggleMainPanel(e.getActionCommand()); - } - void showAnalysisChain(MouseEvent e) { AnalysisPanelProvider.this.showAnalysisChainDialog(); } diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelOperator.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelOperator.java deleted file mode 100644 index 3e42a94a44e..00000000000 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelOperator.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.apache.lucene.luke.app.desktop.components.fragments.analysis; - -import java.util.Collection; -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; - -/** Operator of the preset analyzer panel */ -public interface PresetAnalyzerPanelOperator extends ComponentOperatorRegistry.ComponentOperator { - void setPresetAnalyzers(Collection> presetAnalyzers); - - void setSelectedAnalyzer(Class analyzer); -} diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelProvider.java deleted file mode 100644 index 95824e4cdca..00000000000 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelProvider.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.apache.lucene.luke.app.desktop.components.fragments.analysis; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.util.Collection; -import javax.swing.BorderFactory; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.luke.app.desktop.components.AnalysisTabOperator; -import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; -import org.apache.lucene.luke.app.desktop.util.MessageUtils; - -/** Provider of the preset analyzer panel */ -public final class PresetAnalyzerPanelProvider implements PresetAnalyzerPanelOperator { - - private final ComponentOperatorRegistry operatorRegistry; - - private final JComboBox analyzersCB = new JComboBox<>(); - - private final ListenerFunctions listeners = new ListenerFunctions(); - - public PresetAnalyzerPanelProvider() { - this.operatorRegistry = ComponentOperatorRegistry.getInstance(); - operatorRegistry.register(PresetAnalyzerPanelOperator.class, this); - } - - public JPanel get() { - JPanel panel = new JPanel(new BorderLayout()); - panel.setOpaque(false); - panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - - JLabel header = new JLabel(MessageUtils.getLocalizedMessage("analysis_preset.label.preset")); - panel.add(header, BorderLayout.PAGE_START); - - JPanel center = new JPanel(new FlowLayout(FlowLayout.LEADING)); - center.setOpaque(false); - center.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - center.setPreferredSize(new Dimension(400, 40)); - analyzersCB.addActionListener(listeners::setAnalyzer); - analyzersCB.setEnabled(false); - center.add(analyzersCB); - panel.add(center, BorderLayout.CENTER); - - return panel; - } - - // control methods - - @Override - public void setPresetAnalyzers(Collection> presetAnalyzers) { - String[] analyzerNames = presetAnalyzers.stream().map(Class::getName).toArray(String[]::new); - ComboBoxModel model = new DefaultComboBoxModel<>(analyzerNames); - analyzersCB.setModel(model); - analyzersCB.setEnabled(true); - } - - @Override - public void setSelectedAnalyzer(Class analyzer) { - analyzersCB.setSelectedItem(analyzer.getName()); - } - - private class ListenerFunctions { - - void setAnalyzer(ActionEvent e) { - operatorRegistry - .get(AnalysisTabOperator.class) - .ifPresent( - operator -> operator.setAnalyzerByType((String) analyzersCB.getSelectedItem())); - } - } -} diff --git a/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/Analysis.java b/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/Analysis.java index 676e2178c01..e44222423e2 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/Analysis.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/Analysis.java @@ -133,9 +133,6 @@ public List getNamedTokens() { } } - /** Returns built-in {@link Analyzer}s. */ - Collection> getPresetAnalyzerTypes(); - /** Returns available char filter names. */ Collection getAvailableCharFilters(); diff --git a/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java b/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java index c63cc103998..7c5c0015bcc 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/models/analysis/AnalysisImpl.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; -import java.lang.reflect.Modifier; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.FileSystems; @@ -28,14 +27,12 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.stream.Collectors; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.CharFilterFactory; @@ -46,7 +43,6 @@ import org.apache.lucene.analysis.custom.CustomAnalyzer; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.luke.models.LukeException; -import org.apache.lucene.luke.util.reflection.ClassScanner; import org.apache.lucene.util.AttributeImpl; import org.apache.lucene.util.AttributeSource; import org.apache.lucene.util.IOUtils; @@ -54,8 +50,6 @@ /** Default implementation of {@link AnalysisImpl} */ public final class AnalysisImpl implements Analysis { - private List> presetAnalyzerTypes; - private Analyzer analyzer; @Override @@ -84,25 +78,6 @@ public void addExternalJars(List jarFiles) { TokenFilterFactory.reloadTokenFilters(classLoader); } - @Override - public Collection> getPresetAnalyzerTypes() { - if (Objects.isNull(presetAnalyzerTypes)) { - List> types = new ArrayList<>(); - for (Class clazz : getInstantiableSubTypesBuiltIn(Analyzer.class)) { - try { - // add to presets if no args constructor is available - clazz.getConstructor(); - types.add(clazz); - } catch ( - @SuppressWarnings("unused") - NoSuchMethodException e) { - } - } - presetAnalyzerTypes = List.copyOf(types); - } - return presetAnalyzerTypes; - } - @Override public Collection getAvailableCharFilters() { return CharFilterFactory.availableCharFilters().stream().sorted().collect(Collectors.toList()); @@ -120,17 +95,6 @@ public Collection getAvailableTokenFilters() { .collect(Collectors.toList()); } - private List> getInstantiableSubTypesBuiltIn(Class superType) { - ClassScanner scanner = - new ClassScanner("org.apache.lucene.analysis", getClass().getClassLoader()); - Set> types = scanner.scanSubTypes(superType); - return types.stream() - .filter(type -> !Modifier.isAbstract(type.getModifiers())) - .filter(type -> !type.getSimpleName().startsWith("Mock")) - .sorted(Comparator.comparing(Class::getName)) - .collect(Collectors.toList()); - } - @Override public List analyze(String text) { Objects.requireNonNull(text); diff --git a/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java b/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java index 3ee9d3ad22f..5462148f433 100644 --- a/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java +++ b/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java @@ -34,16 +34,6 @@ public class TestAnalysisImpl extends LuceneTestCase { - @Test - public void testGetPresetAnalyzerTypes() throws Exception { - AnalysisImpl analysis = new AnalysisImpl(); - Collection> analyerTypes = analysis.getPresetAnalyzerTypes(); - assertNotNull(analyerTypes); - for (Class clazz : analyerTypes) { - clazz.getConstructor().newInstance(); - } - } - @Test public void testGetAvailableCharFilters() { AnalysisImpl analysis = new AnalysisImpl();