Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library view now uses file's scope. Preliminary search working.
- Loading branch information
John J. Camilleri
authored and
John J. Camilleri
committed
Apr 17, 2012
1 parent
e65f3a5
commit 2fe2658
Showing
4 changed files
with
277 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...work.eclipse.ui/src/org/grammaticalframework/eclipse/ui/views/GFScopeContentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/** | ||
* GF Eclipse Plugin | ||
* http://www.grammaticalframework.org/eclipse/ | ||
* John J. Camilleri, 2012 | ||
* | ||
* The research leading to these results has received funding from the | ||
* European Union's Seventh Framework Programme (FP7/2007-2013) under | ||
* grant agreement no. FP7-ICT-247914. | ||
*/ | ||
package org.grammaticalframework.eclipse.ui.views; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.jface.viewers.ITreeContentProvider; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.xtext.resource.IEObjectDescription; | ||
import org.eclipse.xtext.scoping.IGlobalScopeProvider; | ||
import org.eclipse.xtext.scoping.IScope; | ||
import org.grammaticalframework.eclipse.gF.GFPackage; | ||
import org.grammaticalframework.eclipse.scoping.TagEntry; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class GFScopeContentProvider implements ITreeContentProvider { | ||
|
||
class ModuleItem { | ||
private String name; | ||
|
||
public ModuleItem(String name) { | ||
super(); | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
/* Code below auto-generated by Eclipse */ | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + getOuterType().hashCode(); | ||
result = prime * result + ((name == null) ? 0 : name.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
ModuleItem other = (ModuleItem) obj; | ||
if (!getOuterType().equals(other.getOuterType())) | ||
return false; | ||
if (name == null) { | ||
if (other.name != null) | ||
return false; | ||
} else if (!name.equals(other.name)) | ||
return false; | ||
return true; | ||
} | ||
|
||
private GFScopeContentProvider getOuterType() { | ||
return GFScopeContentProvider.this; | ||
} | ||
|
||
} | ||
|
||
@Inject | ||
IGlobalScopeProvider scopeProvider; | ||
|
||
private Map<ModuleItem, List<IEObjectDescription>> tagMap; | ||
|
||
@Override | ||
public void dispose() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | ||
tagMap = new HashMap<ModuleItem, List<IEObjectDescription>>(); | ||
|
||
if (newInput == null) | ||
return; | ||
|
||
// Get scope | ||
Resource resource = (Resource)newInput; | ||
IScope scope = scopeProvider.getScope(resource, GFPackage.Literals.EXP__IDENT, null); | ||
Iterable<IEObjectDescription> items = scope.getAllElements(); | ||
|
||
// Organise into modules | ||
for (IEObjectDescription ieObjectDescription : items) { | ||
ModuleItem module = new ModuleItem(ieObjectDescription.getUserData(TagEntry.USER_DATA_KEY_MODULENAME)); | ||
if (!tagMap.containsKey(module)) { | ||
tagMap.put(module, new ArrayList<IEObjectDescription>()); | ||
} | ||
tagMap.get(module).add(ieObjectDescription); | ||
} | ||
} | ||
|
||
/** | ||
* Get list module names in the scope | ||
*/ | ||
@Override | ||
public Object[] getElements(Object inputElement) { | ||
return tagMap.keySet().toArray(); | ||
} | ||
|
||
/** | ||
* Get the children of any module in the scope | ||
*/ | ||
@Override | ||
public Object[] getChildren(Object parentElement) { | ||
if (parentElement instanceof ModuleItem) { | ||
List<IEObjectDescription> items = tagMap.get(parentElement); | ||
return items.toArray(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Object getParent(Object element) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean hasChildren(Object element) { | ||
return (element instanceof ModuleItem); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...mework.eclipse.ui/src/org/grammaticalframework/eclipse/ui/views/GFScopeLabelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* GF Eclipse Plugin | ||
* http://www.grammaticalframework.org/eclipse/ | ||
* John J. Camilleri, 2012 | ||
* | ||
* The research leading to these results has received funding from the | ||
* European Union's Seventh Framework Programme (FP7/2007-2013) under | ||
* grant agreement no. FP7-ICT-247914. | ||
*/ | ||
package org.grammaticalframework.eclipse.ui.views; | ||
|
||
import org.eclipse.jface.viewers.StyledCellLabelProvider; | ||
import org.eclipse.jface.viewers.StyledString; | ||
import org.eclipse.jface.viewers.ViewerCell; | ||
import org.eclipse.xtext.resource.IEObjectDescription; | ||
import org.grammaticalframework.eclipse.scoping.TagEntry; | ||
import org.grammaticalframework.eclipse.ui.labeling.GFImages; | ||
import org.grammaticalframework.eclipse.ui.labeling.GFLabelProvider; | ||
import org.grammaticalframework.eclipse.ui.views.GFScopeContentProvider.ModuleItem; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class GFScopeLabelProvider extends StyledCellLabelProvider { | ||
|
||
/** | ||
* Image helper | ||
*/ | ||
@Inject | ||
private GFImages images; | ||
|
||
@Inject | ||
private GFLabelProvider labelProvider; | ||
|
||
@Override | ||
public void update(ViewerCell cell) { | ||
if (cell.getElement() instanceof ModuleItem) { | ||
ModuleItem moduleItem = (ModuleItem)cell.getElement(); | ||
|
||
cell.setImage(images.forLibraryReference()); | ||
cell.setText(moduleItem.getName()); | ||
|
||
} else if (cell.getElement() instanceof IEObjectDescription) { | ||
IEObjectDescription item = (IEObjectDescription)cell.getElement(); | ||
|
||
// IEObjectDescription item = (IEObjectDescription)element; | ||
// item.getUserData(TagEntry.USER_DATA_KEY_TYPE); | ||
cell.setImage(images.forAnyJudgement()); | ||
|
||
String name = item.getName().toString(); | ||
String type = item.getUserData(TagEntry.USER_DATA_KEY_ARGS); | ||
StyledString styledString = labelProvider.twoPartLabel(name, type); | ||
|
||
cell.setText(styledString.getString()); | ||
cell.setStyleRanges(styledString.getStyleRanges()); | ||
} | ||
|
||
super.update(cell); | ||
} | ||
|
||
} |