
gdt.jgui.base.JCategoryPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JEntigrator Show documentation
Show all versions of JEntigrator Show documentation
The entigrator application
The newest version!
package gdt.jgui.base;
/*
* Copyright 2016 Alexander Imas
* This file is part of JEntigrator.
JEntigrator is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JEntigrator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JEntigrator. If not, see .
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Properties;
import java.util.logging.Logger;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import org.apache.commons.codec.binary.Base64;
import gdt.data.entity.BaseHandler;
import gdt.data.entity.EntityHandler;
import gdt.data.entity.FacetHandler;
import gdt.data.entity.facet.ExtensionHandler;
import gdt.data.grain.Core;
import gdt.data.grain.Locator;
import gdt.data.grain.Sack;
import gdt.data.store.Entigrator;
import gdt.jgui.console.JConsoleHandler;
import gdt.jgui.console.JContext;
import gdt.jgui.console.JFacetRenderer;
import gdt.jgui.console.JItemPanel;
import gdt.jgui.console.JItemsListPanel;
import gdt.jgui.console.JMainConsole;
import gdt.jgui.console.ReloadDialog;
import gdt.jgui.console.WContext;
import gdt.jgui.console.WUtils;
import gdt.jgui.entity.JArchivePanel;
import gdt.jgui.entity.JEntitiesPanel;
import gdt.jgui.entity.JEntityFacetPanel;
import gdt.jgui.entity.JReferenceEntry;
/**
* This context displays of all entities belonging to the category.
* @author Alexander Imas
* @version 1.0
* @since 2016-03-11
*/
public class JCategoryPanel extends JItemsListPanel implements WContext{
private static final long serialVersionUID = 1L;
public static final String RENDERER = "renderer";
public static final String LIST_MEMBERS = "list members";
public static final String CATEGORY_TITLE = "category title";
String entihome$;
String renderer$;
String entityType$;
String categoryTitle$;
String iconClass$;
String iconFile$;
JMenu menu;
JMenuItem deleteItem;
JMenuItem copyItem;
private JMenuItem[] mia;
static boolean debug=false;
boolean ignoreOutdate=false;
boolean refresh=false;
/**
* Default constructor
*
*/
public JCategoryPanel() {
super();
}
/**
* Get context locator.
* @return the locator.
*/
@Override
public String getLocator() {
Properties locator=new Properties();
locator.setProperty(Locator.LOCATOR_TYPE, JContext.CONTEXT_TYPE);
locator.setProperty(JContext.CONTEXT_TYPE,getType());
locator.setProperty(JItemsListPanel.POSITION,String.valueOf(getPosition()));
if(entihome$!=null)
locator.setProperty(Entigrator.ENTIHOME,entihome$);
if(renderer$!=null){
locator.setProperty(RENDERER,renderer$);
}
if(entityType$!=null){
locator.setProperty(EntityHandler.ENTITY_TYPE,entityType$);
if(entihome$!=null){
Entigrator entigrator=console.getEntigrator(entihome$);
locator.setProperty(Locator.LOCATOR_ICON_CONTAINER,Locator.LOCATOR_ICON_CONTAINER_CLASS);
if(debug)
System.out.println("JCategoryPanel:getLocator:1");
FacetHandler fh=BaseHandler.getHandler(entigrator, entityType$);
if(debug)
if(fh!=null)
System.out.println("JCategoryPanel:getLocator:fh="+fh.getClass().getName());
else
System.out.println("JCategoryPanel:getLocator:cannot get handler for entity type=="+entityType$);
JFacetRenderer fr=JConsoleHandler.getFacetRenderer(entigrator, fh);
if(debug)
if(fr!=null)
System.out.println("JCategoryPanel:getLocator:fr="+fr.getClass().getName());
else
System.out.println("JCategoryPanel:getLocator:cannot get renderer for hanler=="+fh.getClass().getName());
locator.setProperty(Locator.LOCATOR_ICON_CLASS,fr.getClass().getName());
locator.setProperty(Locator.LOCATOR_ICON_FILE,fr.getFacetIcon());
categoryTitle$=fr.getCategoryTitle();
}
}
if(categoryTitle$!=null)
locator.setProperty(Locator.LOCATOR_TITLE, categoryTitle$);
else
locator.setProperty(Locator.LOCATOR_TITLE, getTitle());
locator.setProperty(BaseHandler.HANDLER_SCOPE,JConsoleHandler.CONSOLE_SCOPE);
locator.setProperty(BaseHandler.HANDLER_CLASS,getClass().getName());
locator.setProperty(Locator.LOCATOR_ICON_CONTAINER,Locator.LOCATOR_ICON_CONTAINER_CLASS);
if(iconFile$!=null)
locator.setProperty(Locator.LOCATOR_ICON_FILE,iconFile$);
if(debug)
System.out.println("JCategoryPanel:getLocator finish:locator="+locator.toString());
return Locator.toString(locator);
}
/**
* Create the context.
* @param console the main application console
* @param locator$ the locator string.
* @return the context.
*/
@Override
public JContext instantiate(JMainConsole console, String locator$) {
if(debug)
System.out.println("JCategoryPanel:instantiate:locator="+locator$);
clearItems();
try{
this.console=console;
Properties locator=Locator.toProperties(locator$);
entihome$=locator.getProperty(Entigrator.ENTIHOME);
Entigrator entigrator=console.getEntigrator(entihome$);
renderer$=locator.getProperty(RENDERER);
String extension$=locator.getProperty(ExtensionHandler.EXTENSION);
JFacetRenderer facetRenderer=null;
if(extension$==null)
facetRenderer=(JFacetRenderer)JConsoleHandler.getHandlerInstance(entigrator, renderer$);
else
facetRenderer=(JFacetRenderer)JConsoleHandler.getHandlerInstance(entigrator,renderer$, extension$);
if(facetRenderer==null){
//if(debug)
System.out.println("JCategoryPanel:instantiate:ERROR:cannot load renderer="+renderer$);
return null;
}
String frLocator$=facetRenderer.getLocator();
frLocator$=Locator.append(frLocator$, Entigrator.ENTIHOME, entihome$);
frLocator$=Locator.append(frLocator$, JFacetRenderer.ONLY_ITEM,Locator.LOCATOR_TRUE);
facetRenderer.instantiate(console,frLocator$ );
entityType$=facetRenderer.getEntityType();
categoryTitle$=facetRenderer.getCategoryTitle();
if(debug)
System.out.println("JCategoryPanel:instantiate:entity type="+entityType$+" category="+categoryTitle$);
this.locator$=getLocator();
String onlyItem$=locator.getProperty(JFacetRenderer.ONLY_ITEM);
if(debug)
System.out.println("JCategoryPanel:instantiate:entity type="+entityType$+" category="+categoryTitle$+" only item="+onlyItem$);
if(Locator.LOCATOR_TRUE.equals(onlyItem$))
return this;
JItemPanel[] ipa=listCategoryMembers(console, this.locator$);
if(debug)
System.out.println("JCategoryPanel:instantiate:1");
if(ipa!=null){
putItems(ipa);
try{
pos=Integer.parseInt(locator.getProperty(POSITION));
select(pos);
}catch(Exception e){
Logger.getLogger(getClass().getName()).info(e.toString());
}
}
}catch(Exception e){
Logger.getLogger(getClass().getName()).info(e.toString());
}
return this;
}
/**
* Get context menu.
* @return the context menu.
*/
@Override
public JMenu getContextMenu() {
menu=super.getContextMenu();
mia=null;
int cnt=menu.getItemCount();
if(cnt>0){
mia=new JMenuItem[cnt];
for(int i=0;isl=new ArrayList();
for(JItemPanel ip:ipa)
if(ip.isChecked())
sl.add(ip.getLocator());
String[]sa=sl.toArray(new String[0]);
console.clipboard.clear();
for(String aSa:sa)
console.clipboard.putString(aSa);
}
} );
menu.add(copyItem);
JMenuItem archiveItem = new JMenuItem("Archive");
archiveItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JItemPanel[] ipa=JCategoryPanel.this.getItems();
Entigrator entigrator=console.getEntigrator(entihome$);
Properties locator;
ArrayListsl=new ArrayList();
String entityKey$;
for(JItemPanel ip:ipa){
if(ip.isChecked()){
locator=Locator.toProperties(ip.getLocator());
entityKey$=locator.getProperty(EntityHandler.ENTITY_KEY);
sl.add(entityKey$);
}
}
String[] sa=sl.toArray(new String[0]);
String[] ea=JReferenceEntry.getCoalition(console, entigrator, sa);
JArchivePanel archivePanel=new JArchivePanel();
String apLocator$=archivePanel.getLocator();
apLocator$=Locator.append(apLocator$,Entigrator.ENTIHOME,entihome$);
apLocator$=Locator.append(apLocator$, EntityHandler.ENTITY_LIST,Locator.toString(ea));
apLocator$=Locator.append(apLocator$,Locator.LOCATOR_ICON_CONTAINER, Locator.LOCATOR_ICON_CONTAINER_CLASS);
apLocator$=Locator.append(apLocator$,Locator.LOCATOR_ICON_CLASS,getClass().getName());
apLocator$=Locator.append(apLocator$,Locator.LOCATOR_ICON_FILE, "category.png");
JConsoleHandler.execute(console, apLocator$);
}
} );
menu.add(archiveItem);
}
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
return menu;
}
private static JItemPanel[] listCategoryMembers(JMainConsole console,String locator$){
try{
if(debug)
System.out.println("JCategoryPanel:listCategoryMembers:locator="+locator$);
Properties locator=Locator.toProperties(locator$);
String entihome$=locator.getProperty(Entigrator.ENTIHOME);
String entityType$=locator.getProperty(EntityHandler.ENTITY_TYPE);
if(entityType$==null||"null".equals(entityType$))
return null;
Entigrator entigrator=console.getEntigrator(entihome$);
ArrayList sl=new ArrayList();
String[] sa=entigrator.indx_listEntities("entity",entityType$);
if(sa!=null)
for(String s:sa)
sl.add(s);
sa=entigrator.indx_listEntitiesAtPropertyName(entityType$);
if(sa!=null)
for(String s:sa)
if(!sl.contains(s))
sl.add(s);
sa=sl.toArray(new String[0]);
if(sa.length<1)
return null;
ArrayListipl=new ArrayList();
JItemPanel itemPanel;
String emLocator$;
Core [] ca=entigrator.indx_getMarks(sa);
if(debug)
System.out.println("JCategoryPanel:listCategoryMembers:ca="+ca.length);
JEntityFacetPanel em;
Properties emLocator;
String iconFile$;
FacetHandler[] fha=BaseHandler.listAllHandlers(entigrator);
Hashtablefrtab=new Hashtable();
JFacetRenderer facetRenderer;
for(Core c:ca){
try{
if(debug)
System.out.println("JCategoryPanel:listCategoryMembers:c type="+c.type+" name="+c.name+" value="+c.value);
em=new JEntityFacetPanel();
emLocator$=em.getLocator();
emLocator=Locator.toProperties(emLocator$);
emLocator.setProperty(Entigrator.ENTIHOME , entihome$);
emLocator.setProperty(EntityHandler.ENTITY_KEY ,c.name);
emLocator.setProperty(Locator.LOCATOR_CHECKABLE, Locator.LOCATOR_TRUE);
emLocator.setProperty(Locator.LOCATOR_TITLE, c.value);
emLocator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE);
//System.out.println("JCategoryPanel:listCategoryMembers:1");
iconFile$=entigrator.ent_getIconAtKey(c.name);
if(iconFile$!=null&&!"sack.gif".equals(iconFile$)&&!"null".equals(iconFile$)){
emLocator.setProperty(Locator.LOCATOR_ICON_CONTAINER,Locator.LOCATOR_ICON_CONTAINER_ICONS);
emLocator.setProperty(Locator.LOCATOR_ICON_FILE,iconFile$);
}else{
String type$=entigrator.getEntityType(c.name);
boolean found=false;
//System.out.println("JCategoryPanel:listCategoryMembers:2");
for(FacetHandler fh:fha){
//System.out.println("JCategoryPanel:listCategoryMembers:3:fh="+fh.getTitle()+" type="+type$);
if(type$==null)
continue;
if(type$.equals(fh.getType())){
facetRenderer=frtab.get(fh);
if(facetRenderer==null){
facetRenderer= JConsoleHandler.getFacetRenderer(entigrator, fh);
if(facetRenderer==null)
continue;
frtab.put(fh, facetRenderer);
}
emLocator.setProperty(Locator.LOCATOR_ICON_CONTAINER,Locator.LOCATOR_ICON_CONTAINER_CLASS);
emLocator.setProperty(Locator.LOCATOR_ICON_CLASS,facetRenderer.getClass().getName());
emLocator.setProperty(Locator.LOCATOR_ICON_FILE,facetRenderer.getFacetIcon());
found=true;
break;
}
}
if(!found){
emLocator.setProperty(Locator.LOCATOR_ICON_CONTAINER,Locator.LOCATOR_ICON_CONTAINER_CLASS);
emLocator.setProperty(Locator.LOCATOR_ICON_CLASS,JEntitiesPanel.class.getName());
emLocator.setProperty(Locator.LOCATOR_ICON_FILE,"facet.png");
}
}
itemPanel=new JItemPanel(console,Locator.toString(emLocator));
ipl.add(itemPanel);
}catch(Exception ee){
Logger.getLogger(JCategoryPanel.class.getName()).info(ee.toString());
}
}
entigrator.clearCache();
Collections.sort(ipl,new ItemPanelComparator());
return ipl.toArray(new JItemPanel[0]);
}catch(Exception e) {
Logger.getLogger(JEntitiesPanel.class.getName()).severe(e.toString());
return null;
}
}
private static void listWebItems(Entigrator entigrator,String webHome$,String locator$,StringBuffer sb){
try{
Properties locator=Locator.toProperties(locator$);
String entityType$=locator.getProperty(EntityHandler.ENTITY_TYPE);
String pageBeginCount$=locator.getProperty(JEntitiesPanel.PAGE_BEGIN_COUNT);
if(entityType$==null||"null".equals(entityType$))
return ;
ArrayList sl=new ArrayList();
String[] sa=entigrator.indx_listEntities("entity",entityType$);
if(sa!=null)
for(String s:sa)
sl.add(s);
sa=entigrator.indx_listEntitiesAtPropertyName(entityType$);
if(sa!=null)
for(String s:sa)
if(!sl.contains(s))
sl.add(s);
sa=sl.toArray(new String[0]);
if(sa!=null){
//
ArrayListpage=new ArrayList();
String[] ia;
sa=entigrator.indx_sortKeysAtlabel(sa);
if(debug)
System.out.println("JCategoryPanel:listWebitems:sorted keys="+sa.length);
int pageBegin=0;
if(pageBeginCount$!=null)
try{ pageBegin=Integer.parseInt(pageBeginCount$);}catch(Exception e){}
int pageEnd=pageBegin+JEntitiesPanel.PAGE_SIZE;
// page.clear();
if(pageEnd");
locator$=Locator.append(locator$, JEntitiesPanel.PAGE_BEGIN_COUNT, String.valueOf(pageEnd));
String moreItem$="Next page ";
sb.append(moreItem$);
}else{
for(int i=0;i");
}
}
}catch(Exception e) {
Logger.getLogger(JCategoryPanel.class.getName()).severe(e.toString());
}
}
private static String getItem(String icon$, String url$, String title$,String foiLocator$){
if(debug)
System.out.println("JCategoryPanel:getItem: locator="+foiLocator$);
String iconTerm$="
";
foiLocator$=Locator.append(foiLocator$,WContext.WEB_HOME, url$);
foiLocator$=Locator.append(foiLocator$,WContext.WEB_REQUESTER, JCategoryPanel.class.getName());
return iconTerm$+""+" "+title$+"";
}
/**
* Get context title.
* @return the title string.
*/
@Override
public String getTitle() {
if(categoryTitle$!=null)
return categoryTitle$;
else
return "Category panel";
}
/**
* Get context subtitle.
* @return the subtitle string.
*/
@Override
public String getSubtitle() {
return entihome$;
}
/**
* Get context type.
* @return the type string.
*/
@Override
public String getType() {
return "Category panel";
}
/**
* Complete the context after
* remove it from the main console.
*/
@Override
public void close() {
console.getTrack().pop();
console.getTrack().push(getLocator());
}
@Override
public void activate() {
if(debug)
System.out.println("JCategoryPanel:activate:begin");
if(ignoreOutdate){
ignoreOutdate=false;
return;
}
Entigrator entigrator=console.getEntigrator(entihome$);
if(!entigrator.store_outdated()){
if(debug)
System.out.println("JCategoryPanel:activate:up to date");
if(refresh){
if(debug)
System.out.println("JCategoryPanel:refresh");
refresh=false;
JConsoleHandler.execute(console,getLocator());
}
return;
}
int n=new ReloadDialog(this).show();
if(2==n){
//cancel
ignoreOutdate=true;
return;
}
if(1==n){
//replace
entigrator.store_replace();
}
if(0==n){
//reload
entigrator.store_reload();
JConsoleHandler.execute(console, getLocator());
}
}
@Override
public String getWebView(Entigrator entigrator, String locator$) {
try{
if(debug)
System.out.println("JCategoryPanel:BEGIN:locator="+locator$);
Properties locator=Locator.toProperties(locator$);
String webHome$=locator.getProperty(WContext.WEB_HOME);
String webRequester$=locator.getProperty(WContext.WEB_REQUESTER);
String category$=locator.getProperty(CATEGORY_TITLE);
if(debug)
System.out.println("JEntityCategoryPanel:web home="+webHome$+ " web requester="+webRequester$);
StringBuffer sb=new StringBuffer();
sb.append("");
sb.append("");
sb.append("");
sb.append(WUtils.getMenuBarScript());
sb.append(WUtils.getMenuBarStyle());
sb.append("");
sb.append("");
sb.append(" ");
sb.append("Base: ");
sb.append(entigrator.getBaseName());
sb.append(" ");
sb.append("Category: ");
sb.append(category$);
sb.append(" ");
sb.append("
");
listWebItems(entigrator,webHome$,locator$,sb);
// if(sa!=null)
// for(String s:sa)
// sb.append(s+"
");
sb.append("");
sb.append("");
sb.append("");
return sb.toString();
}catch(Exception e){
Logger.getLogger(JBasesPanel.class.getName()).severe(e.toString());
}
return null;
}
@Override
public String getWebConsole(Entigrator entigrator, String locator$) {
return null;
}
public static String getCategoryIcon(Entigrator entigrator,String entityType$){
try{
FacetHandler[] fha=BaseHandler.listAllHandlers(entigrator);
JFacetRenderer facetRenderer;
for(FacetHandler fh:fha){
facetRenderer=JConsoleHandler.getFacetRenderer(entigrator, fh);
if(facetRenderer!=null&&entityType$.equals(facetRenderer.getEntityType()))
return facetRenderer.getCategoryIcon(entigrator);
}
}catch(Exception e){
Logger.getLogger(JAllCategoriesPanel.class.getName()).severe(e.toString());
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy