}
});
// initialize search text field
_searchDatastoreTextField = WidgetFactory.createTextField("Search/filter datastores");
_searchDatastoreTextField.setBorder(new CompoundBorder(new EmptyBorder(4, 0, 0, 0), WidgetUtils.BORDER_THIN));
_searchDatastoreTextField.setOpaque(false);
_searchDatastoreTextField.getDocument().addDocumentListener(new DCDocumentListener() {
@Override
protected void onChange(DocumentEvent event) {
String text = _searchDatastoreTextField.getText();
if (StringUtils.isNullOrEmpty(text)) {
// when there is no search query, set all datastores visible
for (DatastorePanel datastorePanel : _datastorePanels) {
datastorePanel.setVisible(true);
}
} else {
// do a case insensitive search
text = text.trim().toLowerCase();
for (DatastorePanel datastorePanel : _datastorePanels) {
String name = datastorePanel.getDatastore().getName().toLowerCase();
datastorePanel.setVisible(name.indexOf(text) != -1);
}
selectFirstVisibleDatastore();
}
}
});
_searchDatastoreTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
clickAnalyzeButton();
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
selectNextVisibleDatastore();
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
selectPreviousVisibleDatastore();
}
}
});
setLayout(new VerticalLayout(4));
final DCLabel headerLabel = DCLabel.dark("Select datastore for analysis");
headerLabel.setFont(WidgetUtils.FONT_HEADER1);
add(headerLabel);
final DCLabel createNewDatastoreLabel = DCLabel.dark("Create a new datastore:");
createNewDatastoreLabel.setFont(WidgetUtils.FONT_HEADER1);
final DCPanel newDatastorePanel = new DCPanel();
newDatastorePanel.setLayout(new VerticalLayout(4));
newDatastorePanel.setBorder(new EmptyBorder(10, 10, 10, 0));
newDatastorePanel.add(createNewDatastoreLabel);
newDatastorePanel.add(createNewDatastorePanel());
add(newDatastorePanel);
_listPanel = new DCPanel();
_listPanel.setLayout(new VerticalLayout(4));
_listPanel.setBorder(new EmptyBorder(10, 10, 10, 0));
add(_listPanel);
updateDatastores();
final DCPanel buttonPanel = new DCPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
buttonPanel.setBorder(new EmptyBorder(0, 10, 0, 0));
buttonPanel.add(_analyzeButton);
add(buttonPanel);
}