Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #279 #280

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void handleSaveAs() throws Exception {
private boolean handleSaveAs(OWLOntology ont) throws Exception {
OWLOntologyManager man = getModelManager().getOWLOntologyManager();
OWLOntologyFormat oldFormat = man.getOntologyFormat(ont);
OWLOntologyFormat format = OntologyFormatPanel.showDialog(this, oldFormat, "Choose a format to use when saving the " + getModelManager().getRendering(ont) + " ontology");
OWLOntologyFormat format = OntologyFormatPanel.showDialog(this, oldFormat, "<html>Choose a format to use when saving the <i>" + getModelManager().getRendering(ont) + "</i> ontology</html>");
if (format == null) {
logger.warn("Please select a valid format");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Author: Matthew Horridge<br>
Expand All @@ -25,34 +28,35 @@
* Date: 20/09/2012
*/
public class SearchPanel extends JPanel {

private SearchOptionsPanel searchOptionsPanel;

private SearchResultsPanel searchResultsPanel;

private String searchString;



private Logger log = LoggerFactory.getLogger(SearchPanel.class);

private OWLEditorKit editorKit;

public SearchPanel(OWLEditorKit editorKit) {
this.editorKit = editorKit;
setLayout(new BorderLayout(4, 4));
searchOptionsPanel = new SearchOptionsPanel(editorKit);
add(searchOptionsPanel, BorderLayout.NORTH);
searchResultsPanel = new SearchResultsPanel(editorKit);
add(searchResultsPanel);

searchOptionsPanel.addListener(new SearchOptionsChangedListener() {
public void searchRequestOptionChanged() {
doSearch();
}

public void searchResultsPresentationOptionChanged() {
updateSearchResultsPresentation();
}
});

JPanel searchActionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
searchActionsPanel.add(new JButton(new AbstractAction("Copy selected entities") {
public void actionPerformed(ActionEvent e) {
Expand All @@ -61,32 +65,32 @@ public void actionPerformed(ActionEvent e) {
}));
add(searchActionsPanel, BorderLayout.SOUTH);
}

public void setSearchResultClickedListener(SearchResultClickedListener searchResultClickedListener) {
searchResultsPanel.setSearchResultClickedListener(searchResultClickedListener);
}

public void setSearchString(String searchString) {
log.debug("search String: {}", searchString);
this.searchString = searchString;
searchOptionsPanel.refresh();
doSearch();
}

private SearchRequest createSearchRequest() {
private SearchRequest createSearchRequest() throws PatternSyntaxException {
OWLEntityFinderPreferences prefs = OWLEntityFinderPreferences.getInstance();
int flags = Pattern.DOTALL | (prefs.isCaseSensitive() ? 0 : Pattern.CASE_INSENSITIVE);

ImmutableList.Builder<Pattern> builder = ImmutableList.builder();

String preparedSearchString;
for (String splitSearchString : searchString.split("\\s+")) {
if (prefs.isUseRegularExpressions()) {
preparedSearchString = splitSearchString;
if (prefs.isIgnoreWhiteSpace()) {
preparedSearchString = preparedSearchString.replace(" ", "\\s+");
}
}
else {
} else {
if (prefs.isIgnoreWhiteSpace()) {
StringBuilder sb = new StringBuilder();
String[] split = splitSearchString.split("\\s+");
Expand All @@ -98,8 +102,7 @@ private SearchRequest createSearchRequest() {
}
}
preparedSearchString = sb.toString();
}
else {
} else {
preparedSearchString = Pattern.quote(splitSearchString);
}
}
Expand All @@ -111,54 +114,58 @@ private SearchRequest createSearchRequest() {
// Pattern searchPattern = Pattern.compile(preparedSearchString, flags);
return new SearchRequest(builder.build());
}

private void doSearch() {
if (searchString.trim().isEmpty()) {
searchResultsPanel.clearSearchResults();
return;
}
SearchManager searchManager = editorKit.getSearchManager();
SearchRequest searchRequest = createSearchRequest();
SearchRequest searchRequest;
try {
searchRequest = createSearchRequest();
} catch (PatternSyntaxException ex) {
log.debug("entered pattern: '{}'", ex.getPattern());
return;
}
searchManager.performSearch(searchRequest, new SearchResultHandler() {
public void searchFinished(List<SearchResult> searchResults) {
int categorySizeLimit = getCategoryLimit();
searchResultsPanel.setSearchResults(new SearchResultSet(searchResults), categorySizeLimit);

}
});
}

private int getCategoryLimit() {
int categorySizeLimit = 10;
if (searchOptionsPanel.isShowAllResults()) {
categorySizeLimit = Integer.MAX_VALUE;
}
return categorySizeLimit;
}



private void updateSearchResultsPresentation() {
int categorySizeLimit = getCategoryLimit();
searchResultsPanel.setCategorySizeLimit(categorySizeLimit);
}



public void moveSelectionDown() {
searchResultsPanel.moveSelectionDown();
}

public void moveSelectionUp() {
searchResultsPanel.moveSelectionUp();
}

private void copySelectedEntities() {
Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
List<OWLEntity> objects = new ArrayList<OWLEntity>();
objects.addAll(searchResultsPanel.getSelectedEntities());
ViewClipboard clipboard = ViewClipboard.getInstance();
TransferableOWLObject contents = new TransferableOWLObject(editorKit.getOWLModelManager(), objects);
clipboard.getClipboard().setContents(contents, null);

StringBuilder buffer = new StringBuilder();
for (OWLEntity owlObject : objects) {
buffer.append(editorKit.getOWLModelManager().getRendering(owlObject));
Expand All @@ -169,7 +176,7 @@ private void copySelectedEntities() {
StringSelection stringSelection = new StringSelection(buffer.toString().trim());
systemClipboard.setContents(stringSelection, null);
}

public Optional<OWLEntity> getSelectedEntity() {
return searchResultsPanel.getSelectedEntity();
}
Expand Down