if (link.isVisible()) if (link.isRight()) rightFields--; else leftFields--;
private void synchronizeMacroLinkFields(){	Object[] objs = new Object[getSubObjectsV().size()];	getSubObjectsV().copyInto(objs);	// add macros	Enumeration e = templateData.getTemplate().getMacrosV().elements();	while (e.hasMoreElements())	{		VDBMacro macro = (VDBMacro)e.nextElement();		Object obj = getSubObject(macro.getName());		if (obj==null)		{			TemplateEPICSMacro tem = null;			for (int i=0; i<objs.length; i++)				if (objs[i] instanceof TemplateEPICSMacro)				{					TemplateEPICSMacro t = (TemplateEPICSMacro)objs[i];					if (t.getFieldData().getName().equals(macro.getName()))					{						tem = t;						break;					}				}								// renamed			if (tem!=null)			{				Object key = null;				Enumeration e2 = getSubObjects().keys();				while (e2.hasMoreElements())				{					Object key2 = e2.nextElement();					Object val = getSubObjects().get(key2);					if (val instanceof TemplateEPICSMacro && val==tem)					{						key = key2;						break;					}				}								if (key!=null)				{					removeObject(key.toString());										// remove from properties					String keyStr = key.toString();					Iterator it = templateData.getProperties().keySet().iterator();					while (it.hasNext())					{						// !!! not perfect solution						String propertyName = it.next().toString();						if (propertyName.equals(keyStr))							templateData.removeProperty(propertyName);					}				}				else					System.out.println("Internal error...");									addSubObject(tem.getFieldData().getName(), tem);				// add to properties				templateData.addProperty(tem.getFieldData().getName(), tem.getFieldData().getValue());				// update lookup table and fix source links 				tem.fixTemplateLink();												//System.out.println("!! renamed !! "+macro.getName());			}			else			{				//System.out.println("!! added !!"+macro.getName());				// add macro				VDBTemplateMacro tf = new VDBTemplateMacro(getTemplateData(), macro);				EPICSLink link = createLinkField(tf);				if (link!=null)					addSubObject(tf.getName(), link);			}		}		else		{			// fix macro if necessary (result of add+remove action)			VDBTemplateMacro tmd = ((VDBTemplateMacro)((TemplateEPICSMacro)obj).getFieldData());			if (tmd.getMacro()!=macro)			{				//System.out.println("!! fixing macro !!"+macro.getName());				tmd.setMacro(macro);			}		}	}	// remove macros	for (int i=0; i<objs.length; i++)	{		if (objs[i] instanceof TemplateEPICSMacro)		{			TemplateEPICSMacro link = (TemplateEPICSMacro)objs[i];			if (!templateData.getTemplate().getMacros().containsKey(link.getFieldData().getName()))			{				//System.out.println("!! removed !! "+link.getFieldData().getName());				// remove macro				link.destroyAndRemove();					removeObject(link.getFieldData().getName());								fields--;								// remove from properties				templateData.removeProperty(link.getFieldData().getName());			}		}	}		// save macros ID	macrosID = getTemplateData().getTemplate().getMacrosGeneratedID();	//com.cosylab.vdct.graphics.DrawingSurface.getInstance().setModified(true);}