public InsertEdit insert(String key, String value) { return insert(new KeyValuePair(key, value)); }
private static void addInsertEdits(TextChange textChange, NLSSubstitution[] substitutions, Map newKeyToSubstMap, Map oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { String value= substitution.getValueNonEmpty(); KeyValuePair curr= new KeyValuePair(substitution.getKey(), value); InsertEdit insert= model.insert(curr); String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, curr.getKey()); TextChangeCompatibility.addTextEdit(textChange, message, insert); } } }
private void openEditButton(ISelection selection) { try { IStructuredSelection sel= (IStructuredSelection) fTableViewer.getSelection(); NLSSubstitution substitution= (NLSSubstitution) sel.getFirstElement(); if (substitution == null) { return; } NLSInputDialog dialog= new NLSInputDialog(getShell(), substitution); if (dialog.open() == Window.CANCEL) return; KeyValuePair kvPair= dialog.getResult(); if (substitution.getState() == NLSSubstitution.EXTERNALIZED) { substitution.setKey(kvPair.getKey()); } substitution.setValue(kvPair.getValue()); validateKeys(false); } finally { fTableViewer.refresh(); fTableViewer.getControl().setFocus(); fTableViewer.setSelection(selection); } }
return null; String value= oldPair.getValue(); KeyValuePair newPair= new KeyValuePair(fNewName, value); ReplaceEdit edit= model.replace(oldPair, newPair); if (edit == null)
public ReplaceEdit replace(KeyValuePair toReplace, KeyValuePair replaceWith) { for (Iterator iter = fKeyValuePairs.iterator(); iter.hasNext();) { KeyValuePairModell keyValuePair = (KeyValuePairModell) iter.next(); if (keyValuePair.fKey.equals(toReplace.getKey())) { String newText = new KeyValuePairModell(replaceWith).getEncodedText(fLineDelimiter); KeyValuePairModell next = (KeyValuePairModell) iter.next(); int range = next.fOffset - keyValuePair.fOffset; return new ReplaceEdit(keyValuePair.fOffset, range, newText); } } return null; }
private void openEditButton(ISelection selection) { try { IStructuredSelection sel= (IStructuredSelection) fTableViewer.getSelection(); NLSSubstitution substitution= (NLSSubstitution) sel.getFirstElement(); if (substitution == null) { return; } NLSInputDialog dialog= new NLSInputDialog(getShell(), substitution); if (dialog.open() == Window.CANCEL) return; KeyValuePair kvPair= dialog.getResult(); if (substitution.getState() == NLSSubstitution.EXTERNALIZED) { substitution.setKey(kvPair.getKey()); } substitution.setValue(kvPair.getValue()); validateKeys(false); } finally { fTableViewer.refresh(); fTableViewer.getControl().setFocus(); fTableViewer.setSelection(selection); } }
return null; String value= oldPair.getValue(); KeyValuePair newPair= new KeyValuePair(fNewName, value); ReplaceEdit edit= model.replace(oldPair, newPair); if (edit == null)
public ReplaceEdit replace(KeyValuePair toReplace, KeyValuePair replaceWith) { for (Iterator<KeyValuePairModell> iter = fKeyValuePairs.iterator(); iter.hasNext();) { KeyValuePairModell keyValuePair = iter.next(); if (keyValuePair.fKey.equals(toReplace.getKey())) { String newText= new KeyValuePairModell(replaceWith).getKeyValueText(); return new ReplaceEdit(keyValuePair.fOffset, keyValuePair.getLength(), newText); } } return null; }
private void openEditButton(ISelection selection) { try { IStructuredSelection sel= (IStructuredSelection) fTableViewer.getSelection(); NLSSubstitution substitution= (NLSSubstitution) sel.getFirstElement(); if (substitution == null) { return; } NLSInputDialog dialog= new NLSInputDialog(getShell(), substitution); if (dialog.open() == Window.CANCEL) return; KeyValuePair kvPair= dialog.getResult(); if (substitution.getState() == NLSSubstitution.EXTERNALIZED) { substitution.setKey(kvPair.getKey()); } substitution.setValue(kvPair.getValue()); validateKeys(false); } finally { fTableViewer.refresh(); fTableViewer.getControl().setFocus(); fTableViewer.setSelection(selection); } }
public KeyValuePair getResult() { KeyValuePair res= new KeyValuePair(fKeyField.getText(), fValueField.getText()); return res; }
public ReplaceEdit replace(KeyValuePair toReplace, KeyValuePair replaceWith) { for (Iterator<KeyValuePairModell> iter = fKeyValuePairs.iterator(); iter.hasNext();) { KeyValuePairModell keyValuePair = iter.next(); if (keyValuePair.fKey.equals(toReplace.getKey())) { String newText= new KeyValuePairModell(replaceWith).getKeyValueText(); return new ReplaceEdit(keyValuePair.fOffset, keyValuePair.getLength(), newText); } } return null; }
public KeyValuePair getResult() { KeyValuePair res= new KeyValuePair(fKeyField.getText(), fValueField.getText()); return res; }
/** * Inserts the given key value pairs into this model at appropriate * positions. Records all required text changes in the given change * * @param keyValuePairs the key value pairs to insert * @param change the change to use to record text changes */ public void insert(KeyValuePair[] keyValuePairs, TextChange change) { ArrayList<KeyValuePair> sorted= new ArrayList<>(Arrays.asList(keyValuePairs)); Collections.sort(sorted, new Comparator<KeyValuePair>() { @Override public int compare(KeyValuePair p1, KeyValuePair p2) { return Collator.getInstance().compare(p1.fKey, p2.fKey); } }); for (int i = 0; i < sorted.size(); i++) { KeyValuePair curr= sorted.get(i); InsertEdit insertEdit= insert(curr); String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, BasicElementLabels.getJavaElementName(curr.getKey())); TextChangeCompatibility.addTextEdit(change, message, insertEdit); } }
public KeyValuePair getResult() { KeyValuePair res= new KeyValuePair(fKeyField.getText(), fValueField.getText()); return res; }
/** * Inserts the given key value pairs into this model at appropriate * positions. Records all required text changes in the given change * * @param keyValuePairs the key value pairs to insert * @param change the change to use to record text changes */ public void insert(KeyValuePair[] keyValuePairs, TextChange change) { ArrayList<KeyValuePair> sorted= new ArrayList<>(Arrays.asList(keyValuePairs)); Collections.sort(sorted, new Comparator<KeyValuePair>() { @Override public int compare(KeyValuePair p1, KeyValuePair p2) { return Collator.getInstance().compare(p1.fKey, p2.fKey); } }); for (int i = 0; i < sorted.size(); i++) { KeyValuePair curr= sorted.get(i); InsertEdit insertEdit= insert(curr); String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, BasicElementLabels.getJavaElementName(curr.getKey())); TextChangeCompatibility.addTextEdit(change, message, insertEdit); } }
private static void addInsertEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { ArrayList<KeyValuePair> keyValuePairsToAdd= new ArrayList<>(); for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { String value= PropertyFileDocumentModel.escape(substitution.getValueNonEmpty(), true) + model.getLineDelimiter(); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); keyValuePairsToAdd.add(new KeyValuePair(key, value)); } } if (keyValuePairsToAdd.size() > 0) { model.insert(keyValuePairsToAdd.toArray(new KeyValuePair[keyValuePairsToAdd.size()]), textChange); } }
private static void addInsertEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { ArrayList<KeyValuePair> keyValuePairsToAdd= new ArrayList<>(); for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { String value= PropertyFileDocumentModel.escape(substitution.getValueNonEmpty(), true) + model.getLineDelimiter(); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); keyValuePairsToAdd.add(new KeyValuePair(key, value)); } } if (keyValuePairsToAdd.size() > 0) { model.insert(keyValuePairsToAdd.toArray(new KeyValuePair[keyValuePairsToAdd.size()]), textChange); } }
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map newKeyToSubstMap, Map oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); KeyValuePair newPair= new KeyValuePair(substitution.getKey(), substitution.getValueNonEmpty()); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, substitution.getKey()), edit); } } } }
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); String value= PropertyFileDocumentModel.escape(substitution.getValue(), true) + model.getLineDelimiter(); KeyValuePair newPair= new KeyValuePair(key, value); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, BasicElementLabels.getJavaElementName(substitution.getKey())), edit); } } } }
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); String value= PropertyFileDocumentModel.escape(substitution.getValue(), true) + model.getLineDelimiter(); KeyValuePair newPair= new KeyValuePair(key, value); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, BasicElementLabels.getJavaElementName(substitution.getKey())), edit); } } } }