org.netbeans.modeler.search.SearchDialog Maven / Gradle / Ivy
Go to download
Jeddict is an open source Jakarta EE application development platform that accelerates developers productivity and simplifies development tasks of creating complex entity relationship models.
/**
* Copyright [2017] Gaurav Gupta
*
* Licensed 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.modeler.search;
import java.util.List;
import java.util.function.Consumer;
import static java.util.stream.Collectors.toList;
import org.netbeans.modeler.properties.spec.ComboBoxValue;
import org.netbeans.modeler.properties.window.GenericDialog;
import org.netbeans.modeler.resource.toolbar.ImageUtil;
import org.netbeans.modeler.specification.model.document.IModelerScene;
import org.netbeans.modeler.specification.model.document.IRootElement;
import org.netbeans.modeler.widget.node.INodeWidget;
/**
*
* @author jGauravGupta
*/
public class SearchDialog extends GenericDialog {
private final IModelerScene extends IRootElement> scene;
private INodeWidget value;
private AutocompleteJComboBox searchBox;
public SearchDialog(IModelerScene extends IRootElement> scene) {
this.scene=scene;
initComponents();
}
public INodeWidget getValue(){
if(value == null){
value = searchBox.getValue();
}
return value;
}
List> getTerms(){
return scene.getBaseElements()
.stream()
.filter(e -> e instanceof INodeWidget)
.map(e -> (INodeWidget)e)
.map(jcw -> new ComboBoxValue<>(jcw, jcw.getLabel()))
.collect(toList());
}
private Consumer onSelection(){
return jcw -> {
value = jcw;
saveActionPerformed(null);
};
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
searchBox= new AutocompleteJComboBox(getTerms(),onSelection());
javax.swing.JComboBox jComboBox1 = searchBox;
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(org.openide.util.NbBundle.getMessage(SearchDialog.class, "SearchDialog.title.text")); // NOI18N
setIconImage(ImageUtil.getInstance().getImage("search.png"));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, 0, 379, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
);
pack();
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}