001 /* 002 * The contents of this file are subject to the Mozilla Public 003 * License Version 1.1 (the "License"); you may not use this file 004 * except in compliance with the License. You may obtain a copy of 005 * the License at http://www.mozilla.org/MPL/ 006 * 007 * Software distributed under the License is distributed on an "AS 008 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 009 * implied. See the License for the specific language governing 010 * rights and limitations under the License. 011 * 012 * The Original Code is Knowtator. 013 * 014 * The Initial Developer of the Original Code is University of Colorado. 015 * Copyright (C) 2005 - 2008. All Rights Reserved. 016 * 017 * Knowtator was developed by the Center for Computational Pharmacology 018 * (http://compbio.uchcs.edu) at the University of Colorado Health 019 * Sciences Center School of Medicine with support from the National 020 * Library of Medicine. 021 * 022 * Current information about Knowtator can be obtained at 023 * http://knowtator.sourceforge.net/ 024 * 025 * Contributor(s): 026 * Philip V. Ogren <philip@ogren.info> (Original Author) 027 */ 028 029 package edu.uchsc.ccp.knowtator.util; 030 031 import java.util.ArrayList; 032 import java.util.Collection; 033 import java.util.Iterator; 034 import java.util.List; 035 036 import edu.stanford.smi.protege.model.Cls; 037 import edu.stanford.smi.protege.model.Project; 038 import edu.stanford.smi.protege.model.SimpleInstance; 039 import edu.stanford.smi.protege.model.Slot; 040 import edu.stanford.smi.protege.widget.ClsWidget; 041 import edu.stanford.smi.protege.widget.SlotWidget; 042 043 public class ProtegeUtil { 044 045 /** 046 * It seems like there should be a better way of accomplishing this. If you 047 * have suggestions please send them to me! 048 * 049 * @param simpleInstances 050 */ 051 public static Collection<SimpleInstance> castSimpleInstances(Collection simpleInstances) { 052 // return Collections.checkedCollection(simpleInstances, 053 // SimpleInstance.class); 054 List<SimpleInstance> returnValues = new ArrayList<SimpleInstance>(); 055 Iterator simpleInstancesIt = simpleInstances.iterator(); 056 while (simpleInstancesIt.hasNext()) { 057 returnValues.add((SimpleInstance) simpleInstancesIt.next()); 058 } 059 return returnValues; 060 } 061 062 public static Collection<String> castStrings(Collection strings) { 063 List<String> returnValues = new ArrayList<String>(); 064 Iterator stringsIt = strings.iterator(); 065 while (stringsIt.hasNext()) { 066 returnValues.add((String) stringsIt.next()); 067 } 068 return returnValues; 069 } 070 071 public static String getSlotLabel(Cls cls, Slot slot, Project project) { 072 String slotLabel = null; 073 try { 074 ClsWidget clsWidget = project.getDesignTimeClsWidget(cls); 075 if (clsWidget != null) { 076 SlotWidget slotWidget = clsWidget.getSlotWidget(slot); 077 if (slotWidget != null) 078 slotLabel = slotWidget.getLabel(); 079 } 080 } catch (Exception e) { 081 e.printStackTrace(); 082 } 083 084 if (slotLabel != null) 085 return slotLabel; 086 else 087 return slot.getBrowserText(); 088 089 } 090 }