1 package no.uio.ifi.refaktor.handlers;
3 import no.uio.ifi.refaktor.extractors.Prefix;
4 import no.uio.ifi.refaktor.extractors.UnionOfLongestCommonPrefixesExtractor;
5 import no.uio.ifi.refaktor.utils.ParseUtils;
6 import no.uio.ifi.refaktor.utils.SmartTextSelection;
8 import org.eclipse.core.commands.ExecutionEvent;
9 import org.eclipse.core.commands.ExecutionException;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.text.IDocument;
12 import org.eclipse.jface.text.ITextSelection;
13 import org.eclipse.jface.text.TextSelection;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.ui.handlers.HandlerUtil;
16 import org.eclipse.ui.texteditor.ITextEditor;
18 public class TestPropertyExtractorHandler extends SelectionAbstractHandler {
21 public Object execute(ExecutionEvent event) throws ExecutionException {
22 ITextEditor editor = getEditor(event);
23 IDocument document = getDocument(editor);
25 ITextSelection strippedTextSelection = ParseUtils.stripTextSelection(document, getTextSelection(event));
26 SmartTextSelection smartTextSelection = new SmartTextSelection(document, strippedTextSelection);
27 editor.getSite().getSelectionProvider().setSelection(smartTextSelection);
29 UnionOfLongestCommonPrefixesExtractor extractor = new UnionOfLongestCommonPrefixesExtractor(smartTextSelection);
30 // LongestCommonPrefixExtractor extractor = new LongestCommonPrefixExtractor(smartTextSelection);
31 String dialogText = "";
32 if (extractor.selectionIsValid()) {
33 extractor.extractProperty();
34 for (Prefix p: extractor.getPrefixes().values()) {
35 dialogText += p.toString() + " (" + p.getCount() + ")\n";
37 // dialogText += extractor.stringProperty();
39 dialogText = "Selection is invalid";
42 MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), "Test Property Extractor", dialogText);
46 private TextSelection getTextSelection(ExecutionEvent event) throws ExecutionException {
47 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
48 assert selection instanceof TextSelection;
49 return (TextSelection) selection;