From: diginetdev <dig...@us...> - 2004-03-18 19:29:33
|
Update of /cvsroot/columba/columba/src/addressbook/core/org/columba/addressbook/gui/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15360 Modified Files: EditPropertiesAction.java AddContactCardAction.java AddGroupCardAction.java AddVCardAction.java Log Message: [intern] changes for low level abstraction - separation of views from Frame Index: AddContactCardAction.java =================================================================== RCS file: /cvsroot/columba/columba/src/addressbook/core/org/columba/addressbook/gui/action/AddContactCardAction.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** AddContactCardAction.java 22 Feb 2004 14:31:23 -0000 1.16 --- AddContactCardAction.java 18 Mar 2004 19:19:53 -0000 1.17 *************** *** 1,86 **** ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.ContactCard; ! import org.columba.addressbook.gui.dialog.contact.ContactDialog; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! import org.columba.core.gui.util.ImageLoader; ! ! import java.awt.event.ActionEvent; ! ! /** * Add new contact card to selected addressbook. * * @author fdietz ! */ ! public class AddContactCardAction extends DefaultTreeAction { ! public AddContactCardAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addcontact")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addcontact_tooltip").replaceAll("&", "")); ! ! putValue(TOOLBAR_NAME, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addcontact_toolbar")); ! ! // icons ! putValue(SMALL_ICON, ImageLoader.getSmallImageIcon("contact_small.png")); ! putValue(LARGE_ICON, ImageLoader.getImageIcon("contact.png")); ! } ! /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected folder ! AddressbookFolder folder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! ContactDialog dialog = new ContactDialog(mediator.getView()); ! ! // TODO:move this code to dialog ! dialog.setVisible(true); ! ! if (dialog.getResult()) { ! ContactCard card = new ContactCard(); ! ! // move this code to dialog ! dialog.updateComponents(card, false); ! ! // add contact to folder ! folder.add(card); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } ! } --- 1,87 ---- ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.ContactCard; ! import org.columba.addressbook.gui.dialog.contact.ContactDialog; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! import org.columba.core.gui.util.ImageLoader; ! ! import java.awt.event.ActionEvent; ! import javax.swing.JFrame; ! ! /** * Add new contact card to selected addressbook. * * @author fdietz ! */ ! public class AddContactCardAction extends DefaultTreeAction { ! public AddContactCardAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addcontact")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addcontact_tooltip").replaceAll("&", "")); ! ! putValue(TOOLBAR_NAME, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addcontact_toolbar")); ! ! // icons ! putValue(SMALL_ICON, ImageLoader.getSmallImageIcon("contact_small.png")); ! putValue(LARGE_ICON, ImageLoader.getImageIcon("contact.png")); ! } ! /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected folder ! AddressbookFolder folder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! ContactDialog dialog = new ContactDialog((JFrame)mediator.getFrame()); ! ! // TODO:move this code to dialog ! dialog.setVisible(true); ! ! if (dialog.getResult()) { ! ContactCard card = new ContactCard(); ! ! // move this code to dialog ! dialog.updateComponents(card, false); ! ! // add contact to folder ! folder.add(card); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } ! } Index: AddGroupCardAction.java =================================================================== RCS file: /cvsroot/columba/columba/src/addressbook/core/org/columba/addressbook/gui/action/AddGroupCardAction.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** AddGroupCardAction.java 22 Feb 2004 14:31:23 -0000 1.17 --- AddGroupCardAction.java 18 Mar 2004 19:19:53 -0000 1.18 *************** *** 1,89 **** ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.GroupListCard; ! import org.columba.addressbook.gui.dialog.group.EditGroupDialog; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! import org.columba.core.gui.util.ImageLoader; ! ! import java.awt.event.ActionEvent; ! ! /** * Add new groupw card to selected addressbook. * * @author fdietz ! */ ! public class AddGroupCardAction extends DefaultTreeAction { ! public AddGroupCardAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addgroup")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addgroup_tooltip").replaceAll("&", "")); ! ! putValue(TOOLBAR_NAME, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addgroup_toolbar")); ! ! // icons ! putValue(SMALL_ICON, ImageLoader.getSmallImageIcon("group_small.png")); ! putValue(LARGE_ICON, ImageLoader.getImageIcon("group.png")); ! } ! /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected folder ! AddressbookFolder folder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! if (folder == null) { ! return; ! } ! ! EditGroupDialog dialog = new EditGroupDialog(mediator.getView(), null); ! ! if (dialog.getResult()) { ! // Ok ! GroupListCard card = new GroupListCard(); ! ! // TODO:move this code to dialog ! dialog.updateComponents(card, null, false); ! dialog.setVisible(true); ! ! // add new group to folder ! folder.add(card); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } ! } --- 1,90 ---- ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.GroupListCard; ! import org.columba.addressbook.gui.dialog.group.EditGroupDialog; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! import org.columba.core.gui.util.ImageLoader; ! ! import java.awt.event.ActionEvent; ! import javax.swing.JFrame; ! ! /** * Add new groupw card to selected addressbook. * * @author fdietz ! */ ! public class AddGroupCardAction extends DefaultTreeAction { ! public AddGroupCardAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addgroup")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addgroup_tooltip").replaceAll("&", "")); ! ! putValue(TOOLBAR_NAME, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addgroup_toolbar")); ! ! // icons ! putValue(SMALL_ICON, ImageLoader.getSmallImageIcon("group_small.png")); ! putValue(LARGE_ICON, ImageLoader.getImageIcon("group.png")); ! } ! /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected folder ! AddressbookFolder folder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! if (folder == null) { ! return; ! } ! ! EditGroupDialog dialog = new EditGroupDialog((JFrame)mediator.getFrame(), null); ! ! if (dialog.getResult()) { ! // Ok ! GroupListCard card = new GroupListCard(); ! ! // TODO:move this code to dialog ! dialog.updateComponents(card, null, false); ! dialog.setVisible(true); ! ! // add new group to folder ! folder.add(card); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } ! } Index: EditPropertiesAction.java =================================================================== RCS file: /cvsroot/columba/columba/src/addressbook/core/org/columba/addressbook/gui/action/EditPropertiesAction.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** EditPropertiesAction.java 22 Feb 2004 14:31:23 -0000 1.19 --- EditPropertiesAction.java 18 Mar 2004 19:19:53 -0000 1.20 *************** *** 1,130 **** ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.ContactCard; ! import org.columba.addressbook.folder.GroupListCard; ! import org.columba.addressbook.folder.HeaderItem; ! import org.columba.addressbook.folder.HeaderItemList; ! import org.columba.addressbook.gui.dialog.contact.ContactDialog; ! import org.columba.addressbook.gui.dialog.group.EditGroupDialog; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! import org.columba.core.gui.util.ImageLoader; ! ! import java.awt.event.ActionEvent; ! ! ! /** ! * Edit properties of selected contact or group. ! * ! * @author fdietz ! */ ! public class EditPropertiesAction extends DefaultTableAction { ! public EditPropertiesAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_properties")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_properties_tooltip").replaceAll("&", "")); ! ! putValue(TOOLBAR_NAME, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_properties_toolbar")); ! ! // icons ! putValue(SMALL_ICON, ImageLoader.getSmallImageIcon("stock_edit-16.png")); ! putValue(LARGE_ICON, ImageLoader.getImageIcon("stock_edit.png")); ! ! setEnabled(false); ! } ! ! /** ! * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected contact/group card ! Object[] uids = mediator.getTable().getUids(); ! ! // get selected folder ! AddressbookFolder folder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! if (uids.length == 0) { ! return; ! } ! ! //TODO: Why do we need this HeaderItem anyway? ! // -> just get the card from the folder, wether it is a contact or ! // group card ! HeaderItem item = mediator.getTable().getSelectedItem(); ! ! if (item.isContact()) { ! ContactCard card = (ContactCard) folder.get(uids[0]); ! ContactDialog dialog = new ContactDialog(mediator.getView()); ! ! // TODO: move this code to dialog ! dialog.updateComponents(card, true); ! dialog.setVisible(true); ! ! if (dialog.getResult()) { ! //TODO:move this code to dialog ! dialog.updateComponents(card, false); ! ! // modify card properties in folder ! folder.modify(card, uids[0]); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } else { ! GroupListCard card = (GroupListCard) folder.get(uids[0]); ! ! EditGroupDialog dialog = new EditGroupDialog(mediator.getView(), ! null); ! ! Object[] groupUids = card.getUids(); ! HeaderItemList members = folder.getHeaderItemList(groupUids); ! ! // TODO: move this code to dialog ! dialog.updateComponents(card, members, true); ! dialog.setVisible(true); ! ! if (dialog.getResult()) { ! // TODO: move this code to dialog ! dialog.updateComponents(card, null, false); ! ! // modify card properties in folder ! folder.modify(card, uids[0]); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } ! } ! } --- 1,131 ---- ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.ContactCard; ! import org.columba.addressbook.folder.GroupListCard; ! import org.columba.addressbook.folder.HeaderItem; ! import org.columba.addressbook.folder.HeaderItemList; ! import org.columba.addressbook.gui.dialog.contact.ContactDialog; ! import org.columba.addressbook.gui.dialog.group.EditGroupDialog; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! import org.columba.core.gui.util.ImageLoader; ! ! import java.awt.event.ActionEvent; ! import javax.swing.JFrame; ! ! ! /** ! * Edit properties of selected contact or group. ! * ! * @author fdietz ! */ ! public class EditPropertiesAction extends DefaultTableAction { ! public EditPropertiesAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_properties")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_properties_tooltip").replaceAll("&", "")); ! ! putValue(TOOLBAR_NAME, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_properties_toolbar")); ! ! // icons ! putValue(SMALL_ICON, ImageLoader.getSmallImageIcon("stock_edit-16.png")); ! putValue(LARGE_ICON, ImageLoader.getImageIcon("stock_edit.png")); ! ! setEnabled(false); ! } ! ! /** ! * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected contact/group card ! Object[] uids = mediator.getTable().getUids(); ! ! // get selected folder ! AddressbookFolder folder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! if (uids.length == 0) { ! return; ! } ! ! //TODO: Why do we need this HeaderItem anyway? ! // -> just get the card from the folder, wether it is a contact or ! // group card ! HeaderItem item = mediator.getTable().getSelectedItem(); ! ! if (item.isContact()) { ! ContactCard card = (ContactCard) folder.get(uids[0]); ! ContactDialog dialog = new ContactDialog((JFrame)mediator.getFrame()); ! ! // TODO: move this code to dialog ! dialog.updateComponents(card, true); ! dialog.setVisible(true); ! ! if (dialog.getResult()) { ! //TODO:move this code to dialog ! dialog.updateComponents(card, false); ! ! // modify card properties in folder ! folder.modify(card, uids[0]); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } else { ! GroupListCard card = (GroupListCard) folder.get(uids[0]); ! ! EditGroupDialog dialog = new EditGroupDialog((JFrame)mediator.getFrame(), ! null); ! ! Object[] groupUids = card.getUids(); ! HeaderItemList members = folder.getHeaderItemList(groupUids); ! ! // TODO: move this code to dialog ! dialog.updateComponents(card, members, true); ! dialog.setVisible(true); ! ! if (dialog.getResult()) { ! // TODO: move this code to dialog ! dialog.updateComponents(card, null, false); ! ! // modify card properties in folder ! folder.modify(card, uids[0]); ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } ! } ! } Index: AddVCardAction.java =================================================================== RCS file: /cvsroot/columba/columba/src/addressbook/core/org/columba/addressbook/gui/action/AddVCardAction.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AddVCardAction.java 22 Feb 2004 14:31:23 -0000 1.13 --- AddVCardAction.java 18 Mar 2004 19:19:53 -0000 1.14 *************** *** 1,103 **** ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.ContactCard; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.parser.VCardParser; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! ! import java.awt.event.ActionEvent; ! ! import java.io.BufferedReader; ! import java.io.File; ! import java.io.FileReader; ! ! import javax.swing.JFileChooser; ! ! ! /** ! * Import VCARD contact to selected addressbook. ! */ ! public class AddVCardAction extends DefaultTreeAction { ! public AddVCardAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addvcard")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addvcard").replaceAll("&", "")); ! } ! ! /** ! * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected folder ! AddressbookFolder destinationFolder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! // create open file dialog ! JFileChooser fc = new JFileChooser(); ! fc.setFileSelectionMode(JFileChooser.FILES_ONLY); ! fc.setMultiSelectionEnabled(true); ! ! int returnVal = fc.showOpenDialog(frameMediator.getView()); ! ! //if user pressed OK button ! if (returnVal == JFileChooser.APPROVE_OPTION) { ! File[] files = fc.getSelectedFiles(); ! ! for (int i = 0; i < files.length; i++) { ! try { ! StringBuffer strbuf = new StringBuffer(); ! ! // read VCARD file into string buffer ! BufferedReader in = new BufferedReader(new FileReader( ! files[i])); ! String str; ! ! while ((str = in.readLine()) != null) { ! strbuf.append(str + "\n"); ! } ! ! in.close(); ! ! // create contact card ! ContactCard card = VCardParser.parse(strbuf.toString()); ! ! // add to folder ! destinationFolder.add(card); ! } catch (Exception ex) { ! ex.printStackTrace(); ! } ! } ! } ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } --- 1,104 ---- ! // The contents of this file are subject to the Mozilla Public License Version ! // 1.1 ! //(the "License"); you may not use this file except in compliance with the ! //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ ! // ! //Software distributed under the License is distributed on an "AS IS" basis, ! //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License ! //for the specific language governing rights and ! //limitations under the License. ! // ! //The Original Code is "The Columba Project" ! // ! //The Initial Developers of the Original Code are Frederik Dietz and Timo ! // Stich. ! //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. ! // ! //All Rights Reserved. ! package org.columba.addressbook.gui.action; ! ! import org.columba.addressbook.folder.AddressbookFolder; ! import org.columba.addressbook.folder.ContactCard; ! import org.columba.addressbook.gui.frame.AddressbookFrameMediator; ! import org.columba.addressbook.parser.VCardParser; ! import org.columba.addressbook.util.AddressbookResourceLoader; ! ! import org.columba.core.gui.frame.FrameMediator; ! ! import java.awt.event.ActionEvent; ! ! import java.io.BufferedReader; ! import java.io.File; ! import java.io.FileReader; ! ! import javax.swing.JFileChooser; ! import javax.swing.JFrame; ! ! ! /** ! * Import VCARD contact to selected addressbook. ! */ ! public class AddVCardAction extends DefaultTreeAction { ! public AddVCardAction(FrameMediator frameController) { ! super(frameController, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addvcard")); ! ! // tooltip text ! putValue(SHORT_DESCRIPTION, ! AddressbookResourceLoader.getString("menu", "mainframe", ! "menu_file_addvcard").replaceAll("&", "")); ! } ! ! /** ! * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) ! */ ! public void actionPerformed(ActionEvent evt) { ! AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; ! ! // get selected folder ! AddressbookFolder destinationFolder = (AddressbookFolder) mediator.getTree() ! .getSelectedFolder(); ! ! // create open file dialog ! JFileChooser fc = new JFileChooser(); ! fc.setFileSelectionMode(JFileChooser.FILES_ONLY); ! fc.setMultiSelectionEnabled(true); ! ! int returnVal = fc.showOpenDialog((JFrame)frameMediator.getFrame()); ! ! //if user pressed OK button ! if (returnVal == JFileChooser.APPROVE_OPTION) { ! File[] files = fc.getSelectedFiles(); ! ! for (int i = 0; i < files.length; i++) { ! try { ! StringBuffer strbuf = new StringBuffer(); ! ! // read VCARD file into string buffer ! BufferedReader in = new BufferedReader(new FileReader( ! files[i])); ! String str; ! ! while ((str = in.readLine()) != null) { ! strbuf.append(str + "\n"); ! } ! ! in.close(); ! ! // create contact card ! ContactCard card = VCardParser.parse(strbuf.toString()); ! ! // add to folder ! destinationFolder.add(card); ! } catch (Exception ex) { ! ex.printStackTrace(); ! } ! } ! } ! ! // update table ! // TODO: fire event of table model instead ! mediator.getTable().getAddressbookModel().update(); ! } ! } |