JMapframe displays only a single shapefile - netbeans

I used the Netbeans and GeoTools to program a graphical interface to display multiple shapefiles in the same JmapFrame. I used the following code but I do not know, when execute, it display only one shapefile.Svp, someone can help me, I await your answers.
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import java.io.File;
import org.geotools.data.FeatureSource;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
import org.opengis.feature.simple.SimpleFeature;
/**
*
* #author Brahim
*/
class ImportVecteur2
{
private JMapFrame fenMap;
private MapContext mapContext;
ImportVecteur2(JMapFrame fenMap)
{
//this.mapContext = mapContext;
this.fenMap = fenMap;
}
#SuppressWarnings("static-access")
public void chercheAfficheVecteur() //throws Exception
{
try
{
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null)
{
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();
//get vertices of file
// Create a map context and add our shapefile to it
mapContext = new DefaultMapContext();
mapContext.addLayer(featureSource, null);
// Now display the map
fenMap.enableLayerTable(true);
fenMap.setMapContext(mapContext);
fenMap.setVisible(true);
}

Each time you call chercheAfficheVecteur you create a new MapContext so the previous one is thrown away and with it your previous shapefile. If you change the method to be
public void chercheAfficheVecteur() {
try {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();
//get vertices of file
// Create a map context and add our shapefile to it
if(mapContext == null){
mapContext = new DefaultMapContext();
fenMap.setMapContext(mapContext);
}
//make it look prettier
Style style = SLD.createSimpleStyle(featureSource.getSchema());
mapContext.addLayer(featureSource, style);
}
and
ImportVecteur2(JMapFrame fenMap)
{
//this.mapContext = mapContext;
this.fenMap = fenMap;
fenMap.enableLayerTable(true);
fenMap.setVisible(true);
}
It should work better.
After further testing (i.e. I actually compiled some code) - MapContext is deprecated (and has been for some time) please use MapContent.
package org.geotools.tutorial.quickstart;
import java.awt.Color;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import org.geotools.data.FeatureSource;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
public class Test {
private static final Color[] color = { Color.red, Color.blue, Color.green,
Color.MAGENTA };
private static MapContent mapContext;
private static JMapFrame fenMap;
public static void main(String args[]) throws IOException {
Test me = new Test();
me.run();
}
public void run() throws IOException {
fenMap = new JMapFrame();
mapContext = new MapContent();
fenMap.setMapContent(mapContext);
fenMap.enableToolBar(true);
fenMap.setMinimumSize(new Dimension(300, 300));
fenMap.setVisible(true);
int i = 0;
while (chercheAfficheVecteur(i)) {
i++;
i = i % color.length;
}
}
public boolean chercheAfficheVecteur(int next) throws IOException {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return false;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();
// get vertices of file
// Create a map context and add our shapefile to it
if (mapContext == null) {
}
// make it look prettier
Style style = SLD.createSimpleStyle(featureSource.getSchema(), color[next]);
Layer layer = new FeatureLayer(featureSource, style);
mapContext.addLayer(layer);
return true;
}
}

Related

How to replicate a page and all its children using replicator API?

Here is the code in which I am replicating the page
final String pagePath = blogEntryPage.getPath();
final Resource jcrContent= blogEntryPage.getContentResource();
final Node jcrNode = jcrContent.adaptTo(Node.class);
adminSession = jcrNode.getSession();
// REPLICATE THE DATE NODE
replicator.replicate(adminSession, ReplicationActionType.ACTIVATE, pagePath);
Here the problem is only the parent page is getting replicated I want to replicate the child pages also
How about just iterating over the child pages and replicate them as well:
Iterator<Page> childPages = blogEntryPage.listChildren();
while (childPages.hasNext()) {
Page childPage = childPages.next();
replicator.replicate(adminSession, ReplicationActionType.ACTIVATE, childPage.getPath());
}
You could even put this in a method and call it recursively.
Try this, (have not tested)
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.Session;
import com.day.cq.replication.Agent;
import com.day.cq.replication.AgentManager;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationContent;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationOptions;
import com.day.cq.replication.Replicator;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.RolloutManager;
import org.osgi.framework.ServiceReference;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.LoginException;
public class Activator implements BundleActivator {
/*
* (non-Javadoc)
* #see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
AgentManager agentManager = getService(context,AgentManager.class);
Replicator replicator = getService(context,Replicator.class);
ResourceResolverFactory resourceFactory = getService(context,ResourceResolverFactory.class);
ResourceResolver resourceResolver = null;
Session session = null;
String path = "/content/geometrixx-gov";
try {
resourceResolver = resourceFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
for (Map.Entry<String, Agent> e : agentManager.getAgents().entrySet()) {
if (e.getValue().getConfiguration().getTransportURI().contains("/bin/receive?sling:authRequestLogin=1")) {
Agent a = e.getValue();
try {
ReplicationAction ra = new ReplicationAction(ReplicationActionType.ACTIVATE, path);
ReplicationContent rc = a.buildContent(session, ra);
a.replicate(ra, rc, new ReplicationOptions());
System.out.println("Activator cache flush requested check queue");
} catch (ReplicationException ex) {
ex.printStackTrace();
}
}
}
} catch (LoginException e) {
e.printStackTrace();
}
}
public <T> T getService(BundleContext bc, Class<T> c)
{
ServiceReference sr = bc.getServiceReference(c.getName());
if (sr != null)
{
return (T) bc.getService(sr);
}
return null;
}
/*
* (non-Javadoc)
* #see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
// TODO add cleanup code
}
}

Only one of the two AutoCompleteTextView are showing suggestions

I have two AutoCompleteTextView controls on the same page: ACTV1 and ACTV2 and only one (ACTV1 ) is showing suggestions from my database . For each databinding action I've made a java class separetely: ACTV1.java and ACTV2.java.
But if I am adding an intent filter (MAIN, LAUNCHER) in my manifest file for ACTV2.java class and setting in run configuration ACTV2.java as Launch Action then I won't get suggestions anymore for ACTV1 control but this time I'll get suggestions for ACTV2 control.
The two java classes are identically just that differ the name of some constants/controls name.
package com.fishing2;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class CompleteBalti extends Activity {
//private CustomAutoCompleteView CompleteBalti;
private ArrayAdapter<String> adaperbalti;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_partida);
}
final TextWatcher textChecker = new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
public void onTextChanged(CharSequence s, int start, int before, int count)
{
adaperbalti.clear();
callPHP1();
}
};
private void callPHP1(){
String result = "";
InputStream is=null;
AutoCompleteTextView CompleteBalti = (AutoCompleteTextView) findViewById(R.id.nume_localitate);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("st",CompleteBalti.getText().toString()));
{
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.3.159/wtf/balti.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
result = result.substring(1);
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
try{
JSONArray jArray = new JSONArray(result);
JSONObject json_data = null;
for (int i=0;i<jArray.length(); i++)
{
json_data = jArray.getJSONObject(i);
adaperbalti.add(json_data.getString("nume_balta"));
}
} catch(Exception e1){
Log.e("log_tag", "Error converting result "+e1.toString());
}
}
}
}

Google maps API v2 Android, not drawing polygon when offline

I have a test application that I draw a Polygon using google maps API.
The problem is that, when I have no cache of any maps (new installed application) the Polygon does not draw.
Its not a problem not having the maps loaded, but I do need the Polygons drawn in my screen.
Is there a way I can do that?
Sry for my bad english
Heres the code I have:
package ngvl.testegmaps_v2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import ngvl.testegmaps_v2.VO.GeoPosicionamento;
import ngvl.testegmaps_v2.VO.Layer;
import ngvl.testegmaps_v2.VO.Secao;
import ngvl.testegmaps_v2.VO.Talhao;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class MainActivity extends FragmentActivity {
private List<Secao> secoes;
private List<Polygon> poligonos = new ArrayList<Polygon>();
private HashMap<String,Object[]> informacoes = new HashMap<String,Object[]>();
private GoogleMap map;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = fragment.getMap();
map.getUiSettings().setRotateGesturesEnabled(false);
// Setting a click event handler for the map
LatLng latLng = new LatLng(-20.9957152, -47.3241304);
// map.addMarker(new
// MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)).title("Av. Paulista").snippet("São Paulo"));
configuraPosicao(map, latLng);
Button button = (Button)findViewById(R.id.button1);
// Register the onClick listener with the implementation above
button.setOnClickListener(mCorkyListener);
}
private void configuraPosicao(GoogleMap map, LatLng latLng) {
/*
* 3D map.moveCamera( CameraUpdateFactory.newLatLngZoom(latLng, 15));
* map.animateCamera( CameraUpdateFactory.zoomTo(10), 2000, null);
*
* CameraPosition cameraPosition = new CameraPosition.Builder()
* .target(latLng) .zoom(17) .bearing(90) .tilt(45) .build();
*
* map.animateCamera( CameraUpdateFactory.newCameraPosition(
* cameraPosition));
*/
map.setMapType(GoogleMap.MAP_TYPE_NONE);
// map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.0f));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
try {
String json = readFileAsString("geo.json");
Gson gson = new Gson();
this.secoes = gson.fromJson(json, new TypeToken<List<Secao>>() {
}.getType());
json = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
escrevePoligons(map);
}
private String readFileAsString(String fileName) throws IOException {
InputStream is = getAssets().open(fileName);
if (is != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
} finally {
is.close();
}
return sb.toString();
} else {
return "";
}
}
private void escrevePoligons(GoogleMap map) {
float stroke = (float) 1.5;
for (Secao secao : secoes) {
for (Talhao talhao : secao.getTalhoes()) {
for (Layer layer : talhao.getLayers()) {
// PolygonOptions rectOptions = new PolygonOptions();
List<LatLng> latlngs = new ArrayList<LatLng>();
for (GeoPosicionamento geoPosicionamento : layer.getGeoPosicionamentos()) {
latlngs.add(new LatLng(geoPosicionamento.getLatitude()
.setScale(7, BigDecimal.ROUND_HALF_EVEN)
.doubleValue(), geoPosicionamento
.getLongitude()
.setScale(7, BigDecimal.ROUND_HALF_EVEN)
.doubleValue()));
}
int color = 0x1F00FF00;
int color2 = 0x5F000000;
PolygonOptions polygonOptions = new PolygonOptions()
.fillColor(color).addAll(latlngs)
.strokeColor(color2).strokeWidth(stroke);
Polygon p = map.addPolygon(polygonOptions);
poligonos.add(p);
informacoes.put( p.getId(), new Object[]{ secao, talhao , layer } );
//System.out.println(polygonOptions.getPoints());
polygonOptions = null;
latlngs = null;
}
}
}
this.secoes = null;
// String mUrl =
// "https://khms0.google.com.br/kh/v=124&src=app&z={z}&x={x}&y={y}";
// MyUrlTileProvider mTileProvider = new MyUrlTileProvider(256, 256,
// mUrl);
// mTileProvider.tilesRange();
// map.addTileOverlay(new
// TileOverlayOptions().tileProvider(mTileProvider).zIndex(-1f));
//String mUrl = "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png";
//MyUrlTileProvider mTileProvider = new MyUrlTileProvider(256, 256, mUrl);
//map.addTileOverlay(new TileOverlayOptions().tileProvider(mTileProvider).zIndex(-1f));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-20.9957152, -47.3241304), 14));
// TileProvider tileProvider = TileProviderFactory.getTileProvider();
// map.addTileOverlay(new
// TileOverlayOptions().tileProvider(tileProvider));
// map.moveCamera(CameraUpdateFactory.newLatLngZoom(new
// LatLng(-20.9957152, -47.3241304), 15));
map.setOnMapClickListener(new OnMapClickListener()
{
public void onMapClick(LatLng point)
{
Polygon p = isPointInPolygon(point);
if( p != null){
p.setFillColor(getRandomColor());
Object[] clicado = informacoes.get( p.getId() );
Secao secao_clicada = (Secao) clicado[0];
Talhao talhao_clicada = (Talhao) clicado[1];
Layer layer_clicada = (Layer) clicado[2];
//System.out.println(secao_clicada);
//System.out.println(talhao_clicada);
//System.out.println(layer_clicada);
//System.out.println("=======================");
StringBuilder texto = new StringBuilder();
texto.append("Seção: " + secao_clicada.getDesc() + "\n");
texto.append("Talhão: " + talhao_clicada.getTalhao() + "\n");
texto.append("Variedade: " + talhao_clicada.getVariedade() + " - " + talhao_clicada.getDescVariedade() + "\n");
texto.append("Layer: " + layer_clicada.getSequencia() + "\n");
//Toast.makeText(MainActivity.this, texto , Toast.LENGTH_LONG).show();
addMarker(point,texto);
}//else
//Toast.makeText(MainActivity.this,"Clicou fora da Área de um Poligono", Toast.LENGTH_LONG).show();
}
});
}
public void addMarker(LatLng point, StringBuilder texto) {
/*map.addMarker(new MarkerOptions().position(point).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.title("Caracteristicas: ")
.snippet( texto );
*/
Toast.makeText(MainActivity.this, texto , Toast.LENGTH_LONG).show();
}
private Polygon isPointInPolygon(LatLng tap) {
for( Polygon p : poligonos){
int intersectCount = 0;
List<LatLng> vertices = p.getPoints();
for(int j=0; j<vertices.size()-1; j++) {
if( rayCastIntersect(tap, vertices.get(j), vertices.get(j+1)) ) {
intersectCount++;
}
}
if(((intersectCount % 2) == 1)){
return p;
}
}
return null;// odd = inside, even = outside;
}
private boolean rayCastIntersect(LatLng tap, LatLng vertA, LatLng vertB) {
double aY = vertA.latitude;
double bY = vertB.latitude;
double aX = vertA.longitude;
double bX = vertB.longitude;
double pY = tap.latitude;
double pX = tap.longitude;
if ( (aY>pY && bY>pY) || (aY<pY && bY<pY) || (aX<pX && bX<pX) ) {
return false; // a and b can't both be above or below pt.y, and a or b must be east of pt.x
}
double m = (aY-bY) / (aX-bX); // Rise over run
double bee = (-aX) * m + aY; // y = mx + b
double x = (pY - bee) / m; // algebra is neat!
return x > pX;
}
private OnClickListener mCorkyListener = new OnClickListener() {
public void onClick(View v) {
// do something when the button is clicked
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-20.9957152, -47.3241304), 14));
}
};
public int getRandomColor() {
int color;
Random rnd = new Random();
color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),
rnd.nextInt(256));
return color;
}
}
Setting map type to MAP_TYPE_NONE like example above does not solve the problem
I will this as marked solved by using Maps Forge Open Source API
If someone did with Google Maps Api please share and I would change the answer.
The answer I found is that its impossible to render or access anything without rendering the map first (online or via cache)
This is actually a bug of GoogleMaps Api v2 for Android.
It is referenced here:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=5017
Star it if you want to accelerate the bug fix!

eclipse rcp : help to create a customized StyledText widget

I want a customized StyledText widget which can accept a keyword list,then highlight these keywords!
I found it's very hard to implement it by myself.
God damned! after spent hours searching the web, I finally found some sample code from the book The Definitive Guide to SWT and JFace, it's quite simple :
Main class :
package amarsoft.rcp.base.widgets.test;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import amarsoft.rcp.base.widgets.SQLSegmentEditor;
public class PageDemo extends ApplicationWindow {
public PageDemo(Shell parentShell) {
super(parentShell);
final Composite topComp = new Composite(parentShell, SWT.BORDER);
FillLayout fl = new FillLayout();
fl.marginWidth = 100;
topComp.setLayout(fl);
new SQLSegmentEditor(topComp);
}
/**
* #param args
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new PageDemo(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
package amarsoft.rcp.base.widgets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
/**
* SQL语句/SQL语句片段编辑器,除了内容编辑之外,提供一个额外的功能——常用SQL语句关键字高亮显示。
* #author ggfan#amarsoft
*
*/
public class SQLSegmentEditor extends Composite{
private StyledText st;
public SQLSegmentEditor(Composite parent) {
super(parent, SWT.NONE);
this.setLayout(new FillLayout());
st = new StyledText(this, SWT.WRAP);
st.addLineStyleListener(new SQLSegmentLineStyleListener());
}
}
package amarsoft.rcp.base.widgets;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.LineStyleEvent;
import org.eclipse.swt.custom.LineStyleListener;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;
public class SQLSegmentLineStyleListener implements LineStyleListener {
private static final Color KEYWORD_COLOR = SWTResourceManager
.getColor(SWT.COLOR_BLUE);
private List<String> keywords = new ArrayList<String>();
public SQLSegmentLineStyleListener() {
super();
keywords.add("select");
keywords.add("from");
keywords.add("where");
}
#Override
public void lineGetStyle(LineStyleEvent event) {
List<StyleRange> styles = new ArrayList<StyleRange>();
int start = 0;
int length = event.lineText.length();
System.out.println("current line length:" + event.lineText.length());
while (start < length) {
System.out.println("while lopp");
if (Character.isLetter(event.lineText.charAt(start))) {
StringBuffer buf = new StringBuffer();
int i = start;
for (; i < length
&& Character.isLetter(event.lineText.charAt(i)); i++) {
buf.append(event.lineText.charAt(i));
}
if (keywords.contains(buf.toString())) {
styles.add(new StyleRange(event.lineOffset + start, i - start, KEYWORD_COLOR, null, SWT.BOLD));
}
start = i;
}
else{
start ++;
}
}
event.styles = (StyleRange[]) styles.toArray(new StyleRange[0]);
}
}

Identify a class call by another class from another package in eclipse galileo

Here I have a set of resource bundles( a .properties java class) that been called by many classes in a eclipse project file. I just wondering is it eclipse got any shortcut key or function to identify automatically the class(resource bundles) from another package that have been call from another class in different package.
The line that call another package resource bundle is
private ResourceBundle useCaseResourceBundle;
The full code is
package my.com.infopro.icba10.accounting.ui.maintainproductgl;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import my.com.infopro.icba10.accounting.delegate.AccountingDelegate;
import my.com.infopro.icba10.accounting.domain.GLField;
import my.com.infopro.icba10.accounting.domain.GLProduct;
import my.com.infopro.icba10.accounting.domain.GLProductDetail;
import my.com.infopro.icba10.admin.vlh.lov.CurrencyLov;
import my.com.infopro.icba10.kernel.uiframework.annotation.ValidationConfigFile;
import my.com.infopro.icba10.kernel.uiframework.binding.PresentationModelFactory;
import my.com.infopro.icba10.kernel.uiframework.component.CustomizedCombobox;
import my.com.infopro.icba10.kernel.uiframework.form.IconFactory;
import my.com.infopro.icba10.kernel.uiframework.form.IconType;
import my.com.infopro.icba10.kernel.uiframework.form.builders.CustomizedPanelBuilder;
import my.com.infopro.icba10.kernel.uiframework.form.builders.PanelBuilderFactory;
import my.com.infopro.icba10.kernel.uiframework.session.UserSessionProfileStore;
import my.com.infopro.icba10.kernel.uiframework.util.LayoutType;
import my.com.infopro.icba10.kernel.uiframework.validation.controls.CustomizedForm;
import my.com.infopro.icba10.kernel.util.configuration.CustomConfig;
import my.com.infopro.icba10.kernel.util.db.DataAccessMode;
import my.com.infopro.icba10.kernel.valuelisthandler.lov.Lov;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.log4j.Logger;
import com.jgoodies.binding.beans.Model;
import com.jgoodies.binding.list.SelectionInList;
/* =================================================================================================
* HISTORY
* -------------------------------------------------------------------------------------------------
* Date Author Remarks
* -------------------------------------------------------------------------------------------------
* 2010/08/22 hmho class created
* =================================================================================================
*/
#ValidationConfigFile("my.com.infopro.icba10.cbs.core.ui.vconfig.maintainproductglset-vconfig")
public class MaintainProductGLCopyPopUp extends CustomizedForm implements ActionListener {
private Logger logger= Logger.getLogger(MaintainProductGLCopyPopUp.class);
private CustomConfig config = CustomConfig.getInstance();
private ResourceBundle useCaseResourceBundle;
private UserSessionProfileStore userSessionProfileStore= UserSessionProfileStore.getInstance();
private CustomizedCombobox currencyComboBox;
private CustomizedCombobox glSetCodeComboBox;
private JButton okButton = new JButton();
private GLProduct fromGLProduct;
private GLProduct toGLProduct;
private MaintainProductGLMaintForm form;
private String glSetCode;
private String glSetDescription;
private Map<String,List<GLProductDetail>> glDetailMap = new HashMap<String,List<GLProductDetail>>();
private AccountingDelegate accountingDelegate;
public MaintainProductGLCopyPopUp(MaintainProductGLMaintForm form,ResourceBundle useCaseResourceBundle,
GLProduct glProduct,Map<String,List<GLProductDetail>> glDetailMap) {
super();
this.form = form;
this.useCaseResourceBundle = useCaseResourceBundle;
this.toGLProduct = glProduct;
this.glDetailMap = glDetailMap;
}
#Override
public boolean isFormValidatable() {
return true;
}
public void init() {
initPanels();
initBindingAndValidation();
initCode();
initEventHandling();
}
private void initPanels() {
setLayout(new BorderLayout());
add(buildCopyPanel(), BorderLayout.CENTER);
}
private void initBindingAndValidation() {
fromGLProduct = new GLProduct();
presentationModelDelegate = PresentationModelFactory.getPresentationModel(this,
getFormBeans(), new String[]{GLProduct.class.getSimpleName()});
fromGLProduct.setBankingConcept(toGLProduct.getBankingConcept());
fromGLProduct.setModuleCode(toGLProduct.getModuleCode());
glSetCode = toGLProduct.getGlSetCode();
glSetDescription = toGLProduct.getGlSetDescription();
logger.debug("init in copy " );
logger.debug("toGLProduct " + toGLProduct.getGlSetCode());
logger.debug("toGLProduct " + toGLProduct.getGlSetDescription());
}
private void initCode() {
accountingDelegate = new AccountingDelegate();
Lov currencyLov = new CurrencyLov();
presentationModelDelegate.bindComboBoxWithValues(currencyComboBox, currencyLov);
}
private void initEventHandling() {
currencyComboBox.addActionListener(this);
okButton.addActionListener(this);
}
private JPanel buildCopyPanel() {
CustomizedPanelBuilder builder = PanelBuilderFactory.createPanelBuilder(LayoutType.SINGLE_CENTERED);
JPanel popupPanel = new JPanel();
popupPanel.setLayout(new BorderLayout());
popupPanel.setBorder(new TitledBorder (useCaseResourceBundle.getString("copyPanel")));
JPanel copyPanel = new JPanel();
currencyComboBox= new CustomizedCombobox();
glSetCodeComboBox= new CustomizedCombobox();
builder.addComponentGroup(useCaseResourceBundle.getString("currency"), "GLProduct.currencyCode", currencyComboBox);
builder.addComponentGroup(useCaseResourceBundle.getString("glSetCode"), "GLProduct.glSetCode", glSetCodeComboBox);
copyPanel = builder.getStandardPanel();
popupPanel.add(copyPanel, BorderLayout.CENTER);
popupPanel.add(buildButtonPanel(), BorderLayout.SOUTH);
return popupPanel;
}
private JPanel buildButtonPanel() {
JPanel innerButtonPanel = new JPanel();
okButton = new JButton();
okButton.setText(useCaseResourceBundle.getString("okButton"));
okButton.setIcon(IconFactory.createIcon(IconType.OK));
innerButtonPanel.add(okButton);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BorderLayout());
buttonPanel.add(innerButtonPanel,BorderLayout.EAST);
return buttonPanel;
}
public void registerComponentNames() {
}
#Override
protected void createFormBeans() {
fromGLProduct = new GLProduct();
}
#Override
public Model[] getFormBeans() {
return new Model[]{fromGLProduct};
}
#Override
protected void setFormBeans(final Model[] updatedBean) {
fromGLProduct = (GLProduct) updatedBean[0];
}
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
final Object sourceObject = event.getSource();
if (sourceObject.equals(okButton)) {
if(null!=fromGLProduct.getCurrencyCode() && null!=fromGLProduct.getGlSetCode()){
setCopyData();
searchFrame.dispose();
}
}
if (sourceObject.equals(currencyComboBox)) {
List<GLProduct> glSetCodeList = accountingDelegate.findAvailableGlProduct(fromGLProduct);
if(glSetCodeList.size()<=0) {
glSetCodeList.add(new GLProduct());
}
presentationModelDelegate.bindComboBoxWithValues(glSetCodeComboBox, glSetCodeList, "glSetCode",true);
glSetCodeComboBox.createListCellRendererHandler();
}
}
private void setCopyData() {
userSessionProfileStore.setApplicationQueryCall();
logger.debug("copying " );
logger.debug("toGLProduct1 " + toGLProduct.getGlSetCode());
logger.debug("toGLProduct1 " + toGLProduct.getGlSetDescription());
GLProduct copyProduct = accountingDelegate.copyGLProducts(fromGLProduct, toGLProduct);
logger.debug("fromGLProduct " + fromGLProduct.getGlSetCode());
logger.debug("fromGLProduct " + fromGLProduct.getGlSetDescription());
logger.debug("copyProduct " + copyProduct.getGlSetCode());
logger.debug("copyProduct " + copyProduct.getGlSetDescription());
GLField glField = new GLField();
if(null!=copyProduct){
// copyProduct.setGlSetCode(glSetCode);
// copyProduct.setGlSetDescription(glSetDescription);
// Model[] models = new Model[] {copyProduct, glField};
// form.getPresentationModelDelegate().reinitBean(copyProduct);
if(copyProduct.getGLProductDetailList().size()>0){
form.getGlSetTableManagerModel().clearItems();
BeanComparator comparator = new BeanComparator("glField");
Collections.sort(copyProduct.getGLProductDetailList(), comparator);
form.setGlSetTableManagerModel(copyProduct.getGLProductDetailList());
logger.debug("Copy List Size 2 " + copyProduct.getGLProductDetailList().size());
}
SelectionInList selectionInList = form.getGlSetTableManagerModel()
.getItemSelectionsList();
List<GLProductDetail> glProductDetails = new ArrayList<GLProductDetail>();
glProductDetails.clear();
for(int i=0;i<selectionInList.getSize();i++){
GLProductDetail glProductDetail = (GLProductDetail) selectionInList
.getElementAt(i);
glProductDetail.setAction(DataAccessMode.INSERT);
glProductDetails.add(glProductDetail);
}
glDetailMap.clear();
glDetailMap.put(useCaseResourceBundle.getString("defaultCategoryCode"),glProductDetails);
form.setGlProductDetailMap(glDetailMap);
for(String key :form.getGlProductDetailMap().keySet()){
List<GLProductDetail>gls = form.getGlProductDetailMap().get(key);
for(GLProductDetail gl:gls){
logger.debug("Map " +gls.size());
if(null!=gl.getGlCode()){
logger.debug("Map " + gl.getGlField());
logger.debug("Map " + gl.getGlCode());
}
}
}
}
}
}
Is there any way so that i can use any key or function in eclipse to open the java file refer by the useCaseResourceBundle from this class. In some case its easier because the class already declared it clearly.
Example
private ResourceBundle resourceBundle = config.getPropResourceBundle("KERN_BUNDLE_UIFRAMEWORK");
Ctrl+Shift+G
or
Menu -> Search -> References -> ...
Search for references to the selected
element in the workspace / Project / Hierarchy / Working Set...