Index: /applications/editors/josm/plugins/relcontext/TODO
===================================================================
--- /applications/editors/josm/plugins/relcontext/TODO	(revision 25708)
+++ /applications/editors/josm/plugins/relcontext/TODO	(revision 25709)
@@ -9,9 +9,6 @@
 - Break touching rings of multipolygons
 - Option to create separate multipolygon for every outer ring
-- Solve multipolygon settings button width problem
 - Solve width problem for narrows buttons when "fix" and "download" appear simultaneously
 - Sort relation members button (now it's just role fixer)
-- Show role panel only when relation members are selected
-- Rethink role panel. Maybe, replace chosen relation title with role combobox?
 
 == RELEASE ==
Index: /applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
===================================================================
--- /applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java	(revision 25708)
+++ /applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java	(revision 25709)
@@ -30,5 +30,4 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.command.ChangeCommand;
 import org.openstreetmap.josm.data.SelectionChangedListener;
 import org.openstreetmap.josm.data.osm.Relation;
@@ -47,5 +46,4 @@
 import org.openstreetmap.josm.command.ChangeRelationMemberRoleCommand;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
-import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
 import static org.openstreetmap.josm.tools.I18n.tr;
 
@@ -58,5 +56,4 @@
 
     public final static String PREF_PREFIX = "reltoolbox";
-    private static final String PREF_ROLEBOX = PREF_PREFIX + ".rolebox";
 
     private final DefaultTableModel relationsData;
@@ -65,7 +62,5 @@
     private ChosenRelationPopupMenu popupMenu;
     private MultipolygonSettingsPopup multiPopupMenu;
-    private JLabel crRoleIndicator;
     private RoleComboBoxModel roleBoxModel;
-    private String lastSelectedRole;
 
     public RelContextDialog() {
@@ -90,68 +85,46 @@
         rcPanel.add(new JScrollPane(relationsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
 
-        chosenRelationPanel = new JPanel(new BorderLayout());
-
-        // [^] roles [new role][V][Apply]
-        final JPanel rolePanel = new JPanel(new GridBagLayout());
-        final JButton toggleRolePanelButtonTop = new JButton(new TogglePanelAction(rolePanel) {
-            @Override
-            protected void init() {
-                putValue(Action.SMALL_ICON, ImageProvider.get("svpDown"));
-                putValue(Action.SHORT_DESCRIPTION, tr("Show role panel"));
-            }
-        });
-        final JButton toggleRolePanelButtonIn = new JButton(new TogglePanelAction(rolePanel) {
-            @Override
-            protected void init() {
-                putValue(Action.SMALL_ICON, ImageProvider.get("svpUp"));
-                putValue(Action.SHORT_DESCRIPTION, tr("Hide role panel"));
-            }
-        });
-        rolePanel.add(sizeButton(toggleRolePanelButtonIn, 16, 20), GBC.std());
-        crRoleIndicator = new JLabel();
-        rolePanel.add(crRoleIndicator, GBC.std().insets(5, 0, 5, 0));
-        roleBoxModel = new RoleComboBoxModel();
-        JComboBox roleBox = new JComboBox(roleBoxModel);
-        rolePanel.add(roleBox, GBC.std().fill(GBC.HORIZONTAL));
-        rolePanel.add(sizeButton(new JButton(new ApplyNewRoleAction()), 40, 20), GBC.std());
-        rolePanel.add(sizeButton(new JButton(new EnterNewRoleAction()), 40, 20), GBC.eol());
-//        rolePanel.setVisible(false); // todo: take from preferences
+        final MouseListener relationMouseAdapter = new ChosenRelationMouseAdapter();
+        final JComboBox roleBox = new JComboBox();
+        roleBoxModel = new RoleComboBoxModel(roleBox);
+        roleBox.setModel(roleBoxModel);
+        roleBox.addMouseListener(relationMouseAdapter);
+        roleBox.addItemListener(new ItemListener() {
+            public void itemStateChanged( ItemEvent e ) {
+                if( e.getStateChange() == ItemEvent.DESELECTED ) return;
+                String memberRole = roleBoxModel.getSelectedMembersRole();
+                String selectedRole = roleBoxModel.isAnotherRoleSelected() ? askForRoleName() : roleBoxModel.getSelectedRole();
+                if( memberRole != null && selectedRole != null && !memberRole.equals(selectedRole) ) {
+                    applyRoleToSelection(selectedRole.trim());
+                }
+            }
+        });
+        roleBox.setVisible(false);
 
         // [±][X] relation U [AZ][Down][Edit]
-        JPanel topLine = new JPanel(new GridBagLayout());
-        topLine.add(new JButton(new AddRemoveMemberAction(chosenRelation)), GBC.std());
-        topLine.add(sizeButton(toggleRolePanelButtonTop, 16, 24), GBC.std());
-        topLine.add(sizeButton(new JButton(new ClearChosenRelationAction(chosenRelation)), 32, 0), GBC.std());
+        chosenRelationPanel = new JPanel(new GridBagLayout());
+        chosenRelationPanel.add(new JButton(new AddRemoveMemberAction(chosenRelation)), GBC.std());
+        chosenRelationPanel.add(sizeButton(new JButton(new ClearChosenRelationAction(chosenRelation)), 32, 0), GBC.std());
         final ChosenRelationComponent chosenRelationComponent = new ChosenRelationComponent(chosenRelation);
-        chosenRelationComponent.addMouseListener(new ChosenRelationMouseAdapter());
-        topLine.add(chosenRelationComponent, GBC.std().fill().insets(5, 0, 5, 0));
+        chosenRelationComponent.addMouseListener(relationMouseAdapter);
+        chosenRelationPanel.add(chosenRelationComponent, GBC.std().fill().insets(5, 0, 5, 0));
+        chosenRelationPanel.add(roleBox, GBC.std().fill().insets(5, 0, 5, 0));
         final Action sortAndFixAction = new SortAndFixAction(chosenRelation);
         final JButton sortAndFixButton = (JButton) sizeButton(new JButton(sortAndFixAction), 32, 24);
-        topLine.add(sortAndFixButton, GBC.std());
+        chosenRelationPanel.add(sortAndFixButton, GBC.std());
         final Action downloadChosenRelationAction = new DownloadChosenRelationAction(chosenRelation);
         final JButton downloadButton = (JButton) sizeButton(new JButton(downloadChosenRelationAction), 32, 24);
-        topLine.add(downloadButton, GBC.std());
-        topLine.add(new JButton(new EditChosenRelationAction(chosenRelation)), GBC.eol().fill(GBC.VERTICAL));
-
-        chosenRelationPanel.add(topLine, BorderLayout.CENTER);
-        chosenRelationPanel.add(rolePanel, BorderLayout.SOUTH);
+        chosenRelationPanel.add(downloadButton, GBC.std());
+        chosenRelationPanel.add(new JButton(new EditChosenRelationAction(chosenRelation)), GBC.eol().fill(GBC.VERTICAL));
+
         rcPanel.add(chosenRelationPanel, BorderLayout.NORTH);
 
-        rolePanel.addComponentListener(new ComponentAdapter() {
-            @Override
-            public void componentHidden( ComponentEvent e ) {
-                Main.pref.put(PREF_ROLEBOX + ".visible", false);
-                toggleRolePanelButtonTop.setVisible(true);
-            }
-
-            @Override
-            public void componentShown( ComponentEvent e ) {
-                Main.pref.put(PREF_ROLEBOX + ".visible", true);
-                toggleRolePanelButtonTop.setVisible(false);
-            }
-        });
-        rolePanel.setVisible(Main.pref.getBoolean(PREF_ROLEBOX + ".visible", true));
-        toggleRolePanelButtonTop.setVisible(!rolePanel.isVisible());
-        lastSelectedRole = Main.pref.get(PREF_ROLEBOX + ".lastrole");
+        roleBox.addPropertyChangeListener("enabled", new PropertyChangeListener() {
+            public void propertyChange( PropertyChangeEvent evt ) {
+                boolean showRoleBox = roleBox.isEnabled();
+                roleBox.setVisible(showRoleBox);
+                chosenRelationComponent.setVisible(!showRoleBox);
+            }
+        });
 
         sortAndFixAction.addPropertyChangeListener(new PropertyChangeListener() {
@@ -277,27 +250,6 @@
         if( Main.main.getCurrentDataSet() != null )
             selectionChanged(Main.main.getCurrentDataSet().getSelected());
-        updateRoleIndicator();
         roleBoxModel.update();
         // ?
-    }
-
-    private void updateRoleIndicator() {
-        if( crRoleIndicator == null )
-            return;
-        String role = "";
-        if( chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) {
-            Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();
-            for( RelationMember m : chosenRelation.get().getMembers() ) {
-                if( selected.contains(m.getMember()) ) {
-                    if( role.length() == 0 && m.getRole() != null )
-                        role = m.getRole();
-                    else if( !role.equals(m.getRole()) ) {
-                        role = tr("<different>");
-                        break;
-                    }
-                }
-            }
-        }
-        crRoleIndicator.setText(role);
     }
 
@@ -305,5 +257,4 @@
         if( !isVisible() || relationsData == null )
             return;
-        updateRoleIndicator();
         roleBoxModel.update();
         // repopulate relations table
@@ -431,4 +382,5 @@
         @Override
         public void mouseClicked( MouseEvent e ) {
+            if( e.isControlDown() || !(e.getComponent() instanceof JComboBox ) ) // do not use left click handler on combo box
             if( SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main.map.mapView.getEditLayer() != null ) {
                 Main.map.mapView.getEditLayer().data.setSelected(chosenRelation.get());
@@ -456,4 +408,5 @@
         public ChosenRelationPopupMenu() {
             add(new SelectMembersAction(chosenRelation));
+            add(new SelectRelationAction(chosenRelation));
             add(new DeleteChosenRelationAction(chosenRelation));
             add(new DownloadParentsAction(chosenRelation));
@@ -461,23 +414,4 @@
             add(new SelectInRelationPanelAction(chosenRelation));
             add(new RelationHelpAction(chosenRelation));
-        }
-    }
-
-    private class TogglePanelAction extends AbstractAction {
-        private JComponent component;
-
-        public TogglePanelAction( JPanel panel ) {
-            super();
-            this.component = panel;
-            init();
-            if( getValue(Action.SMALL_ICON) == null )
-                putValue(Action.NAME, "R");
-        }
-
-        protected void init() {}
-
-        public void actionPerformed( ActionEvent e ) {
-            Main.pref.put(PREF_ROLEBOX + ".visible", !component.isVisible());
-            component.setVisible(!component.isVisible());
         }
     }
@@ -504,32 +438,4 @@
     }
 
-    private class ApplyNewRoleAction extends AbstractAction {
-        public ApplyNewRoleAction() {
-            super(null, ImageProvider.get("apply"));
-            putValue(Action.SHORT_DESCRIPTION, tr("Apply chosen role to selected relation members"));
-        }
-
-        public void actionPerformed( ActionEvent e ) {
-            String selectedRole = roleBoxModel.getSelectedRole();
-            if( selectedRole != null )
-                applyRoleToSelection(selectedRole.toString().trim());
-        }
-    }
-
-    private class EnterNewRoleAction extends AbstractAction {
-        public EnterNewRoleAction() {
-            super();
-            putValue(Action.NAME, "…");
-//            putValue(SMALL_ICON, ImageProvider.get("dialogs/mappaint", "pencil"));
-            putValue(SHORT_DESCRIPTION, tr("Enter new role for selected relation members"));
-        }
-
-        public void actionPerformed( ActionEvent e ) {
-            String role = askForRoleName();
-            if( role != null )
-                applyRoleToSelection(role);
-        }
-    }
-
     private static class RelationTableModel extends DefaultTableModel {
         @Override
@@ -590,14 +496,26 @@
         private List<String> roles = new ArrayList<String>();
         private int selectedIndex = -1;
-
-        public RoleComboBoxModel() {
+        private JComboBox combobox;
+        private String membersRole;
+        private final String EMPTY_ROLE = tr("<empty>");
+        private final String ANOTHER_ROLE = tr("another...");
+
+        public RoleComboBoxModel( JComboBox combobox ) {
             super();
+            this.combobox = combobox;
             update();
         }
 
         public void update() {
-            String currentRole = getSelectedRole();
+            membersRole = getSelectedMembersRoleIntl();
+            if( membersRole == null ) {
+                if( combobox.isEnabled() )
+                    combobox.setEnabled(false);
+                return;
+            }
+            if( !combobox.isEnabled() )
+                combobox.setEnabled(true);
+
             List<String> items = new ArrayList<String>();
-            items.add(" ");
             if( chosenRelation != null && chosenRelation.get() != null ) {
                 if( chosenRelation.isMultipolygon() ) {
@@ -611,16 +529,44 @@
                 }
                 for( RelationMember m : chosenRelation.get().getMembers() )
-                    if( !items.contains(m.getRole()) )
+                    if( m.getRole().length() > 0 && !items.contains(m.getRole()) )
                         items.add(m.getRole());
             }
-            if( currentRole != null && currentRole.length() > 1 ) {
-                lastSelectedRole = currentRole;
-                Main.pref.put(PREF_ROLEBOX + ".lastrole", lastSelectedRole);
-            }
+            items.add(EMPTY_ROLE);
+            if( !items.contains(membersRole) )
+                items.add(0, membersRole);
+            items.add(ANOTHER_ROLE);
             roles = Collections.unmodifiableList(items);
-            fireContentsChanged(this, 0, getSize());
-            if( lastSelectedRole != null && items.contains(lastSelectedRole) )
-                setSelectedItem(lastSelectedRole);
-            // todo: do we really want empty role as default one? Maybe, store last selected role in preferences
+
+            if( membersRole != null )
+                setSelectedItem(membersRole);
+            else
+                fireContentsChanged(this, -1, -1);
+            combobox.repaint();
+        }
+
+        public String getSelectedMembersRole() {
+            return membersRole == EMPTY_ROLE ? "" : membersRole;
+        }
+
+        public boolean isAnotherRoleSelected() {
+            return getSelectedRole() != null && getSelectedRole().equals(ANOTHER_ROLE);
+        }
+
+        private String getSelectedMembersRoleIntl() {
+            String role = null;
+            if( chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) {
+                Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();
+                for( RelationMember m : chosenRelation.get().getMembers() ) {
+                    if( selected.contains(m.getMember()) ) {
+                        if( role == null )
+                            role = m.getRole();
+                        else if( m.getRole() != null && !role.equals(m.getRole()) ) {
+                            role = tr("<different>");
+                            break;
+                        }
+                    }
+                }
+            }
+            return role == null ? null : role.length() == 0 ? EMPTY_ROLE : role;
         }
 
@@ -642,13 +588,18 @@
 
         public void setSelectedItem( Object anItem ) {
-            selectedIndex = anItem == null ? -1 : roles.indexOf(anItem);
+            int newIndex = anItem == null ? -1 : roles.indexOf(anItem);
+            if( newIndex != selectedIndex ) {
+                selectedIndex = newIndex;
+                fireContentsChanged(this, -1, -1);
+            }
         }
 
         public Object getSelectedItem() {
-            return getSelectedRole();
+            return selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex);
         }
 
         public String getSelectedRole() {
-            return selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex);
+            String role = selectedIndex < 0 || selectedIndex >= getSize() ? null : getRole(selectedIndex);
+            return role != null && role.equals(EMPTY_ROLE) ? "" : role;
         }
     }
Index: /applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java
===================================================================
--- /applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java	(revision 25708)
+++ /applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java	(revision 25709)
@@ -69,12 +69,12 @@
             for( Way w : poly.ways )
                 rel.addMember(new RelationMember("inner", w));
-        if( isBoundary )
-            addBoundaryMembers(rel);
         List<Command> list = removeTagsFromInnerWays(rel);
-        if( isBoundary )
+        if( isBoundary ) {
             if( !askForAdminLevelAndName(rel) )
                 return;
-        if( isBoundary && getPref("boundaryways") )
-            list.addAll(fixWayTagsForBoundary(rel));
+            addBoundaryMembers(rel);
+            if( getPref("boundaryways") )
+                list.addAll(fixWayTagsForBoundary(rel));
+        }
         list.add(new AddCommand(rel));
         Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), list));
Index: /applications/editors/josm/plugins/relcontext/src/relcontext/actions/SelectRelationAction.java
===================================================================
--- /applications/editors/josm/plugins/relcontext/src/relcontext/actions/SelectRelationAction.java	(revision 25709)
+++ /applications/editors/josm/plugins/relcontext/src/relcontext/actions/SelectRelationAction.java	(revision 25709)
@@ -0,0 +1,31 @@
+package relcontext.actions;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.tools.ImageProvider;
+import relcontext.ChosenRelation;
+import relcontext.ChosenRelationListener;
+
+public class SelectRelationAction extends AbstractAction implements ChosenRelationListener {
+    private ChosenRelation rel;
+
+    public SelectRelationAction( ChosenRelation rel ) {
+        super(tr("Select relation"));
+        putValue(SHORT_DESCRIPTION, tr("Select relation in main selection."));
+        putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
+        this.rel = rel;
+        rel.addChosenRelationListener(this);
+        setEnabled(false);
+    }
+
+    public void actionPerformed( ActionEvent e ) {
+        Main.map.mapView.getEditLayer().data.setSelected(rel.get() == null ? null : rel.get());
+    }
+
+    public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
+        setEnabled(newRelation != null);
+    }
+}
