Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:zanata/zanata into integration/ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
seanf committed Apr 30, 2012
2 parents 770e3c2 + 4e128b6 commit 232714d
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 75 deletions.
Expand Up @@ -65,7 +65,7 @@
"and contents[0] = ? and contents[1] = ? and contents[2] = ? and contents[3] = ? and contents[4] = ?"),
@NamedQuery(name = "HTextFlowTargetHistory.findContentInHistory[6]",
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = ? and size(t.contents) = ? " +
"and contents[0] = ? and contents[1] = ? and contents[2] = ? and contents[3] = ? and contents[4] = ? and contents[5] = ?"),
"and contents[0] = ? and contents[1] = ? and contents[2] = ? and contents[3] = ? and contents[4] = ? and contents[5] = ?")
})
public class HTextFlowTargetHistory extends HTextContainer implements Serializable, ITextFlowTargetHistory
{
Expand Down
Expand Up @@ -20,6 +20,7 @@
*/
package org.zanata.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.analysis.Analyzer;
Expand Down Expand Up @@ -105,7 +106,12 @@ public List<HTextFlowTarget> findTextFlowTargets(WorkspaceId workspace, FilterCo
}

String searchFieldPrefix = (constraints.isCaseSensitive() ? IndexFieldLabels.CONTENT_CASE_PRESERVED : IndexFieldLabels.CONTENT_CASE_FOLDED);
int searchLength = Math.min(3, constraints.getSearchString().length());
// FIXME remove .trim() and zero-length check when ngram analyzer is updated to respect leading and trailing whitespace
int searchLength = Math.min(3, constraints.getSearchString().trim().length());
if (searchLength == 0)
{
return new ArrayList<HTextFlowTarget>();
}
Analyzer ngramAnalyzer = new ConfigurableNgramAnalyzer(searchLength, !constraints.isCaseSensitive());

String[] searchFields = new String[6];
Expand Down
Expand Up @@ -26,6 +26,8 @@
import java.util.List;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetDisplay;
Expand Down Expand Up @@ -83,8 +85,6 @@
import org.zanata.webtrans.shared.rpc.UpdateTransUnitResult;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
Expand Down Expand Up @@ -316,16 +316,16 @@ protected void onBind()
@Override
public void onClick(ClickEvent event)
{
Log.info("Save changes and filter");
filterViewConfirmationPanel.updateFilter(filterTranslated, filterNeedReview, filterUntranslated);
filterViewConfirmationPanel.hide();
saveChangesAndFilter();
}
}));

display.getTargetCellEditor().savePendingChange(true);
if (selectedTransUnit != null)
{
targetTransUnitId = selectedTransUnit.getId();
}
initialiseTransUnitList();
registerHandler(filterViewConfirmationPanel.getSaveFuzzyAndFilterButton().addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
{
saveFuzzyAndFilter();
}
}));

Expand All @@ -334,16 +334,7 @@ public void onClick(ClickEvent event)
@Override
public void onClick(ClickEvent event)
{
Log.info("Discard changes and filter");
filterViewConfirmationPanel.updateFilter(filterTranslated, filterNeedReview, filterUntranslated);
filterViewConfirmationPanel.hide();

display.getTargetCellEditor().cancelEdit();
if (selectedTransUnit != null)
{
targetTransUnitId = selectedTransUnit.getId();
}
initialiseTransUnitList();
discardChangesAndFilter();
}
}));

Expand All @@ -352,9 +343,7 @@ public void onClick(ClickEvent event)
@Override
public void onClick(ClickEvent event)
{
Log.info("Cancel filter");
eventBus.fireEvent(new FilterViewEvent(filterViewConfirmationPanel.isFilterTranslated(), filterViewConfirmationPanel.isFilterNeedReview(), filterViewConfirmationPanel.isFilterUntranslated(), true));
filterViewConfirmationPanel.hide();
cancelFilter();
}
}));

Expand Down Expand Up @@ -590,6 +579,46 @@ public void onWorkspaceContextUpdated(WorkspaceContextUpdateEvent event)
History.fireCurrentHistoryState();
}

private void saveChangesAndFilter()
{
Log.info("Save changes and filter");
display.getTargetCellEditor().savePendingChange(true);
hideConfirmationPanelAndDoFiltering();
}

private void saveFuzzyAndFilter()
{
Log.info("Save changes as fuzzy and filter");
display.getTargetCellEditor().acceptFuzzyEdit();
hideConfirmationPanelAndDoFiltering();
}

private void discardChangesAndFilter()
{
Log.info("Discard changes and filter");
display.getTargetCellEditor().cancelEdit();
hideConfirmationPanelAndDoFiltering();
}

private void hideConfirmationPanelAndDoFiltering()
{
filterViewConfirmationPanel.updateFilter(filterTranslated, filterNeedReview, filterUntranslated);
filterViewConfirmationPanel.hide();

if (selectedTransUnit != null)
{
targetTransUnitId = selectedTransUnit.getId();
}
initialiseTransUnitList();
}

private void cancelFilter()
{
Log.info("Cancel filter");
eventBus.fireEvent(new FilterViewEvent(filterViewConfirmationPanel.isFilterTranslated(), filterViewConfirmationPanel.isFilterNeedReview(), filterViewConfirmationPanel.isFilterUntranslated(), true));
filterViewConfirmationPanel.hide();
}

public boolean isFiltering()
{
return (findMessage != null && !findMessage.isEmpty()) || (filterViewConfirmationPanel.isFilterTranslated() || filterViewConfirmationPanel.isFilterNeedReview() || filterViewConfirmationPanel.isFilterUntranslated());
Expand Down
Expand Up @@ -68,7 +68,8 @@ public HistoryToken()
/**
* Generate a history token from the given token string
*
* @param token A GWT history token in the form key1:value1,key2:value2,...
* @param token A GWT history token in the form key1:value1;key2:value2;...
* @see #toTokenString()
*/
public static HistoryToken fromTokenString(String token)
{
Expand All @@ -80,8 +81,7 @@ public static HistoryToken fromTokenString(String token)
}

// decode characters that may still be url-encoded
//TODO need to encode/decode separators in filter and search strings in to/fromTokenString
token = token.replaceAll("%3A", ":").replaceAll("%3B", ";").replaceAll("%2F", "/");
token = token.replace("%3A", ":").replace("%3B", ";").replace("%2F", "/");

for (String pairString : token.split(PAIR_SEPARATOR))
{
Expand All @@ -97,6 +97,7 @@ public static HistoryToken fromTokenString(String token)
{
continue;
}
value = decode(value);

if (key.equals(HistoryToken.KEY_DOCUMENT))
{
Expand Down Expand Up @@ -263,95 +264,144 @@ public void setDocFilterText(String value)
/**
* @return a token string for use with
* {@link com.google.gwt.user.client.History}
* @see HistoryToken#fromTokenString(String)
*/
public String toTokenString()
{
String token = "";
boolean first = true;

if (view != DEFAULT_VIEW)
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_VIEW + DELIMITER_K_V;
if (view == MainView.Search)
{
token += VALUE_SEARCH_RESULTS_VIEW;
token = addTokenToTokenString(token, KEY_VIEW, VALUE_SEARCH_RESULTS_VIEW);
}
else
{
// must be editor
token += VALUE_EDITOR_VIEW;
token = addTokenToTokenString(token, KEY_VIEW, VALUE_EDITOR_VIEW);
}
}

if (!fullDocPath.equals(DEFAULT_DOCUMENT_PATH))
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_DOCUMENT + DELIMITER_K_V + fullDocPath;
token = addTokenToTokenString(token, KEY_DOCUMENT, fullDocPath);
}

if (docFilterExact != DEFAULT_DOC_FILTER_EXACT)
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
// exact is the only non-default filter value
token += KEY_DOC_FILTER_OPTION + DELIMITER_K_V + VALUE_DOC_FILTER_EXACT;
token = addTokenToTokenString(token, KEY_DOC_FILTER_OPTION, VALUE_DOC_FILTER_EXACT);
}

if (!docFilterText.equals(DEFAULT_DOC_FILTER_TEXT))
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_DOC_FILTER_TEXT + DELIMITER_K_V + docFilterText;
token = addTokenToTokenString(token, KEY_DOC_FILTER_TEXT, docFilterText);
}

if (!projectSearchText.equals(DEFAULT_PROJECT_SEARCH_TEXT))
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_SEARCH_PROJECT_TEXT + DELIMITER_K_V + projectSearchText;
token = addTokenToTokenString(token, KEY_SEARCH_PROJECT_TEXT, projectSearchText);
}

if(!projectSearchReplace.equals(DEFAULT_PROJECT_SEARCH_REPLACE))
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_SEARCH_PROJECT_REPLACEMENT + DELIMITER_K_V + projectSearchReplace;
token = addTokenToTokenString(token, KEY_SEARCH_PROJECT_REPLACEMENT, projectSearchReplace);
}

if (projectSearchCaseSensitive != DEFAULT_PROJECT_SEARCH_CASE_SENSITIVE)
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
// sensitive is the only non-default filter value
token += KEY_SEARCH_PROJECT_CASE + DELIMITER_K_V + VALUE_SEARCH_PROJECT_CASE_SENSITIVE;
token = addTokenToTokenString(token, KEY_SEARCH_PROJECT_CASE, VALUE_SEARCH_PROJECT_CASE_SENSITIVE);
}

if (!searchText.equals(DEFAULT_SEARCH_TEXT))
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_SEARCH_DOC_TEXT + DELIMITER_K_V + searchText;
token = addTokenToTokenString(token, KEY_SEARCH_DOC_TEXT, searchText);
}

return token;
}

private static String addTokenToTokenString(String tokenString, String key, String value)
{
String separator = (tokenString.isEmpty() ? "" : PAIR_SEPARATOR);
return tokenString + separator + key + DELIMITER_K_V + encode(value);
}

/**
*
* @see #decode(String)
* @param toEncode
* @return the given string with all token delimiters encoded
*/
private static String encode(String toEncode)
{
StringBuilder sb = new StringBuilder();
for (int i=0; i< toEncode.length(); i++)
{
char nextChar = toEncode.charAt(i);
switch (nextChar)
{
case ':':
sb.append("!c");
break;
case ';':
sb.append("!s");
break;
case '!':
sb.append('!');
default:
sb.append(nextChar);
}
}
Log.info("Encoded: \"" + toEncode + "\" to \"" + sb + "\"");
return sb.toString();
}

/**
* @see #encode(String)
* @param toDecode
* @return the given string with any encoded token delimiters decoded
*/
private static String decode(String toDecode)
{
StringBuilder sb = new StringBuilder();
boolean escaped = false;
for (int i=0; i< toDecode.length(); i++)
{
char nextChar = toDecode.charAt(i);
if (escaped)
{
escaped = false;
switch (nextChar)
{
case '!':
sb.append('!');
break;
case 'c':
sb.append(':');
break;
case 's':
sb.append(';');
break;
default:
Log.warn("Unrecognised escaped character, appending: " + nextChar);
sb.append(nextChar);
}
}
else if (nextChar == '!')
{
escaped = true;
continue;
}
else
{
sb.append(nextChar);
}
}
Log.info("Decoded: \"" + toDecode + "\" to \"" + sb + "\"");
return sb.toString();
}

}

0 comments on commit 232714d

Please sign in to comment.