package no.uio.ifi.refaktor.handlers; import no.uio.ifi.refaktor.extractors.Prefix; import no.uio.ifi.refaktor.extractors.UnionOfLongestCommonPrefixesExtractor; import no.uio.ifi.refaktor.utils.ParseUtils; import no.uio.ifi.refaktor.utils.SmartTextSelection; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.texteditor.ITextEditor; public class TestPropertyExtractorHandler extends SelectionAbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { ITextEditor editor = getEditor(event); IDocument document = getDocument(editor); ITextSelection strippedTextSelection = ParseUtils.stripTextSelection(document, getTextSelection(event)); SmartTextSelection smartTextSelection = new SmartTextSelection(document, strippedTextSelection); editor.getSite().getSelectionProvider().setSelection(smartTextSelection); UnionOfLongestCommonPrefixesExtractor extractor = new UnionOfLongestCommonPrefixesExtractor(smartTextSelection); // LongestCommonPrefixExtractor extractor = new LongestCommonPrefixExtractor(smartTextSelection); String dialogText = ""; if (extractor.selectionIsValid()) { extractor.extractProperty(); for (Prefix p: extractor.getPrefixes().values()) { dialogText += p.toString() + " (" + p.getCount() + ")\n"; } // dialogText += extractor.stringProperty(); } else { dialogText = "Selection is invalid"; } MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), "Test Property Extractor", dialogText); return null; } private TextSelection getTextSelection(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); assert selection instanceof TextSelection; return (TextSelection) selection; } }