Example usage for java.beans PropertyChangeEvent getPropertyName

List of usage examples for java.beans PropertyChangeEvent getPropertyName

Introduction

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

Prototype

public String getPropertyName() 

Source Link

Document

Gets the programmatic name of the property that was changed.

Usage

From source file:org.eclipse.wb.internal.swing.customize.CustomizerAction.java

private void performCustomize0() throws Exception {
    Customizer customizer = m_customizerClass.newInstance();
    // prepare properties information
    final JavaInfoState javaInfoState = JavaInfoState.getState(m_javaInfo);
    boolean explicit = isExplicitPropertyChange(m_javaInfo);
    PropertyChangeListener propertyChangeListener = null;
    if (explicit) {
        propertyChangeListener = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                javaInfoState.changedProperties.add(event.getPropertyName());
                javaInfoState.changedPropertyValues.put(event.getPropertyName(), event.getNewValue());
            }/*from  ww w  .  j  av  a2 s. c  o  m*/
        };
        customizer.addPropertyChangeListener(propertyChangeListener);
    }
    //
    try {
        // open customizer dialog
        customizer.setObject(javaInfoState.object);
        AwtComponentDialog dialog = new AwtComponentDialog(DesignerPlugin.getDefault(), (Component) customizer,
                ModelMessages.CustomizerAction_dialogTitle, MessageFormat
                        .format(ModelMessages.CustomizerAction_dialogMessage, m_customizerClass.getName()));
        int dialogResult = dialog.open();
        // handle update properties
        if (dialogResult == Window.OK) {
            RunnableEx runnable = null;
            if (explicit) {
                // update changed properties
                runnable = new RunnableEx() {
                    public void run() throws Exception {
                        int size = javaInfoState.properties.size();
                        for (int i = 0; i < size; i++) {
                            Property property = javaInfoState.properties.get(i);
                            if (javaInfoState.changedProperties.contains(property.getTitle())) {
                                Object newValue = javaInfoState.changedPropertyValues.get(property.getTitle());
                                Object oldValue = javaInfoState.oldValues.get(i);
                                if (!ObjectUtils.equals(newValue, oldValue)) {
                                    property.setValue(newValue);
                                }
                            }
                        }
                    }
                };
            } else {
                // update all properties
                runnable = new RunnableEx() {
                    public void run() throws Exception {
                        int size = javaInfoState.properties.size();
                        for (int i = 0; i < size; i++) {
                            Object newValue = javaInfoState.getters.get(i).invoke(javaInfoState.object);
                            Object oldValue = javaInfoState.oldValues.get(i);
                            if (!ObjectUtils.equals(newValue, oldValue)) {
                                javaInfoState.properties.get(i).setValue(newValue);
                            }
                        }
                    }
                };
            }
            // run update
            ExecutionUtils.run(m_javaInfo, runnable);
        }
        // rollback property changes
        if (dialogResult == Window.CANCEL) {
            ExecutionUtils.run(m_javaInfo, new RunnableEx() {
                public void run() throws Exception {
                    int size = javaInfoState.properties.size();
                    for (int i = 0; i < size; i++) {
                        Object newValue = javaInfoState.getters.get(i).invoke(javaInfoState.object);
                        Object oldValue = javaInfoState.oldValues.get(i);
                        if (!ObjectUtils.equals(newValue, oldValue)) {
                            javaInfoState.setters.get(i).invoke(javaInfoState.object, oldValue);
                        }
                    }
                }
            });
        }
    } finally {
        if (propertyChangeListener != null) {
            customizer.removePropertyChangeListener(propertyChangeListener);
        }
    }
}

From source file:VASSAL.preferences.Prefs.java

public Prefs(PrefsEditor editor, String name) {
    this.editor = editor;
    this.name = name;
    this.changeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            changed.add(evt.getPropertyName());
        }//from ww  w.  j ava 2s.com
    };
    editor.addPrefs(this);
    init(name);
}

From source file:simulador.controle.GeradorGraficos.java

@Override
public void propertyChange(PropertyChangeEvent evt) {

    if (DEBUG) {//ww  w  .  j  a  v  a  2  s.  co m
        System.out.println("GeradorGraficos.propertyChange: " + evt.getPropertyName());
    }

    switch (evt.getPropertyName()) {

    case BarraFerramentas.BT_SELECAO:

        Map<Integer, Point> pontosRadios = new HashMap();

        Map<Integer, Boolean> valoresCheckbox = (Map) evt.getNewValue();
        Map<Integer, Radio2D> radios2D = painelDesign.getRadios2D();

        for (Map.Entry<Integer, Boolean> parCheckbox : valoresCheckbox.entrySet()) {
            System.out.println("parCheckbox[" + parCheckbox.getKey() + ", " + parCheckbox.getValue() + "]");

            if (parCheckbox.getValue()) {

                Radio2D r2D = radios2D.get(parCheckbox.getKey());
                Rectangle forma = (Rectangle) r2D.getForma();
                Point localizacao = new Point((int) forma.getCenterX(), (int) forma.getCenterY());
                System.out
                        .println("radioCheckBox - localizacao: (" + localizacao.x + ", " + localizacao.y + ")");
                pontosRadios.put(parCheckbox.getKey(), localizacao);

            }
        }

        //int[] coordCelPontoClicado = painelDesign.buscarCelula((Point) evt.getOldValue());
        //PainelDesign.Celula cel = painelDesign.getMapaCelulas().get(coordCelPontoClicado[0]).get(coordCelPontoClicado[1]);
        //Point pontoFinal = new Point(cel.x, cel.y);
        Point pontoClicado = (Point) evt.getOldValue();

        criarGraficoRadiais(pontosRadios, pontoClicado);

        break;

    }

}

From source file:MainWindow.java

public MainWindow() {
    // Login Routine
    loginDialog = new LoginDialog();
    // loginDialog.nameField.setText("cornelius.preidel@googlemail.com");
    // loginDialog.passwordField.setText("germany");
    loginDialog.setSize(400, 150);/*from   w  w w.j  a  va 2 s  .  co m*/
    loginDialog.setModal(true);
    loginDialog.setLocationRelativeTo(null);
    loginDialog.setVisible(true);

    // Get the connected ApiCore
    core = loginDialog._core;

    // Init the UI
    mainFrame = new JFrame("MainApplication");
    mainFrame.setSize(500, 500);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setLayout(new GridLayout(5, 1));

    // WebProjectsList webprojectlist = new WebProjectsList(core);
    // mainFrame.add(webprojectlist);

    // Create the APIS
    Teams teamsAPI = new Teams(core);
    final Projects projectsAPI = new Projects(core);
    final Divisions divisionsAPI = new Divisions(core);
    final Attachments attachmentAPI = new Attachments(core);
    final Issues issueAPI = new Issues(core);

    // TEAMS List
    TeamsList teamList = new TeamsList();
    teamList.setTeams(teamsAPI.GetTeams());
    mainFrame.add(teamList);

    // PROJECTS  List
    projectsList = new ProjectsList();
    mainFrame.add(projectsList);

    // DIVISIONS List
    divisionsList = new DivisionsList();
    // mainFrame.add(divisionsList);

    // DIVISIONS Table
    divisionsTable = new DivisionsTable(core);
    mainFrame.add(divisionsTable);

    // Attachments
    attachmentsList = new AttachmentsList();
    mainFrame.add(attachmentsList);

    // Attachments
    issuesList = new IssuesList();
    mainFrame.add(issuesList);

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            String property = propertyChangeEvent.getPropertyName();
            if ("selectedTeam".equals(property)) {
                DtoTeam selectedTeam = (DtoTeam) propertyChangeEvent.getNewValue();

                // Set the global slug
                core.currentTeam = selectedTeam;
                projectsList.setProjects(projectsAPI.GetProjects());
            } else if ("selectedProject".equals(property)) {
                DtoProject selectedProject = (DtoProject) propertyChangeEvent.getNewValue();
                // Divisions
                divisionsList.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                divisionsTable.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                // Attachments
                attachmentsList.setAttachments(attachmentAPI.GetAttachments(selectedProject.GetId()));
                // Issues
                issuesList.setIssues(issueAPI.GetIssues(selectedProject.GetId()));
            } else if ("selectedDivision".equals(property)) {
                DtoDivision selectedDivision = (DtoDivision) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else if ("selectedIssue".equals(property)) {
                DtoIssue selectedDivision = (DtoIssue) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else {
                if ("selectedAttachment".equals(property)) {
                    DtoAttachment selectedAttachment = (DtoAttachment) propertyChangeEvent.getNewValue();
                    InputStream stream = attachmentAPI.DownloadAttachment(selectedAttachment.GetId());

                    try {
                        byte[] bytes = IOUtils.toByteArray(stream);
                        JFileChooser chooser = new JFileChooser();
                        int returnVal = chooser.showSaveDialog(chooser);
                        File file = chooser.getSelectedFile();

                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write(bytes);
                        fos.flush();
                        fos.close();
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
        }
    };

    // Add Listener
    teamList.addPropertyChangeListener(propertyChangeListener);
    projectsList.addPropertyChangeListener(propertyChangeListener);
    divisionsList.addPropertyChangeListener(propertyChangeListener);
    divisionsTable.addPropertyChangeListener(propertyChangeListener);
    attachmentsList.addPropertyChangeListener(propertyChangeListener);
    issuesList.addPropertyChangeListener(propertyChangeListener);
}

From source file:org.eclipse.php.composer.ui.editor.composer.RepositoriesSection.java

@Override
public void propertyChange(PropertyChangeEvent e) {
    if (e.getPropertyName().startsWith("repositories")) { //$NON-NLS-1$
        refresh();/* w  ww  . jav  a 2s. c o m*/
    }
}

From source file:com.architexa.diagrams.relo.jdt.parts.CompartmentedCodeUnitEditPart.java

private CompartmentCUEditPart realizeCompartment(Resource compartmentType) {
    // create the compartments
    final CompartmentCodeUnit ccu = generateCompartment(compartmentType, getCU());
    ccu.registerTypes(compartmentMap);/*w  w w  . j ava  2s  .c o  m*/

    // install any needed policies
    ArtifactFragment compAF = getRootController().getRootArtifact().getArtifact(ccu);

    // initialize the compartments
    getArtifact().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            ccu.firePropChang(evt.getPropertyName());
            String propName = evt.getPropertyName();
            if (ArtifactFragment.Policy_Contents_Changed.equals(propName)) {
                colorFigure(ColorDPolicy.getColor(getCU()));
            }
        }
    });

    // update children
    this.refreshChildren();

    CompartmentCUEditPart cep = (CompartmentCUEditPart) getRootController().findArtifactEditPart(compAF);

    final IFigure classFigure = (IFigure) CompartmentedCodeUnitEditPart.super.getFigure().getChildren().get(0);
    if (classFigure != null)
        NonEmptyFigureSupport.listenToModel(getArtFrag(), ((CodeUnitFigure) classFigure).nonEmptyFigure);
    return cep;
}

From source file:org.eclipse.php.composer.api.entities.JsonEntity.java

protected void listen() {
    try {//from   w w w  . ja v a  2s. co  m
        for (Field field : getFields(this.getClass())) {
            if (JsonCollection.class.isAssignableFrom(field.getType())) {
                final String prop = getFieldName(field);
                final JsonEntity sender = this;

                if (listening.contains(prop)) {
                    continue;
                }

                field.setAccessible(true);
                JsonEntity obj = (JsonEntity) field.get(this);

                if (obj != null) {
                    obj.addPropertyChangeListener(new PropertyChangeListener() {
                        public void propertyChange(PropertyChangeEvent e) {
                            firePropertyChange(prop + "." + e.getPropertyName(), e.getOldValue(), //$NON-NLS-1$
                                    e.getNewValue());

                            // append to sort order - use reflection
                            if (sender instanceof AbstractJsonObject) {
                                try {
                                    Method mtd = JsonEntity.class.getDeclaredMethod("appendSortOrder", //$NON-NLS-1$
                                            String.class);
                                    mtd.setAccessible(true);
                                    mtd.invoke(sender, prop);
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }
                            }
                        }
                    });

                    listening.add(prop);
                }
            }
        }
    } catch (Exception e) {
        log.error(e);
    }
}

From source file:de.fhg.igd.swingrcp.ActionAdapter.java

/**
 * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
 *///from www .j  a  v  a2 s.c o  m
@Override
public void propertyChange(final PropertyChangeEvent evt) {
    // propagate property change event
    // -> enabled
    if (evt.getPropertyName().equals("enabled"))
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                firePropertyChange(Action.ENABLED, evt.getOldValue(), evt.getNewValue());
            }

        });
}

From source file:core.reporting.ImportFromFile.java

@Override
public void propertyChange(PropertyChangeEvent evt) {
    Object nval = evt.getNewValue();
    String prp = evt.getPropertyName();
    if (prp.equals(TConstants.FILE_SELECTED)) {
        csvInputFile = (File) evt.getNewValue();
        validateCSVFile();//  ww  w  .ja va 2 s  . c o  m
    }
    if (nval == saveAction) {
        importCSVRecors();
    }
}

From source file:org.datacleaner.widgets.OpenAnalysisJobFileChooserAccessory.java

@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
        _file = _fileChooser.getSelectedFileObject();
        if (_file != null && _file.getName().getBaseName().endsWith(FileFilters.ANALYSIS_XML.getExtension())) {
            showFileInformation();//w w  w.  j a v a2s .  c o  m
        } else {
            setVisible(false);
        }
    }
}