Example usage for java.beans PropertyChangeEvent getNewValue

List of usage examples for java.beans PropertyChangeEvent getNewValue

Introduction

In this page you can find the example usage for java.beans PropertyChangeEvent getNewValue.

Prototype

public Object getNewValue() 

Source Link

Document

Gets the new value for the property, expressed as an Object.

Usage

From source file:org.squidy.designer.zoom.ContainerShape.java

@Override
public void initializeLayout() {
    super.initializeLayout();

    final ImageButton startProcessing = new ImageButton(
            ActionShape.class.getResource("/images/24x24/media_play_green.png"), "Start");
    final ImageButton stopProcessing = new ImageButton(
            ActionShape.class.getResource("/images/24x24/media_stop_red.png"), "Stop");
    stopProcessing.setEnabled(false);//from  ww w  . j  a  va2  s  . co  m

    startProcessing.addZoomActionListener(new ZoomActionListener() {

        /**
         * @param e
         */
        public void actionPerformed(ZoomActionEvent e) {

            new Thread() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see java.lang.Thread#run()
                 */
                @Override
                public void run() {
                    if (!getProcessable().isProcessing()) {
                        startProcessing.setEnabled(false);
                        stopProcessing.setEnabled(true);
                        invalidatePaint();
                        ContainerShape.this.start();
                        ContainerShape.this.doStart();

                        Manager.get().notify(getProcessable(), Action.START);
                    }
                }
            }.start();
        }
    });

    stopProcessing.addZoomActionListener(new ZoomActionListener() {

        /**
         * @param e
         */
        public void actionPerformed(ZoomActionEvent e) {
            new Thread() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see java.lang.Thread#run()
                 */
                @Override
                public void run() {
                    // if (getProcessable().isProcessing()) {
                    startProcessing.setEnabled(true);
                    stopProcessing.setEnabled(false);
                    invalidatePaint();
                    ContainerShape.this.stop();
                    ContainerShape.this.doStop();
                    // }

                    Manager.get().notify(getProcessable(), Action.STOP);
                }
            }.start();
        }
    });

    ImageButton delete = new ImageButton(ActionShape.class.getResource("/images/24x24/delete2.png"), "Delete");
    delete.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Pressed delete on " + getBreadcrumb());
            }

            int option = JOptionPane.showConfirmDialog(Designer.getInstance(),
                    "Would you like to delete " + getTitle() + "?", "Delete?", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    new ImageIcon(ActionShape.class.getResource("/images/delete.png")));

            if (option == JOptionPane.OK_OPTION) {
                ZoomShape<?> zoomShape = null;
                if (currentZoomState == ZoomState.ZOOM_IN && getParent() instanceof ZoomShape<?>) {
                    zoomShape = (ZoomShape<?>) getParent();
                }
                delete();
                if (zoomShape != null) {
                    zoomShape.animateToCenterView(e.getCamera());

                    // Set pipe shapes visible and pickable.
                    for (Object child : zoomShape.getChildrenReference()) {
                        if (child instanceof PipeShape) {
                            ShapeUtils.setApparent((PipeShape) child, true);
                        }
                    }
                }

                Manager.get().notify(getProcessable(), Action.DELETE);
            }
        }
    });

    ImageButton duplicate = new ImageButton(ActionShape.class.getResource("/images/24x24/copy.png"),
            "Duplicate");
    duplicate.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Duplicate has been pressed for " + getBreadcrumb());
            }

            Manager.get().notify(getProcessable(), Action.DUPLICATE);
        }
    });
    duplicate.setEnabled(false);

    ImageButton publish = new ImageButton(ActionShape.class.getResource("/images/24x24/export2.png"),
            "Publish");
    publish.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Publish has been pressed for " + getBreadcrumb());
            }

            Storable storable = ShapeUtils.getObjectInHierarchy(Storable.class, ContainerShape.this);
            if (storable != null) {
                storable.store();
            }
        }
    });
    publish.setEnabled(false);

    ImageButton update = new ImageButton(ActionShape.class.getResource("/images/24x24/import1.png"), "Update");
    update.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Update has been pressed for " + getBreadcrumb());
            }
        }
    });
    update.setEnabled(false);

    addPropertyChangeListener(Processable.PROPERTY_PROCESSING, new PropertyChangeListener() {

        /*
        * (non-Javadoc)
        * 
        * 
        * 
        * @seejava.beans.PropertyChangeListener#propertyChange(java.
        * beans. PropertyChangeEvent)
        */
        public void propertyChange(PropertyChangeEvent evt) {
            startProcessing.setEnabled(!(Boolean) evt.getNewValue());
            stopProcessing.setEnabled((Boolean) evt.getNewValue());

            if ((Boolean) evt.getNewValue())
                doStart();
            else
                doStop();
        }
    });

    //      addPropertyChangeListener(Processable.PROPERTY_PROCESSING_STOP,
    //            new PropertyChangeListener() {
    //
    //               /*
    //                * (non-Javadoc)
    //                * 
    //                * 
    //                * 
    //                * @seejava.beans.PropertyChangeListener#propertyChange(java.
    //                * beans. PropertyChangeEvent)
    //                */
    //               public void propertyChange(PropertyChangeEvent evt) {
    //                  // startProcessing.setToggleState(ZoomToggle.RELEASED);
    //                  // stopProcessing.setToggleState(ZoomToggle.PRESSED);
    //                  startProcessing.setEnabled(true);
    //                  stopProcessing.setEnabled(false);
    //                  doStop();
    //               }
    //            });

    ShapeUtils.setApparent(startProcessing, false);
    ShapeUtils.setApparent(stopProcessing, false);
    if (!(this instanceof WorkspaceShape)) {
        ShapeUtils.setApparent(delete, false);
        ShapeUtils.setApparent(duplicate, false);
        ShapeUtils.setApparent(publish, false);
        ShapeUtils.setApparent(update, false);
    }

    addAction(startProcessing);
    addAction(stopProcessing);
    if (!(this instanceof WorkspaceShape)) {
        addAction(delete);
        addAction(duplicate);
        addAction(publish);
        addAction(update);
    }
}

From source file:edu.ucla.stat.SOCR.analyses.gui.Clustering.java

/** Implementation of PropertyChageListener.*/
public void propertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    if (propertyName.equals("DataUpdate")) {
        //update the local version of the dataTable by outside source
        dataTable = (JTable) (e.getNewValue());
        dataPanel.removeAll();//from www. ja  va  2  s .  com
        dataPanel.add(new JScrollPane(dataTable));
    }
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowserControl.java

/**
 * Loads data, filters nodes or sets the selected node.
 * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
 *///from   w  w w  .  j av  a  2s . c  o  m
public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (Browser.SELECTED_DATA_BROWSER_NODE_DISPLAY_PROPERTY.equals(name)) {
        ImageDisplay node = (ImageDisplay) evt.getNewValue();
        if (node == null)
            return;
        model.setSelectedDisplay(node);
    } else if (Browser.SELECTED_DATA_BROWSER_NODES_DISPLAY_PROPERTY.equals(name)) {
        List<ImageDisplay> nodes = (List<ImageDisplay>) evt.getNewValue();
        model.setSelectedDisplays(nodes);
    } else if (Browser.UNSELECTED_DATA_BROWSER_NODE_DISPLAY_PROPERTY.equals(name)) {
        ImageDisplay node = (ImageDisplay) evt.getNewValue();
        if (node == null)
            return;
        model.setUnselectedDisplay(node);
    } else if (QuickFiltering.FILTER_DATA_PROPERTY.equals(name)) {
        filterNodes((SearchObject) evt.getNewValue());
    } else if (QuickFiltering.DISPLAY_ALL_NODES_PROPERTY.equals(name)) {
        showAll();
    } else if (FilteringDialog.FILTER_PROPERTY.equals(name)
            || QuickFiltering.FILTER_TAGS_PROPERTY.equals(name)) {
        FilterContext filter = (FilterContext) evt.getNewValue();
        model.filterByContext(filter);
    } else if (FilteringDialog.LOAD_TAG_PROPERTY.equals(name)
            || QuickFiltering.TAG_LOADING_PROPERTY.equals(name)) {
        model.loadExistingTags();
    } else if (Browser.ROLL_OVER_PROPERTY.equals(name)) {
        if (view.isRollOver()) {
            RollOverNode n = (RollOverNode) evt.getNewValue();
            if (n != null && n.getNode() != null) {
                ImageNode node = n.getNode();
                Thumbnail prv = node.getThumbnail();
                BufferedImage full = prv.getFullScaleThumb();
                if (prv.getScalingFactor() == Thumbnail.MAX_SCALING_FACTOR)
                    full = prv.getZoomedFullScaleThumb();
                RollOverThumbnailManager.rollOverDisplay(full, node.getBounds(), n.getLocationOnScreen(),
                        node.toString());
            } else
                RollOverThumbnailManager.stopOverDisplay();
        }
    } else if (SlideShowView.CLOSE_SLIDE_VIEW_PROPERTY.equals(name)) {
        view.slideShowView(false);
    } else if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)
            || EditorDialog.CREATE_PROPERTY.equals(name)) {
        DataObject object = (DataObject) evt.getNewValue();
        model.createDataObject(object);
    } else if (ImageTableView.TABLE_NODES_SELECTION_PROPERTY.equals(name)) {
        List<ImageDisplay> selected = (List) evt.getNewValue();
        model.setTableNodesSelected(selected);
    } else if (ImageTableView.TABLE_SELECTION_MENU_PROPERTY.equals(name)) {
        Point location = (Point) evt.getNewValue();
        if (location != null)
            view.showPopup(location);
    } else if (Browser.POPUP_POINT_PROPERTY.equals(name)) {
        Point p = (Point) evt.getNewValue();
        if (p != null)
            view.showPopup(p);
    } else if (ImageTableView.TABLE_SELECTION_VIEW_PROPERTY.equals(name)) {
        Boolean b = (Boolean) evt.getNewValue();
        if (b)
            view.viewSelectedNode();
    } else if (ImageTableView.TABLE_SELECTION_ROLL_OVER_PROPERTY.equals(name)) {
        RollOverNode node = (RollOverNode) evt.getNewValue();
        model.getBrowser().setRollOverNode(node);
    } else if (Browser.CELL_SELECTION_PROPERTY.equals(name)) {
        CellDisplay cell = (CellDisplay) evt.getNewValue();
        model.setSelectedCell(cell);
    } else if (SelectionWizard.SELECTED_ITEMS_PROPERTY.equals(name)) {
        Map m = (Map) evt.getNewValue();
        if (m == null || m.size() != 1)
            return;
        Set set = m.entrySet();
        Entry entry;
        Iterator i = set.iterator();
        Class type;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            type = (Class) entry.getKey();
            if (DatasetData.class.equals(type)) {
                model.addToDatasets((Collection) entry.getValue());
            }
        }
    } else if (PlateGrid.WELL_FIELDS_PROPERTY.equals(name)) {
        PlateGridObject p = (PlateGridObject) evt.getNewValue();
        if (p == null)
            return;
        model.viewFieldsFor(p.getRow(), p.getColumn(), p.isMultipleSelection());
    } else if (Browser.VIEW_DISPLAY_PROPERTY.equals(name)) {
        viewDisplay((ImageDisplay) evt.getNewValue());
    } else if (Browser.MAIN_VIEW_DISPLAY_PROPERTY.equals(name)) {
        ImageDisplay node = (ImageDisplay) evt.getNewValue();
        Object ho = node.getHierarchyObject();
        if (ho instanceof ImageData)
            model.viewDisplay(node, true);
    }
}

From source file:org.openmicroscopy.shoola.agents.imviewer.util.saver.ImgSaver.java

/** 
 * Notifies that the image has been saved locally.
 * //w ww .  ja v  a2s  . c  o m
 * @param name The path to the local file.
 */
private void notifySave(String name) {
    NotificationDialog dialog = new NotificationDialog(this, "Save Image", getSaveMessage(name), true);
    dialog.addPropertyChangeListener(new PropertyChangeListener() {

        /**
         * Opens the image with default viewer.
         */
        public void propertyChange(PropertyChangeEvent evt) {
            if (NotificationDialog.HYPERLINK_OPEN_PROPERTY.equals(evt.getPropertyName())) {
                UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier();
                un.openApplication(null, (String) evt.getNewValue());
            }
        }
    });
    dialog.pack();
    UIUtilities.centerAndShow(dialog);
}

From source file:org.zeromeaner.gui.reskin.StandaloneFrame.java

private void createCards() {
    introPanel = new StandaloneLicensePanel();
    content.add(introPanel, CARD_INTRO);

    playCard = new JPanel(new BorderLayout());
    content.add(playCard, CARD_PLAY);//  w w w . jav a  2 s .  c  om

    JPanel confirm = new JPanel(new GridBagLayout());
    JOptionPane option = new JOptionPane("A game is in open.  End this game?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!CARD_PLAY_END.equals(currentCard))
                return;
            if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) {
                gamePanel.shutdown();
                try {
                    gamePanel.shutdownWait();
                } catch (InterruptedException ie) {
                }
                contentCards.show(content, nextCard);
                currentCard = nextCard;
            }
            if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) {
                contentCards.show(content, CARD_PLAY);
                currentCard = CARD_PLAY;
                playButton.setSelected(true);
            }

            ((JOptionPane) evt.getSource()).setValue(-1);
        }
    });
    GridBagConstraints cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0);
    confirm.add(option, cx);
    content.add(confirm, CARD_PLAY_END);

    content.add(new StandaloneModeselectPanel(), CARD_MODESELECT);

    netplayCard = new JPanel(new BorderLayout());
    netplayCard.add(netLobby, BorderLayout.SOUTH);
    content.add(netplayCard, CARD_NETPLAY);

    confirm = new JPanel(new GridBagLayout());
    option = new JOptionPane("A netplay game is open.  End this game and disconnect?",
            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
    option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!CARD_NETPLAY_END.equals(currentCard))
                return;
            if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) {
                gamePanel.shutdown();
                try {
                    gamePanel.shutdownWait();
                } catch (InterruptedException ie) {
                }
                netLobby.disconnect();
                contentCards.show(content, nextCard);
                currentCard = nextCard;
            }
            if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) {
                contentCards.show(content, CARD_NETPLAY);
                currentCard = CARD_NETPLAY;
                netplayButton.setSelected(true);
            }

            ((JOptionPane) evt.getSource()).setValue(-1);
        }
    });
    cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE,
            new Insets(10, 10, 10, 10), 0, 0);
    confirm.add(option, cx);
    content.add(confirm, CARD_NETPLAY_END);

    StandaloneKeyConfig kc = new StandaloneKeyConfig(this);
    kc.load(0);
    content.add(kc, CARD_KEYS_1P);
    kc = new StandaloneKeyConfig(this);
    kc.load(1);
    content.add(kc, CARD_KEYS_2P);

    StandaloneGameTuningPanel gt = new StandaloneGameTuningPanel();
    gt.load(0);
    content.add(gt, CARD_TUNING_1P);
    gt = new StandaloneGameTuningPanel();
    gt.load(1);
    content.add(gt, CARD_TUNING_2P);

    StandaloneAISelectPanel ai = new StandaloneAISelectPanel();
    ai.load(0);
    content.add(ai, CARD_AI_1P);
    ai = new StandaloneAISelectPanel();
    ai.load(1);
    content.add(ai, CARD_AI_2P);

    StandaloneGeneralConfigPanel gc = new StandaloneGeneralConfigPanel();
    gc.load();
    content.add(gc, CARD_GENERAL);

    final JFileChooser fc = FileSystemViews.get().fileChooser("replay/");

    fc.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Zeromeaner Replay Files";
        }

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().endsWith(".zrep");
        }
    });

    fc.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION))
                return;
            JFileChooser fc = (JFileChooser) e.getSource();
            String path = fc.getSelectedFile().getPath();
            if (!path.contains("replay/"))
                path = "replay/" + path;
            startReplayGame(path);
        }
    });
    fc.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent e) {
            fc.rescanCurrentDirectory();
        }
    });
    content.add(fc, CARD_OPEN);

    content.add(new StandaloneFeedbackPanel(), CARD_FEEDBACK);
}

From source file:edu.ku.brc.specify.tasks.InteractionsProcessor.java

/**
 * Creates a new loan from a RecordSet./*  ww  w.  jav  a2  s  .  com*/
 * @param currPrepProvider an existing loan that needs additional Preps
 * @param infoRequest a info request
 * @param recordSetArg the recordset to use to create the loan
 */
public void createOrAdd(final T currPrepProvider, final InfoRequest infoRequest,
        final RecordSetIFace recordSetArg) {
    RecordSetIFace recordSet = recordSetArg;
    boolean isEmptyAcc = false;
    if (infoRequest == null && recordSet == null) {
        String catNumField = "catalogNumber";

        // Get a List of InfoRequest RecordSets
        Vector<RecordSetIFace> rsList = task.getInfoReqRecordSetsFromSideBar();
        RecordSetTask rsTask = (RecordSetTask) TaskMgr.getTask(RecordSetTask.RECORD_SET);
        List<RecordSetIFace> colObjRSList = rsTask.getRecordSets(CollectionObject.getClassTableId());

        // If the List is empty then
        if (rsList.size() == 0 && colObjRSList.size() == 0 && (isFor != forAcc || currPrepProvider != null)) {
            recordSet = task.askForDataObjRecordSet(CollectionObject.class, catNumField);

        } else {
            ASK_TYPE rv = askSourceOfPreps(rsList.size() > 0, colObjRSList.size() > 0, currPrepProvider);
            if (rv == ASK_TYPE.ChooseRS) {
                recordSet = RecordSetTask.askForRecordSet(CollectionObject.getClassTableId(), rsList);

            } else if (rv == ASK_TYPE.EnterDataObjs) {
                recordSet = task.askForDataObjRecordSet(CollectionObject.class, catNumField);

            } else if (rv == ASK_TYPE.None) {
                recordSet = null;
                isEmptyAcc = true;
            } else if (rv == ASK_TYPE.Cancel) {
                if (viewable != null) {
                    viewable.setNewObject(null);
                }
                return;
            }
        }
    }

    if (recordSet == null && !isEmptyAcc) {
        return;
    }

    if (isEmptyAcc) {
        PrepLoaderSQL prepLoaderSQL = new PrepLoaderSQL(null, recordSet, infoRequest, isFor);
        prepLoaderSQL.execute();
    } else {
        DBTableIdMgr.getInstance().getInClause(recordSet);

        DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoById(recordSet.getDbTableId());

        DataProviderFactory.getInstance().evict(tableInfo.getClassObj()); // XXX Not sure if this is really needed

        DataProviderSessionIFace session = null;
        try {
            session = DataProviderFactory.getInstance().createSession();

            // OK, it COULD be a RecordSet contain one or more InfoRequest, 
            // we will only accept an RS with one InfoRequest
            if (infoRequest == null && recordSet.getDbTableId() == InfoRequest.getClassTableId()) {
                if (recordSet.getNumItems() == 1) {
                    RecordSetItemIFace item = recordSet.getOnlyItem();
                    if (item != null) {
                        InfoRequest infoReq = session.get(InfoRequest.class, item.getRecordId().intValue());
                        if (infoReq != null) {
                            createOrAdd(null, infoReq, infoReq.getRecordSets().iterator().next());

                        } else {
                            // error about missing info request
                            // Error Dialog
                        }
                    } else {
                        // error about item being null for some unbelievable reason 
                        // Error Dialog
                    }
                } else {
                    // error about item having more than one or none
                    // Error Dialog
                }
                return;
            }

            // OK, here we have a recordset of CollectionObjects
            // First we process all the CollectionObjects in the RecordSet
            // and create a list of Preparations that can be loaned
            String sqlStr = DBTableIdMgr.getInstance().getQueryForTable(recordSet);
            if (StringUtils.isNotBlank(sqlStr)) {

                //CACA 
                final JStatusBar statusBar = UIRegistry.getStatusBar();
                statusBar.setIndeterminate(LOAN_LOADR, true);

                if (recordSet.getNumItems() > 2) {
                    UIRegistry.writeSimpleGlassPaneMsg(getResourceString("NEW_INTER_LOADING_PREP"), 24);
                }

                PrepLoaderSQL prepLoaderSQL = new PrepLoaderSQL(currPrepProvider, recordSet, infoRequest,
                        isFor);
                prepLoaderSQL.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        log.debug(evt.getNewValue());
                        if ("progress".equals(evt.getPropertyName())) {
                            statusBar.setValue(LOAN_LOADR, (Integer) evt.getNewValue());
                        }
                    }
                });
                prepLoaderSQL.execute();

            } else {
                log.error("Query String empty for RecordSet tableId[" + recordSet.getDbTableId() + "]");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(InteractionsProcessor.class, ex);
        }
    }
}

From source file:org.jspresso.hrsample.backend.JspressoModelTest.java

/**
 * Tests that 3+ level nested property changes get notified.
 *//*from w  ww  . j a  v  a  2 s .co m*/
@Test
public void testSubNestedPropertyChange() {
    final HibernateBackendController hbc = (HibernateBackendController) getBackendController();

    EnhancedDetachedCriteria crit = EnhancedDetachedCriteria.forClass(Department.class);
    final Department d = hbc.findFirstByCriteria(crit, EMergeMode.MERGE_LAZY, Department.class);
    final StringBuilder buff = new StringBuilder();
    d.addPropertyChangeListener(
            OrganizationalUnit.MANAGER + "." + Employee.CONTACT + "." + ContactInfo.CITY + "." + Nameable.NAME,
            new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    buff.append(evt.getNewValue());
                }
            });
    City currentCity = d.getManager().getContact().getCity();
    currentCity.setName("testSubNotif");
    assertEquals("Sub-nested notification did not arrive correctly", currentCity.getName(), buff.toString());
    buff.delete(0, buff.length());

    City newCity = hbc.getEntityFactory().createEntityInstance(City.class);
    newCity.setName("newSubNotif");
    newCity.setZip("12345");
    d.getManager().getContact().setCity(newCity);
    assertEquals("Sub-nested notification did not arrive correctly", newCity.getName(), buff.toString());
    buff.delete(0, buff.length());

    newCity.setName("anotherOne");
    assertEquals("Sub-nested notification did not arrive correctly", newCity.getName(), buff.toString());
    buff.delete(0, buff.length());

    currentCity.setName("noNotifExpected");
    assertEquals("Sub-nested notification arrived whereas is shouldn't", "", buff.toString());
    buff.delete(0, buff.length());

    City anotherNewCity = hbc.getEntityFactory().createEntityInstance(City.class);
    anotherNewCity.setName("anotherNewCity");
    anotherNewCity.setZip("12345");

    Employee newManager = hbc.getEntityFactory().createEntityInstance(Employee.class);
    newManager.getContact().setCity(anotherNewCity);
    newManager.setCompany(d.getCompany());
    d.setManager(newManager);
    assertEquals("Sub-nested notification did not arrive correctly", anotherNewCity.getName(), buff.toString());
    buff.delete(0, buff.length());

    anotherNewCity.setName("anotherNewNotif");
    assertEquals("Sub-nested notification did not arrive correctly", anotherNewCity.getName(), buff.toString());
    buff.delete(0, buff.length());
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.SearchPanel.java

/** Initializes the components composing the display. */
private void initComponents() {
    usersBox = new JComboBox();
    groupsBox = createGroupBox();//from   ww w .j  ava  2s .  c o m
    scopes = new HashMap<Integer, JCheckBox>(model.getNodes().size());
    types = new HashMap<Integer, JCheckBox>(model.getTypes().size());
    IconManager icons = IconManager.getInstance();
    fromDate = UIUtilities.createDatePicker(true, EditorUtil.DATE_PICKER_FORMAT);
    fromDate.setBackground(UIUtilities.BACKGROUND_COLOR);
    fromDate.addPropertyChangeListener("date", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Date d = (Date) evt.getNewValue();
            if (d != null) {
                if (d.after(new Date())) {
                    UserNotifier un = DataBrowserAgent.getRegistry().getUserNotifier();
                    un.notifyWarning("Invalid Date", "Selecting a future 'From' date doesn't make any sense.");
                    fromDate.setDate(null);
                }
                if (toDate.getDate() != null && d.after(toDate.getDate())) {
                    UserNotifier un = DataBrowserAgent.getRegistry().getUserNotifier();
                    un.notifyWarning("Invalid Date",
                            "Cannot set a 'From' date which is more recent than the 'To' date.");
                    fromDate.setDate(null);
                }
            }
        }
    });
    fromDate.setToolTipText(DATE_TOOLTIP);

    toDate = UIUtilities.createDatePicker(true, EditorUtil.DATE_PICKER_FORMAT);
    toDate.setBackground(UIUtilities.BACKGROUND_COLOR);
    toDate.setToolTipText(DATE_TOOLTIP);
    toDate.addPropertyChangeListener("date", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Date d = (Date) evt.getNewValue();
            if (d != null) {
                if (fromDate.getDate() != null && d.before(fromDate.getDate())) {
                    UserNotifier un = DataBrowserAgent.getRegistry().getUserNotifier();
                    un.notifyWarning("Invalid Date",
                            "Cannot set a 'To' date which is prior to the 'From' date.");
                    toDate.setDate(null);
                }
            }
        }
    });

    clearDate = new JButton(icons.getIcon(IconManager.CLOSE));
    clearDate.setToolTipText("Reset the dates");
    UIUtilities.unifiedButtonLookAndFeel(clearDate);
    clearDate.setBackground(UIUtilities.BACKGROUND_COLOR);
    clearDate.setActionCommand("" + SearchComponent.RESET_DATE);
    clearDate.addActionListener(model);

    fullTextArea = new JTextField(AREA_COLUMNS);
    fullTextArea.addKeyListener(new KeyAdapter() {

        /** Finds the phrase. */
        public void keyPressed(KeyEvent e) {
            Object source = e.getSource();
            if (source != fullTextArea)
                return;
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                model.search();
            }
        }
    });

    helpBasicButton = new JButton(icons.getIcon(IconManager.HELP));
    helpBasicButton.setToolTipText("Search Tips.");
    helpBasicButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    UIUtilities.unifiedButtonLookAndFeel(helpBasicButton);
    helpBasicButton.addActionListener(model);
    helpBasicButton.setActionCommand("" + SearchComponent.HELP);

    SearchContext ctx = model.getSearchContext();
    if (ctx == null)
        return;
}

From source file:de.xirp.plugin.ViewerBase.java

/**
 * If a property has changed the controls which are referenced by
 * this property are determined and the value of the property is
 * set to them. Controls which are already disposed are ignored.
 * //from   www  . jav  a  2 s  .  co m
 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
 */
@Override
public void propertyChange(PropertyChangeEvent event) {
    String propName = event.getPropertyName();
    String setterName = SET_PREFIX + StringUtils.capitalize(propName);

    List<Control> controls = setter.get(setterName);
    List<Control> delete = new ArrayList<Control>(controls.size());
    for (Control control : controls) {
        if (SWTUtil.swtAssert(control)) {
            Object value = event.getNewValue();
            // if the method returned something
            // update the ui with it
            if (value != null) {
                setValue(control, value);
            }
        } else {
            // mark disposed controls for deletion
            delete.add(control);
        }
    }
    // Delete disposed controls
    for (Control control : delete) {
        setter.remove(setterName, control);
    }
}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java

public void run_propertyChange(PropertyChangeEvent e) {
    clearChart();/*from   w ww  .j  a  va  2 s  .c  o  m*/
    MSRun run = (MSRun) e.getNewValue();
    ((SpinnerRunModel) scanSpinner.getModel()).setRun(run);
}