Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package xdev.ui;
/*-
* #%L
* XDEV Application Framework
* %%
* Copyright (C) 2003 - 2020 XDEV Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.event.ContainerEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.JMenu;
import xdev.Application;
import xdev.db.DBException;
import xdev.db.QueryInfo;
import xdev.db.locking.LockNotificationStrategy;
import xdev.db.locking.LockTimeMonitor;
import xdev.db.locking.PessimisticLockStrategy;
import xdev.db.locking.RowAlreadyLockedException;
import xdev.db.sql.Condition;
import xdev.db.sql.SELECT;
import xdev.event.ApplicationExitListener;
import xdev.lang.cmd.Query;
import xdev.ui.FormularComponent.ValueChangeListener;
import xdev.ui.event.ContainerHierarchyListener;
import xdev.ui.event.FirstShowAdapter;
import xdev.ui.event.FormularListener;
import xdev.ui.locking.AbstractLockRenewWindow;
import xdev.ui.locking.HybridLockInUseNotificationStrategy;
import xdev.ui.locking.LockAlreadyInUseIndicator;
import xdev.ui.locking.LockPropertyInfo;
import xdev.ui.locking.Lockable;
import xdev.ui.locking.LockableFormSupport;
import xdev.ui.locking.LockingApplicationExitAdapter;
import xdev.ui.locking.OnComponentFocusPessimisticLockStrategy;
import xdev.ui.paging.FormularPageControl;
import xdev.ui.paging.Pageable;
import xdev.util.logging.LoggerFactory;
import xdev.util.logging.XdevLogger;
import xdev.vt.KeyValues;
import xdev.vt.VirtualTable;
import xdev.vt.VirtualTable.VirtualTableRow;
import xdev.vt.VirtualTableException;
/**
* The {@link XdevFormular} is a GUI form container containing
* {@link FormularComponent}s and {@link ManyToManyComponent}s.
*
*
* The {@link XdevFormular} can be used to display a row of a
* {@link VirtualTable}. Therefore the {@link XdevFormular} must contain
* {@link FormularComponent}s that are mapped to the columns of the
* {@link VirtualTable} you want to display. This can be done by the XDEV IDE or
* manually.
*
*
*
* The {@link XdevFormular} also manages n:m-relations. Therefore
* {@link ManyToManyComponent}s can be added into this container.
*
*
*
* The {@link XdevFormular} provides methods to:
*
*
display {@link VirtualTableRow}s like
* {@link #setModel(xdev.vt.VirtualTable.VirtualTableRow)}
*
insert {@link VirtualTableRow}s like {@link #insert(boolean)}
*
update (before loaded) {@link VirtualTableRow}s like
* {@link #update(boolean)}
*
delete (before loaded) {@link VirtualTableRow}s like
* {@link #delete(boolean)}
*
*
*
* @author XDEV Software
*
* @see FormularListener
* @see FormularComponent
* @see MasterDetailComponent
* @see ManyToManyComponent
*
* @since 2.0
*/
public class XdevFormular extends XdevContainer implements Formular, Pageable, Lockable
{
private FormularSupport support = new FormularSupport(this);
private boolean saveStateAfterModelUpdate = true;
/**
* Logger instance for this class.
*/
private static final XdevLogger LOGGER = LoggerFactory
.getLogger(XdevFormular.class);
private LockPropertyInfo lockingPropertyInfo = new LockPropertyInfo();
private ApplicationExitListener exitListener;
/**
* @return the support
*/
public FormularSupport getSupport()
{
return support;
}
/**
* {@inheritDoc}
*/
@Override
// @BeanProperty(category = DefaultBeanCategories.DATA, owner =
// "showDialog")
public void setRenewLockWindow(AbstractLockRenewWindow renewDialog)
{
this.getLockingPropertyInfo().setRenewLockWindow(renewDialog);
}
/**
* {@inheritDoc}
*/
@Override
public AbstractLockRenewWindow getRenewLockWindow()
{
return this.getLockingPropertyInfo().getRenewLockWindow();
}
/**
* {@inheritDoc}
*/
@BeanProperty(category = DefaultBeanCategories.DATA, longMin = 0, longMax = Long.MAX_VALUE)
@Override
public void setNotificationThreshold(long notificationThreshold)
{
this.getLockingPropertyInfo().setNotificationThreshold(notificationThreshold);
}
/**
* {@inheritDoc}
*/
@Override
public long getNotificationThreshold()
{
return this.getLockingPropertyInfo().getNotificationThreshold();
}
/**
* {@inheritDoc}
*/
@Override
// @BeanProperty(category = DefaultBeanCategories.DATA, owner =
// "showDialog")
public void setLockInUseNotifier(LockAlreadyInUseIndicator lockInUseDialog)
{
this.getLockingPropertyInfo().setLockInUseNotifier(lockInUseDialog);
}
/**
* {@inheritDoc}
*/
@Override
public LockAlreadyInUseIndicator getLockInUseNotifier()
{
return this.getLockingPropertyInfo().getLockInUseNotifier();
}
/**
* {@inheritDoc}
*/
@BeanProperty(category = DefaultBeanCategories.DATA, owner = Lockable.AUTO_LOCK, longMin = 1, longMax = Long.MAX_VALUE)
@Override
public void setLockingTime(long lockingTime)
{
this.getLockingPropertyInfo().setLockingTime(lockingTime);
}
/**
* {@inheritDoc}
*/
@Override
public long getLockingTime()
{
return this.getLockingPropertyInfo().getLockingTime();
}
/**
* {@inheritDoc}
*/
@BeanProperty(category = DefaultBeanCategories.DATA, owner = Lockable.AUTO_LOCK)
@Override
public void setCountdownMonitors(LockTimeMonitor[] countdownMonitors)
{
this.getLockingPropertyInfo().setCountdownMonitors(countdownMonitors);
}
/**
* {@inheritDoc}
*/
@Override
public LockTimeMonitor[] getCountdownMonitors()
{
return this.getLockingPropertyInfo().getCountdownMonitors();
}
/**
* {@inheritDoc}
*/
@BeanProperty(category = DefaultBeanCategories.DATA)
@Override
public void setAutoLock(boolean autoLock)
{
// lazy init locking
this.lockingPropertyInfo.setAutoLock(autoLock);
// default strategies
this.setLockNotificationStrategy(new HybridLockInUseNotificationStrategy(this));
this.setLockStrategy(new OnComponentFocusPessimisticLockStrategy(this));
if(autoLock)
{
LockableFormSupport support = new LockableFormSupport(this);
this.support = support;
this.exitListener = new LockingApplicationExitAdapter();
Application.addExitListener(this.exitListener);
}
else
{
this.support = new FormularSupport(this);
if(this.exitListener != null)
{
Application.removeExitListener(this.exitListener);
}
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAutoLock()
{
return this.getLockingPropertyInfo().isAutoLock();
}
/**
* Create a new {@link XdevFormular} with no layout manager.
*
*
* Alias for XdevFormular(null)
*
*
* @see #XdevFormular(LayoutManager)
*
*/
public XdevFormular()
{
super();
}
/**
* Create a new {@link XdevFormular} with the specified layout manager.
*
* @param layout
* the LayoutManager to use
*/
public XdevFormular(LayoutManager layout)
{
super(layout);
}
/*
* Handler for FormularListener#formularComponentValueChanged(FormularEvent)
*
* @since 3.1
*/
{
addContainerListener(new ContainerHierarchyListener()
{
Map listenerMap = new HashMap();
Map focusListenerMap = new HashMap();
@Override
public void componentAddedInHierarchy(ContainerEvent e)
{
Component child = e.getChild();
if(child instanceof Container)
{
UIUtils.lookupComponentTree((Container)child,new ComponentTreeVisitor()
{
@Override
public Object visit(Component cpn)
{
if(cpn instanceof FormularComponent)
{
addFocusListener(cpn);
add((FormularComponent)cpn);
}
return null;
}
});
}
else if(child instanceof FormularComponent)
{
add((FormularComponent)child);
}
}
void add(final FormularComponent formularComponent)
{
if(!listenerMap.containsKey(formularComponent))
{
ValueChangeListener valueChangeListener = new ValueChangeListener()
{
@Override
public void valueChanged(Object eventObject)
{
fireFormularComponentValueChanged(formularComponent,eventObject);
}
};
formularComponent.addValueChangeListener(valueChangeListener);
listenerMap.put(formularComponent,valueChangeListener);
}
}
void addFocusListener(final Component component)
{
if(!focusListenerMap.containsKey(component))
{
FocusListener focusListener = new FocusListener()
{
@Override
public void focusGained(FocusEvent e)
{
fireFormularComponentFocusGained(component,e);
}
@Override
public void focusLost(FocusEvent e)
{
fireFormularComponentFocusLost(component,e);
}
};
component.addFocusListener(focusListener);
focusListenerMap.put(component,focusListener);
}
}
@Override
public void componentRemovedInHierarchy(ContainerEvent e)
{
}
});
}
/**
* {@inheritDoc}
*
* @since 4.0
*/
@Override
public Iterable formComponents()
{
final List list = new ArrayList();
lookupComponentTree(new ComponentTreeVisitor