Skip to content

Commit

Permalink
Fixes #3305 by coloring built-in attributes in shapefiles in red
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Mar 23, 2022
1 parent 00531c7 commit 1322364
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 57 deletions.
@@ -1,18 +1,20 @@
/*******************************************************************************************************
*
* NavigatorLabelProvider.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* NavigatorLabelProvider.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;

import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

import ummisco.gama.ui.navigator.contents.VirtualContent;
Expand All @@ -21,7 +23,7 @@
* The Class NavigatorLabelProvider.
*/
public class NavigatorLabelProvider extends CellLabelProvider
implements ILabelProvider/* , IColorProvider , IFontProvider */ {
implements ILabelProvider, IColorProvider /* IFontProvider */ {

@Override
public String getText(final Object element) {
Expand All @@ -46,16 +48,16 @@ public boolean isLabelProperty(final Object element, final String property) {
// return GamaFonts.getNavigFolderFont();
// }

// @Override
// public Color getForeground(final Object element) {
// // if (element instanceof VirtualContent) return ((VirtualContent<?>) element).getColor();
// return null;
// }
//
// @Override
// public Color getBackground(final Object element) {
// return null;
// }
@Override
public Color getForeground(final Object element) {
if (element instanceof VirtualContent) return ((VirtualContent<?>) element).getColor();
return null;
}

@Override
public Color getBackground(final Object element) {
return null;
}

@Override
public void update(final ViewerCell cell) {}
Expand Down
Expand Up @@ -11,8 +11,12 @@
package ummisco.gama.ui.navigator.contents;

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

import ummisco.gama.ui.resources.GamaColors;

/**
* Class LinkedFile.
*
Expand Down Expand Up @@ -85,4 +89,10 @@ public void getSuffix(final StringBuilder sb) {
@Override
public VirtualContentType getType() { return VirtualContentType.CATEGORY; }

@Override
public Color getColor() {
if (suffix.contains("built-in attribute")) return GamaColors.system(SWT.COLOR_RED);
return null;
}

}
Expand Up @@ -13,9 +13,12 @@
import java.util.Map;

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

import one.util.streamex.StreamEx;
import ummisco.gama.ui.resources.GamaColors;
import ummisco.gama.ui.resources.GamaColors.GamaUIColor;
import ummisco.gama.ui.resources.GamaIcons;
import ummisco.gama.ui.resources.IGamaColors;
Expand Down Expand Up @@ -80,11 +83,13 @@ public Object[] getNavigatorChildren() {
*
* @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 Color getColor() {
for (String s : tags.values()) {
if (s.contains("built-in attribute")) return GamaColors.system(SWT.COLOR_RED);
}
return null;
}

@Override
public void getSuffix(final StringBuilder sb) {}
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* VirtualContent.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* VirtualContent.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 @@ -18,6 +18,7 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider;

Expand All @@ -28,31 +29,32 @@
/**
* The Class VirtualContent.
*
* @param <P> the generic type
* @param <P>
* the generic type
*/
public abstract class VirtualContent<P extends VirtualContent<?>> {

/**
* The Enum VirtualContentType.
*/
public enum VirtualContentType {

/** The root. */
ROOT,
/** The virtual folder. */
VIRTUAL_FOLDER,
/** The project. */
PROJECT,
/** The folder. */
FOLDER,
/** The file. */
FILE,
/** The file reference. */
FILE_REFERENCE,
/** The category. */
CATEGORY,
/** The gaml element. */
GAML_ELEMENT
ROOT,
/** The virtual folder. */
VIRTUAL_FOLDER,
/** The project. */
PROJECT,
/** The folder. */
FOLDER,
/** The file. */
FILE,
/** The file reference. */
FILE_REFERENCE,
/** The category. */
CATEGORY,
/** The gaml element. */
GAML_ELEMENT
}

/** The default label provider. */
Expand All @@ -76,36 +78,38 @@ public enum VirtualContentType {

/** The Constant NO_PROBLEM. */
public static final int NO_PROBLEM = -1;

/** The Constant CLOSED. */
public static final int CLOSED = -2;

/** The Constant LINK_OK. */
public static final int LINK_OK = -3;

/** The Constant LINK_BROKEN. */
public static final int LINK_BROKEN = -4;

/** The Constant WEBLINK_OK. */
public static final int WEBLINK_OK = -5;

/** The Constant WEBLINK_BROKEN. */
public static final int WEBLINK_BROKEN = -6;

/** The empty. */
public static Object[] EMPTY = {};

/** The root. */
private final P root;

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

/**
* Instantiates a new virtual content.
*
* @param root the root
* @param name the name
* @param root
* the root
* @param name
* the name
*/
public VirtualContent(final P root, final String name) {
this.root = root;
Expand Down Expand Up @@ -180,12 +184,13 @@ public boolean handleSingleClick() {
*/
public abstract Image getImage();

// public abstract Color getColor();
public Color getColor() { return null; }

/**
* Gets the suffix.
*
* @param sb the sb
* @param sb
* the sb
* @return the suffix
*/
public abstract void getSuffix(StringBuilder sb);
Expand Down Expand Up @@ -261,7 +266,8 @@ public WrappedProject getProject() {
/**
* Checks if is contained in.
*
* @param current the current
* @param current
* the current
* @return true, if is contained in
*/
public boolean isContainedIn(final VirtualContent<?> current) {
Expand Down
Expand Up @@ -17,19 +17,25 @@
import static ummisco.gama.ui.metadata.FileMetaDataProvider.shapeFileSupportedBy;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
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 msi.gaml.types.Types;
import ummisco.gama.ui.navigator.NavigatorContentProvider;
import ummisco.gama.ui.resources.GamaColors;
import ummisco.gama.ui.resources.GamaIcons;
import ummisco.gama.ui.utils.PreferencesHelper;

Expand All @@ -50,6 +56,8 @@ public class WrappedFile extends WrappedResource<WrappedResource<?, ?>, IFile> {
/** The image. */
Image image;

Color color;

/**
* Instantiates a new wrapped file.
*
Expand Down Expand Up @@ -136,8 +144,16 @@ public Object[] getFileChildren() {
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);
Map<String, String> attributes;
if (metaData instanceof ShapeInfo info && !(attributes = info.getAttributes()).isEmpty()) {
Map<String, String> tags = new LinkedHashMap<>(attributes);
attributes.forEach((k, v) -> {
if (Types.AGENT.getSpecies().hasAttribute(k)) {
tags.put(k, tags.get(k) + " <- built-in attribute of agents");
color = GamaColors.system(SWT.COLOR_RED);
}
});
final Tags wf = new Tags(this, tags, "Attributes", false);
if (wf.getNavigatorChildren().length > 0) { sub.add(wf); }
}
return sub.toArray();
Expand All @@ -158,10 +174,8 @@ public Image getImage() {
return image;
}

// @Override
// public Color getColor() {
// return null;
// }
@Override
public Color getColor() { return color; }

@Override
public void getSuffix(final StringBuilder sb) {
Expand Down

0 comments on commit 1322364

Please sign in to comment.