Skip to content

Commit

Permalink
Adds an "Attributes" category to shapefiles in the navigator (see #3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Mar 10, 2022
1 parent 9a7c8ea commit e3ab832
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 86 deletions.
3 changes: 3 additions & 0 deletions ummisco.gama.ui.navigator/plugin.xml
Expand Up @@ -57,6 +57,9 @@
</objectState>
</or>
</and>
<objectClass
name="ummisco.gama.ui.navigator.contents.Tag">
</objectClass>
<objectClass
name="ummisco.gama.ui.navigator.contents.WrappedFolder">
</objectClass>
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* Tag.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* Tag.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.ui.navigator.contents;

Expand All @@ -22,12 +22,20 @@
*/
public class Tag extends VirtualContent<Tags> {

/** The search. */
private final boolean search;

/** The suffix. */
private final String suffix;

/**
* @param root
* @param name
*/
public Tag(final Tags root, final String wrapped) {
public Tag(final Tags root, final String wrapped, final String suffix, final boolean search) {
super(root, wrapped);
this.search = search;
this.suffix = suffix;
}

/**
Expand All @@ -40,11 +48,6 @@ public boolean hasChildren() {
return false;
}

// @Override
// public Font getFont() {
// return GamaFonts.getNavigLinkFont(); // by default
// }

/**
* Method getNavigatorChildren()
*
Expand All @@ -61,16 +64,6 @@ public boolean hasChildren() {
@Override
public Image getImage() { return null; }

/**
* Method getColor()
*
* @see ummisco.gama.ui.navigator.contents.VirtualContent#getColor()
*/
// @Override
// public Color getColor() {
// return ThemeHelper.isDark() ? GamaColors.system(SWT.COLOR_WHITE) : GamaColors.system(SWT.COLOR_BLACK);
// }

@Override
public boolean handleDoubleClick() {
return true;
Expand All @@ -83,7 +76,7 @@ public int findMaxProblemSeverity() {

@Override
public void getSuffix(final StringBuilder sb) {
// sb.append(suffix);
if (suffix != null) { sb.append(suffix); }
}

@Override
Expand Down
@@ -1,20 +1,21 @@
/*******************************************************************************************************
*
* Tags.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* Tags.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.ui.navigator.contents;

import java.util.Collection;
import java.util.Map;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

import one.util.streamex.StreamEx;
import ummisco.gama.ui.resources.GamaColors.GamaUIColor;
import ummisco.gama.ui.resources.GamaIcons;
import ummisco.gama.ui.resources.IGamaColors;
Expand All @@ -29,15 +30,20 @@
public class Tags extends VirtualContent<WrappedFile> {

/** The tags. */
final Collection<String> tags;
final Map<String, String> tags;

/** The search. */
final boolean search;

/**
* @param root
* @param name
*/
public Tags(final WrappedFile root, final Collection<String> object, final String name) {
public Tags(final WrappedFile root, final Map<String, String> object, final String name,
final boolean doubleClickForSearching) {
super(root, name);
tags = object;
search = doubleClickForSearching;
}

/**
Expand All @@ -50,14 +56,6 @@ public boolean hasChildren() {
return !tags.isEmpty();
}

// @Override
// public Font getFont() {
// return GamaFonts.getSmallFont(); // by default
// }

@Override
public WrappedFile getParent() { return super.getParent(); }

/**
* Method getNavigatorChildren()
*
Expand All @@ -66,7 +64,7 @@ public boolean hasChildren() {
@Override
public Object[] getNavigatorChildren() {
if (tags.isEmpty()) return EMPTY;
return tags.stream().map(each -> new Tag(this, each)).toArray();
return StreamEx.ofKeys(tags).map(each -> new Tag(this, each, tags.get(each), search)).toArray();
}

/**
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* WrappedFile.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* WrappedFile.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.ui.navigator.contents;

Expand All @@ -26,6 +26,7 @@
import org.eclipse.swt.graphics.Image;

import msi.gama.runtime.GAMA;
import msi.gama.util.file.GamaShapeFile.ShapeInfo;
import msi.gama.util.file.IGamaFileMetaData;
import msi.gaml.compilation.kernel.GamaBundleLoader;
import ummisco.gama.ui.navigator.NavigatorContentProvider;
Expand All @@ -39,21 +40,23 @@ public class WrappedFile extends WrappedResource<WrappedResource<?, ?>, IFile> {

/** The file parent. */
WrappedFile fileParent;

/** The is shape file. */
boolean isShapeFile;

/** The is shape file support. */
boolean isShapeFileSupport;

/** The image. */
Image image;

/**
* Instantiates a new wrapped file.
*
* @param root the root
* @param wrapped the wrapped
* @param root
* the root
* @param wrapped
* the wrapped
*/
public WrappedFile(final WrappedContainer<?> root, final IFile wrapped) {
super(root, wrapped);
Expand Down Expand Up @@ -128,11 +131,14 @@ public Object[] getFileChildren() {
final IFile p = getResource();
try {
final IContainer folder = p.getParent();
final List<WrappedFile> sub = new ArrayList<>();
final List<VirtualContent> sub = new ArrayList<>();
for (final IResource r : folder.members()) {
if (r instanceof IFile && isSupport(p, (IFile) r)) {
sub.add((WrappedFile) getManager().findWrappedInstanceOf(r));
}
if (r instanceof IFile && isSupport(p, (IFile) r)) { sub.add(getManager().findWrappedInstanceOf(r)); }
}
final IGamaFileMetaData metaData = GAMA.getGui().getMetaDataProvider().getMetaData(p, false, false);
if (metaData instanceof ShapeInfo info && !info.getAttributes().isEmpty()) {
final Tags wf = new Tags(this, info.getAttributes(), "Attributes", false);
if (wf.getNavigatorChildren().length > 0) { sub.add(wf); }
}
return sub.toArray();
} catch (final CoreException e) {
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* WrappedGamaFile.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* WrappedGamaFile.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.ui.navigator.contents;

Expand All @@ -31,6 +31,7 @@
import msi.gaml.compilation.GAML;
import msi.gaml.compilation.ast.ISyntacticElement;
import msi.gaml.descriptions.IExpressionDescription;
import one.util.streamex.StreamEx;
import ummisco.gama.ui.navigator.NavigatorContentProvider;
import ummisco.gama.ui.resources.GamaIcons;

Expand All @@ -41,15 +42,17 @@ public class WrappedGamaFile extends WrappedFile {

/** The is experiment. */
boolean isExperiment;

/** The uri problems. */
IMap<String, Integer> uriProblems;

/**
* Instantiates a new wrapped gama file.
*
* @param root the root
* @param wrapped the wrapped
* @param root
* the root
* @param wrapped
* the wrapped
*/
public WrappedGamaFile(final WrappedContainer<?> root, final IFile wrapped) {
super(root, wrapped);
Expand All @@ -66,9 +69,7 @@ public void computeURIProblems() {
for (final IMarker marker : markers) {
final String s = marker.getAttribute("URI_KEY", "UNKNOWN");
final int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
if (uriProblems == null) {
uriProblems = GamaMapFactory.createUnordered();
}
if (uriProblems == null) { uriProblems = GamaMapFactory.createUnordered(); }
uriProblems.put(s, severity);
}
} catch (final CoreException ce) {}
Expand All @@ -87,14 +88,12 @@ public boolean hasChildren() {

@Override
public Object[] getNavigatorChildren() {
if (NavigatorContentProvider.FILE_CHILDREN_ENABLED) { return getFileChildren(); }
if (NavigatorContentProvider.FILE_CHILDREN_ENABLED) return getFileChildren();
return EMPTY;
}

@Override
public boolean isGamaFile() {
return true;
}
public boolean isGamaFile() { return true; }

@Override
public int countModels() {
Expand All @@ -121,56 +120,44 @@ protected void computeFileType() {
/**
* Checks for tag.
*
* @param tag the tag
* @param tag
* the tag
* @return true, if successful
*/
public boolean hasTag(final String tag) {
final IGamaFileMetaData metaData = GAMA.getGui().getMetaDataProvider().getMetaData(getResource(), false, false);
// DEBUG.LOG("Tags of " + getName() + ": " + ((GamlFileInfo) metaData).getTags());
if (metaData instanceof GamlFileInfo) {
for (final String t : ((GamlFileInfo) metaData).getTags()) {
if (t.contains(tag)) { return true; }
}
for (final String t : ((GamlFileInfo) metaData).getTags()) { if (t.contains(tag)) return true; }
}
return false;
}

@Override
public Object[] getFileChildren() {
final IGamaFileMetaData metaData = GAMA.getGui().getMetaDataProvider().getMetaData(getResource(), false, false);
if (metaData instanceof GamlFileInfo) {
final GamlFileInfo info = (GamlFileInfo) metaData;
if (metaData instanceof GamlFileInfo info) {
final List<VirtualContent<?>> l = new ArrayList<>();
final String path = getResource().getFullPath().toOSString();
final ISyntacticElement element = GAML.getContents(URI.createPlatformResourceURI(path, true));
if (element != null) {
if (!GamlFileExtension.isExperiment(path)) {
l.add(new WrappedModelContent(this, element));
}
if (!GamlFileExtension.isExperiment(path)) { l.add(new WrappedModelContent(this, element)); }
element.visitExperiments(exp -> {
final IExpressionDescription d = exp.getExpressionAt(IKeyword.VIRTUAL);
if (d == null || !d.equalsString("true")) {
l.add(new WrappedExperimentContent(this, exp));
}
if (d == null || !d.equalsString("true")) { l.add(new WrappedExperimentContent(this, exp)); }
});
}
if (!info.getImports().isEmpty()) {
final Category wf = new Category(this, info.getImports(), "Imports");
if (wf.getNavigatorChildren().length > 0) {
l.add(wf);
}
if (wf.getNavigatorChildren().length > 0) { l.add(wf); }
}
if (!info.getUses().isEmpty()) {
final Category wf = new Category(this, info.getUses(), "Uses");
if (wf.getNavigatorChildren().length > 0) {
l.add(wf);
}
if (wf.getNavigatorChildren().length > 0) { l.add(wf); }
}
if (!info.getTags().isEmpty()) {
final Tags wf = new Tags(this, info.getTags(), "Tags");
if (wf.getNavigatorChildren().length > 0) {
l.add(wf);
}
final Tags wf = new Tags(this, StreamEx.of(info.getTags()).toMap(s -> null), "Tags", true);
if (wf.getNavigatorChildren().length > 0) { l.add(wf); }
}
return l.toArray();
}
Expand All @@ -180,15 +167,15 @@ public Object[] getFileChildren() {
/**
* Gets the URI problem.
*
* @param uri the uri
* @param uri
* the uri
* @return the URI problem
*/
public int getURIProblem(final URI uri) {

if (uri == null) { return -1; }
if (uriProblems == null) { return -1; }
if (uri == null || uriProblems == null) return -1;
final String fragment = uri.toString();
final int[] severity = new int[] { -1 };
final int[] severity = { -1 };
uriProblems.forEachPair((s, arg1) -> {
if (s.startsWith(fragment)) {
severity[0] = arg1;
Expand Down

0 comments on commit e3ab832

Please sign in to comment.