Last active
December 11, 2015 00:48
-
-
Save olivier-schmitt/4518589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mynewspaper.netbeans.completion.lang; | |
import java.io.BufferedReader; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.URI; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import org.netbeans.spi.editor.completion.xhtml.api.CompletionItemData; | |
import org.netbeans.spi.editor.completion.xhtml.api.CompletionItemService; | |
/** | |
* | |
* @author oschmitt | |
*/ | |
public class LangCompletionItemService implements CompletionItemService { | |
private Map<String, String> labelAndValues = new HashMap<String, String>(); | |
@Override | |
public List<CompletionItemData> getDatas(String query) { | |
List<CompletionItemData> result = new ArrayList<CompletionItemData>(); | |
for (String value : this.labelAndValues.keySet()) { | |
if (value.startsWith(query)) { | |
String label = this.labelAndValues.get(value); | |
CompletionItemData completionItemData = new CompletionItemData(value, | |
label, | |
String.format("Language code for %s is %s", | |
label, | |
value)); | |
result.add(completionItemData); | |
} | |
} | |
return result; | |
} | |
@Override | |
public boolean accept(String scheme) { | |
return ("lang").equals(scheme); | |
} | |
@Override | |
public void configure(URI uri) throws CompletionConfigurationException { | |
try { | |
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
InputStream inputStream = classLoader.getResourceAsStream("mynewspaper/netbeans/completion/lang/lang.csv"); | |
if (inputStream != null) { | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | |
String line = null; | |
while ((line = bufferedReader.readLine()) != null) { | |
if (line.contains(";")) { | |
String[] valueAndLabel = line.split(";"); | |
String value = valueAndLabel[0]; | |
String label = valueAndLabel[1]; | |
labelAndValues.put(value, label); | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new CompletionConfigurationException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment