/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.helpers;
import java.text.ParseException;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITypedRegion;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.tml.TMLPartitionScanner;
import de.innovationgate.eclipse.editors.tml.TMLRegion;
public class ActionIDLookup implements AttributeValueLookup {
public Set<String> lookupValues(TMLRegion region, IDocument document, ITextViewer viewer, IFile activeFile) {
Set<String> actionIds = new HashSet<String>();
try {
ITypedRegion[] partitions = document.computePartitioning(0, document.getLength());
for (ITypedRegion partition : partitions) {
if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
TMLRegion unknownRegion;
try {
unknownRegion = TMLRegion.parse(partition, document);
if (unknownRegion.getTagName() != null && unknownRegion.getTagName().equals("action")) {
String actionId = unknownRegion.getAttributeValue("id");
if (actionId != null && !actionId.trim().equals("")) {
actionIds.add(actionId);
}
}
} catch (ParseException e) {
Plugin.getDefault().logError("Unable to parse region at '" + partition.getOffset() + "'.", e);
}
}
}
} catch (BadLocationException e) {
Plugin.getDefault().logError("Unable to lookup action ids.", e);
}
return actionIds;
}
}