/*******************************************************************************
* 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.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.tml.TMLRegion;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
public class LabelFileLookup implements AttributeValueLookup {
public Set<String> lookupValues(TMLRegion region, IDocument document, ITextViewer viewer, IFile activeFile) {
Set<String> labelFilenames = new HashSet<String>();
try {
WGADesignStructureHelper designHelper = new WGADesignStructureHelper(activeFile);
String language = designHelper.getDevelopmentLanguage();
IFolder labelContainer = designHelper.getLabelContainer(language);
if (labelContainer != null && labelContainer.exists()) {
Iterator<IFile> labelFiles = designHelper.getLabelFiles(labelContainer).iterator();
while (labelFiles.hasNext()) {
IFile labelFile = labelFiles.next();
labelFilenames.add(labelFile.getName().substring(0, labelFile.getName().length() - (labelFile.getFileExtension().length() + 1)));
}
}
} catch (CoreException e) {
Plugin.getDefault().logError("Unable to lookup label files.", e);
}
return labelFilenames;
}
public static String determineLabelFileName(TMLRegion tmlLabelTag) {
if (tmlLabelTag.hasAttribute("file") && tmlLabelTag.isDynamicAttributeValue("file")) {
// dynamic label file
return null;
} else if (tmlLabelTag.hasAttribute("file")) {
return tmlLabelTag.getAttributeValue("file");
} else {
return "general";
}
}
}