Ignore:
Timestamp:
23.06.2009 22:03:37 (3 years ago)
Author:
Gubaer
Message:

new: MultiFetchServerObjectReader using APIs Multi Fetch method
update: now uses Multi Fetch to check for deleted primitives on the server
update: now uses Multi Fetch to update the selected primitives with the state from the server
fixed: cleaned up merging in MergeVisitor
new: conflict resolution dialog; now resolves conflicts due to different visibilities
new: replacement for realEqual() on OsmPrimitive and derived classes; realEqual now @deprecated
fixed: cleaning up OsmReader
fixed: progress indication in OsmApi

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/properties/PropertiesMerger.java

    r1676 r1690  
    1818import javax.swing.JButton; 
    1919import javax.swing.JLabel; 
     20import javax.swing.JOptionPane; 
    2021import javax.swing.JPanel; 
    21  
     22import javax.swing.SwingUtilities; 
     23 
     24import org.openstreetmap.josm.Main; 
    2225import org.openstreetmap.josm.data.coor.LatLon; 
     26import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 
    2327import org.openstreetmap.josm.gui.conflict.MergeDecisionType; 
    2428import org.openstreetmap.josm.tools.ImageProvider; 
     
    4852    private JLabel lblTheirDeletedState; 
    4953 
     54    private JLabel lblMyVisibleState; 
     55    private JLabel lblMergedVisibleState; 
     56    private JLabel lblTheirVisibleState; 
     57 
    5058    private final PropertiesMergeModel model; 
    5159 
     
    5967    } 
    6068 
    61     protected void build() { 
    62         setLayout(new GridBagLayout()); 
     69    protected void buildHeaderRow() { 
    6370        GridBagConstraints gc = new GridBagConstraints(); 
    6471 
    65         // ------------------ 
    6672        gc.gridx = 1; 
    6773        gc.gridy = 0; 
     
    8894        lblTheirVersion.setToolTipText(tr("Properties in their dataset, i.e. the server dataset")); 
    8995        add(lblTheirVersion, gc); 
    90  
    91         // -------------------------------- 
     96    } 
     97 
     98    protected void buildCoordinateConflictRows() { 
     99        GridBagConstraints gc = new GridBagConstraints(); 
     100 
    92101        gc.gridx = 0; 
    93102        gc.gridy = 1; 
     
    161170        JButton btnUndecideCoordinates = new JButton(actUndecideCoordinates); 
    162171        add(btnUndecideCoordinates, gc); 
    163         // --------------------------------------------------- 
     172    } 
     173 
     174    protected void buildDeletedStateConflictRows() { 
     175        GridBagConstraints gc = new GridBagConstraints(); 
    164176 
    165177        gc.gridx = 0; 
     
    191203        model.addObserver(actKeepMyDeletedState); 
    192204        JButton btnKeepMyDeletedState = new JButton(actKeepMyDeletedState); 
    193         btnKeepMyCoordinates.setName("button.keepmydeletedstate"); 
     205        btnKeepMyDeletedState.setName("button.keepmydeletedstate"); 
    194206        add(btnKeepMyDeletedState, gc); 
    195207 
     
    212224        model.addObserver(actKeepTheirDeletedState); 
    213225        JButton btnKeepTheirDeletedState = new JButton(actKeepTheirDeletedState); 
    214         btnKeepMyCoordinates.setName("button.keeptheirdeletedstate"); 
     226        btnKeepTheirDeletedState.setName("button.keeptheirdeletedstate"); 
    215227        add(btnKeepTheirDeletedState, gc); 
    216228 
     
    233245        model.addObserver(actUndecideDeletedState); 
    234246        JButton btnUndecideDeletedState = new JButton(actUndecideDeletedState); 
    235         btnKeepMyCoordinates.setName("button.undecidedeletedstate"); 
     247        btnUndecideDeletedState.setName("button.undecidedeletedstate"); 
    236248        add(btnUndecideDeletedState, gc); 
    237  
     249    } 
     250 
     251    protected void buildVisibleStateRows() { 
     252        GridBagConstraints gc = new GridBagConstraints(); 
     253 
     254        gc.gridx = 0; 
     255        gc.gridy = 5; 
     256        gc.gridwidth = 1; 
     257        gc.gridheight = 1; 
     258        gc.fill = GridBagConstraints.BOTH; 
     259        gc.anchor = GridBagConstraints.LINE_START; 
     260        gc.weightx = 0.0; 
     261        gc.weighty = 0.0; 
     262        gc.insets = new Insets(0,5,0,5); 
     263        add(new JLabel(tr("Visible State:")), gc); 
     264 
     265        gc.gridx = 1; 
     266        gc.gridy = 5; 
     267        gc.fill = GridBagConstraints.BOTH; 
     268        gc.anchor = GridBagConstraints.CENTER; 
     269        gc.weightx = 0.33; 
     270        gc.weighty = 0.0; 
     271        add(lblMyVisibleState = buildValueLabel("label.myvisiblestate"), gc); 
     272 
     273        gc.gridx = 2; 
     274        gc.gridy = 5; 
     275        gc.fill = GridBagConstraints.NONE; 
     276        gc.anchor = GridBagConstraints.CENTER; 
     277        gc.weightx = 0.0; 
     278        gc.weighty = 0.0; 
     279        KeepMyVisibleStateAction actKeepMyVisibleState = new KeepMyVisibleStateAction(); 
     280        model.addObserver(actKeepMyVisibleState); 
     281        JButton btnKeepMyVisibleState = new JButton(actKeepMyVisibleState); 
     282        btnKeepMyVisibleState.setName("button.keepmyvisiblestate"); 
     283        add(btnKeepMyVisibleState, gc); 
     284 
     285        gc.gridx = 3; 
     286        gc.gridy = 5; 
     287        gc.fill = GridBagConstraints.BOTH; 
     288        gc.anchor = GridBagConstraints.CENTER; 
     289        gc.weightx = 0.33; 
     290        gc.weighty = 0.0; 
     291        add(lblMergedVisibleState = buildValueLabel("label.mergedvisiblestate"), gc); 
     292 
     293        gc.gridx = 4; 
     294        gc.gridy = 5; 
     295        gc.fill = GridBagConstraints.NONE; 
     296        gc.anchor = GridBagConstraints.CENTER; 
     297        gc.weightx = 0.0; 
     298        gc.weighty = 0.0; 
     299        KeepTheirVisibleStateAction actKeepTheirVisibleState = new KeepTheirVisibleStateAction(); 
     300        model.addObserver(actKeepTheirVisibleState); 
     301        JButton btnKeepTheirVisibleState = new JButton(actKeepTheirVisibleState); 
     302        btnKeepTheirVisibleState.setName("button.keeptheirvisiblestate"); 
     303        add(btnKeepTheirVisibleState, gc); 
     304 
     305        gc.gridx = 5; 
     306        gc.gridy = 5; 
     307        gc.fill = GridBagConstraints.BOTH; 
     308        gc.anchor = GridBagConstraints.CENTER; 
     309        gc.weightx = 0.33; 
     310        gc.weighty = 0.0; 
     311        add(lblTheirVisibleState = buildValueLabel("label.theirvisiblestate"), gc); 
     312 
     313        // --------------------------------------------------- 
     314        gc.gridx = 3; 
     315        gc.gridy = 6; 
     316        gc.fill = GridBagConstraints.NONE; 
     317        gc.anchor = GridBagConstraints.CENTER; 
     318        gc.weightx = 0.0; 
     319        gc.weighty = 0.0; 
     320        UndecideVisibleStateConflictAction actUndecideVisibleState = new UndecideVisibleStateConflictAction(); 
     321        model.addObserver(actUndecideVisibleState); 
     322        JButton btnUndecideVisibleState = new JButton(actUndecideVisibleState); 
     323        btnUndecideVisibleState.setName("button.undecidevisiblestate"); 
     324        add(btnUndecideVisibleState, gc); 
     325    } 
     326 
     327    protected void build() { 
     328        setLayout(new GridBagLayout()); 
     329        buildHeaderRow(); 
     330        buildCoordinateConflictRows(); 
     331        buildDeletedStateConflictRows(); 
     332        buildVisibleStateRows(); 
    238333    } 
    239334 
     
    265360    } 
    266361 
    267     protected void updateCoordiates() { 
     362    public String visibleStateToString(Boolean visible) { 
     363        if (visible == null) 
     364            return tr("(none)"); 
     365        if (visible) 
     366            return tr("visible (on the server)"); 
     367        else 
     368            return tr("not visible (on the server)"); 
     369    } 
     370 
     371    public String visibleStateToStringMerged(Boolean visible) { 
     372        if (visible == null) 
     373            return tr("(none)"); 
     374        if (visible) 
     375            return tr("Keep a clone of the local version"); 
     376        else 
     377            return tr("Physically delete from local dataset"); 
     378    } 
     379 
     380    protected void updateCoordinates() { 
    268381        lblMyCoordinates.setText(coordToString(model.getMyCoords())); 
    269382        lblMergedCoordinates.setText(coordToString(model.getMergedCoords())); 
     
    320433    } 
    321434 
     435    protected void updateVisibleState() { 
     436        lblMyVisibleState.setText(visibleStateToString(model.getMyVisibleState())); 
     437        lblMergedVisibleState.setText(visibleStateToStringMerged(model.getMergedVisibleState())); 
     438        lblTheirVisibleState.setText(visibleStateToString(model.getTheirVisibleState())); 
     439 
     440        if (! model.hasVisibleStateConflict()) { 
     441            lblMyVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 
     442            lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 
     443            lblTheirVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 
     444        } else { 
     445            if (!model.isDecidedVisibleState()) { 
     446                lblMyVisibleState.setBackground(BGCOLOR_UNDECIDED); 
     447                lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 
     448                lblTheirVisibleState.setBackground(BGCOLOR_UNDECIDED); 
     449            } else { 
     450                lblMyVisibleState.setBackground( 
     451                        model.isVisibleStateDecision(MergeDecisionType.KEEP_MINE) 
     452                        ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT 
     453                ); 
     454                lblMergedVisibleState.setBackground(BGCOLOR_DECIDED); 
     455                lblTheirVisibleState.setBackground( 
     456                        model.isVisibleStateDecision(MergeDecisionType.KEEP_THEIR) 
     457                        ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT 
     458                ); 
     459            } 
     460        } 
     461    } 
     462 
    322463    public void update(Observable o, Object arg) { 
    323         updateCoordiates(); 
     464        updateCoordinates(); 
    324465        updateDeletedState(); 
     466        updateVisibleState(); 
    325467    } 
    326468 
     
    418560        } 
    419561    } 
     562 
     563    class KeepMyVisibleStateAction extends AbstractAction implements Observer { 
     564        public KeepMyVisibleStateAction() { 
     565            putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine")); 
     566            putValue(Action.SHORT_DESCRIPTION, tr("Keep my visible state")); 
     567        } 
     568 
     569        public void actionPerformed(ActionEvent e) { 
     570            if (confirmKeepMine()) { 
     571                model.decideVisibleStateConflict(MergeDecisionType.KEEP_MINE); 
     572            } 
     573        } 
     574 
     575        public void update(Observable o, Object arg) { 
     576            setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState()); 
     577        } 
     578 
     579        protected boolean confirmKeepMine() { 
     580            String [] options = { 
     581                    tr("Yes, reset the id"), 
     582                    tr("No, abort") 
     583            }; 
     584            int ret = JOptionPane.showOptionDialog( 
     585                    null, 
     586                    tr("<html>To keep your local version, JOSM<br>" 
     587                            + "has to reset the id of {0} {1} to 0.<br>" 
     588                            + "On the next upload the server will assign<br>" 
     589                            + "it a new id.<br>" 
     590                            + "Do yo agree?</html>", 
     591                            OsmPrimitiveType.from(model.getMyPrimitive()).getLocalizedDisplayNamePlural(), 
     592                            model.getMyPrimitive().id 
     593                    ), 
     594                    tr("Reset id to 0"), 
     595                    JOptionPane.YES_NO_OPTION, 
     596                    JOptionPane.QUESTION_MESSAGE, 
     597                    null, 
     598                    options, 
     599                    options[1] 
     600            ); 
     601            return ret == JOptionPane.YES_OPTION; 
     602        } 
     603    } 
     604 
     605    class KeepTheirVisibleStateAction extends AbstractAction implements Observer { 
     606        public KeepTheirVisibleStateAction() { 
     607            putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir")); 
     608            putValue(Action.SHORT_DESCRIPTION, tr("Keep their visible state")); 
     609        } 
     610 
     611        public void actionPerformed(ActionEvent e) { 
     612            if (confirmKeepTheir()){ 
     613                model.decideVisibleStateConflict(MergeDecisionType.KEEP_THEIR); 
     614            } 
     615        } 
     616 
     617        public void update(Observable o, Object arg) { 
     618            setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState()); 
     619        } 
     620 
     621        protected boolean confirmKeepTheir() { 
     622            String [] options = { 
     623                    tr("Yes, purge it"), 
     624                    tr("No, abort") 
     625            }; 
     626            int ret = JOptionPane.showOptionDialog( 
     627                    null, 
     628                    tr("<html>JOSM will have to remove your local primitive with id {0}<br>" 
     629                            + "from the dataset.<br>" 
     630                            + "Do you agree?</html>", 
     631                            model.getMyPrimitive().id 
     632                    ), 
     633                    tr("Remove from dataset"), 
     634                    JOptionPane.YES_NO_OPTION, 
     635                    JOptionPane.QUESTION_MESSAGE, 
     636                    null, 
     637                    options, 
     638                    options[1] 
     639            ); 
     640            return ret == JOptionPane.YES_OPTION; 
     641        } 
     642    } 
     643 
     644    class UndecideVisibleStateConflictAction extends AbstractAction implements Observer { 
     645        public UndecideVisibleStateConflictAction() { 
     646            putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide")); 
     647            putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between visible state")); 
     648        } 
     649 
     650        public void actionPerformed(ActionEvent e) { 
     651            model.decideVisibleStateConflict(MergeDecisionType.UNDECIDED); 
     652        } 
     653 
     654        public void update(Observable o, Object arg) { 
     655            setEnabled(model.hasVisibleStateConflict() && model.isDecidedVisibleState()); 
     656        } 
     657    } 
    420658} 
Note: See TracChangeset for help on using the changeset viewer.