Changeset 8918

Show
Ignore:
Timestamp:
10/04/08 17:21:19 (7 weeks ago)
Author:
henning_sperr
Message:

create mirror, and remove command

Location:
trunk/java/org.semanticdesktop.nepomuk.comp.imapping
Files:
1 added
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/command/Commands.java

    r8913 r8918  
    1111import info.imapping.core.command.impl.MoveItem; 
    1212import info.imapping.core.command.impl.EraseItem; 
     13import info.imapping.core.command.impl.RemoveItem; 
    1314import info.imapping.core.command.impl.RemoveLink; 
    1415import info.imapping.core.command.impl.RenameLink; 
     
    4041        public CreateTextItem createTextItem(final IMapItem parent, 
    4142                        final IPoint position, final IDimensions dimensions, 
    42                         final String text, boolean named, IItem cdsItem, MapItem mapItem) { 
     43                        final String text, boolean named, IItem cdsItem) { 
    4344 
    4445                final CreateTextItem command = new CreateTextItem( 
    4546                                (IWritableMapItem) parent, position, dimensions, text, named, 
    46                                 itemFactory, cdsItem, mapItem); 
     47                                itemFactory, cdsItem); 
    4748                manager.execute(command); 
    4849                return command; 
     
    7475        } 
    7576 
    76         public EraseItem removeItem(MapItem mapItem, MapItemRepository myRepos) { 
     77        public EraseItem eraseItem(MapItem mapItem, MapItemRepository myRepos) { 
    7778                final EraseItem command = new EraseItem(mapItem, myRepos); 
     79                manager.execute(command); 
     80                return command; 
     81        } 
     82         
     83        public RemoveItem removeItem(MapItem mapItem, MapItemRepository myRepos) { 
     84                final RemoveItem command = new RemoveItem(mapItem, myRepos); 
    7885                manager.execute(command); 
    7986                return command; 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/command/impl/CreateTextItem.java

    r8913 r8918  
    5151         * @param named true if NameItem, else false 
    5252         * @param give cds item if you want to init a mapitem 
    53          * @param give map item if you want a mirror 
    5453         *  
    5554         */ 
    5655        public CreateTextItem(IWritableMapItem parent, IPoint position, IDimensions dimensions, String text, 
    57                         boolean named, MapItemFactory factory, IItem cdsItem, MapItem mapItem) { 
     56                        boolean named, MapItemFactory factory, IItem cdsItem) { 
    5857                this.parent = parent; 
    5958                this.position = position; 
     
    6362                this.factory = factory; 
    6463                this.existingCDS=cdsItem; 
    65                 this.existingMap=mapItem; 
    6664        } 
    6765 
     
    7573                //if we have CDS item, create MapItem for it 
    7674                if (existingCDS!=null){ 
    77                         createdItem = factory.createOrphanMapItem(existingCDS); 
    78                 } 
    79                 else if (existingMap!=null){ 
    80                          
     75                        createdItem = factory.createOrphanMapItem(existingCDS, parent); 
    8176                } 
    8277                else if (named) { 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/command/impl/EraseItem.java

    r8913 r8918  
    88 
    99/** 
    10  * Creates a text item as child of the given parent. 
     10 * Erases an Item. 
    1111 *  
    12  * @author Steffen Braun 
     12 * @author Henning Sperr 
    1313 *  
    1414 */ 
     
    2323 
    2424        /** 
    25          * Removes an IMapping item from all parent bodies.  
    26          *  
     25         * Erases an IMapping item from all parent bodies.  
     26         * and its CDSItem 
    2727         * @param item 
    2828         */ 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/domain/IMapItem.java

    r8913 r8918  
    247247        StoreImapItem getDelegate(); 
    248248 
     249        IMapItem createMirror(String text); 
     250 
    249251} 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/domain/impl/MapItem.java

    r8913 r8918  
    66import info.imapping.core.command.impl.EraseItem; 
    77import info.imapping.core.command.impl.EraseLink; 
     8import info.imapping.core.command.impl.RemoveItem; 
    89import info.imapping.core.command.impl.RemoveLink; 
    910import info.imapping.core.command.impl.RenameLink; 
     
    3334import org.ontoware.rdfreactor.runtime.Base; 
    3435import org.semanticdesktop.swecr.model.IModel; 
     36import org.semanticdesktop.swecr.model.INameItem; 
    3537import org.semanticdesktop.swecr.model.IRelation; 
    3638import org.semanticdesktop.swecr.model.IStatement; 
     
    340342                setInnerHeight(dimensions.getInnerHeight()); 
    341343        } 
    342          
    343         // TODO erase and remove item 
     344 
    344345        /** {@inheritDoc} */ 
    345346        public URI[] remove() { 
    346                 throw _toBeImplemented(); 
     347                RemoveItem removeCommand = commands.removeItem(this,this.repository); 
     348                return null; 
    347349        } 
    348350         
     
    350352        public URI[] erase() { 
    351353                 
    352                 EraseItem eraseCommand = commands.removeItem(this,this.repository); 
     354                EraseItem eraseCommand = commands.eraseItem(this,this.repository); 
    353355         
    354356                return null; 
     
    400402                IDimensions dimensions = new Dimensions(200, 150, 1.2); 
    401403                CreateTextItem command = commands.createTextItem( 
    402                                 this, new Point.ImmutablePoint(0, 0), dimensions, text, named,null,null); 
     404                                this, new Point.ImmutablePoint(0, 0), dimensions, text, named,null); 
    403405                return command.getCreatedTextItem(); 
    404406        } 
     
    488490        } 
    489491 
     492        public IMapItem createMirror(String text) { 
     493                IDimensions dimensions = new Dimensions(200, 150, 1.2); 
     494                //create the Command to init the Item 
     495                INameItem nameItem = store.getCDSModel().getNameItem(text); 
     496                CreateTextItem command = commands.createTextItem( 
     497                                this, new Point.ImmutablePoint(0, 0), dimensions, "", true,nameItem); 
     498                //add to the items list 
     499                return (MapItem)command.getCreatedTextItem(); 
     500        } 
     501 
    490502} 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/domain/impl/MapItemFactory.java

    r8913 r8918  
    9292        /** 
    9393         * Create MapItem for Orphan 
     94         * @param parent  
    9495         * @param CDSItem 
    9596         * @return MapItem 
    9697         */ 
    97         public MapItem createOrphanMapItem(IItem cdsItem){ 
    98                 return createMapItemForCDSItem(cdsItem); 
     98        public MapItem createOrphanMapItem(IItem cdsItem, IWritableMapItem parent){ 
     99                MapItem createdMapItem= createMapItemForCDSItem(cdsItem); 
     100                createdMapItem.setParent(parent); 
     101                return createdMapItem; 
    99102                //(MapItem) itemRepository.getForURI(cdsItem.asJavaURI().toString()); 
    100103                 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/domain/impl/MapItemRepository.java

    r8913 r8918  
    123123                store.removeCDSItem(mapItem.getCDSURI()); 
    124124        } 
     125        public void removeMapItem(IWritableMapItem item) { 
     126                itemByURIMap.remove(item.getURI()); 
     127                itemByNameMap.remove(item.getText()); 
     128        } 
    125129 
    126130        public final MapItemFactory getItemFactory() { 
     
    151155                return parentlessItems; 
    152156        } 
     157 
    153158} 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/service/IMapService.java

    r8913 r8918  
    101101        Set<MapItem> createAndGetAllOrphans(); 
    102102 
     103        boolean isAlreadyNamed(String text); 
     104 
    103105} 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/main/java/info/imapping/core/service/impl/MapService.java

    r8913 r8918  
    171171                                //create the Command to init the Item 
    172172                                CreateTextItem command = commandManager.getCommands().createTextItem( 
    173                                                 null, new Point.ImmutablePoint(0, 0), dimensions, "", true,actualCDSItem,null); 
     173                                                null, new Point.ImmutablePoint(0, 0), dimensions, "", true,actualCDSItem); 
    174174                                //add to the items list 
    175175                                OrphanItems.add((MapItem)command.getCreatedTextItem()); 
     
    190190        } 
    191191 
     192        public boolean isAlreadyNamed(String text) { 
     193                 
     194                return getCDSModel().hasNameItem(text); 
     195        } 
     196 
    192197} 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.core/src/test/java/info/imapping/core/command/CreateTextItemTest.java

    r8913 r8918  
    77import info.imapping.core.domain.IPoint; 
    88import info.imapping.core.domain.impl.Dimensions; 
     9import info.imapping.core.domain.impl.MapItem; 
    910import info.imapping.core.domain.impl.Point; 
    1011 
     
    2930                                position,  
    3031                                dimensions, 
    31                                 ISWC_2008, true,null,null); 
     32                                ISWC_2008, true,null); 
    3233 
    3334                /* root has this item as single Detailitem */ 
     
    5960                assertNotNull(cdsItem); 
    6061                assertNotNull(cdsRoot);  
     62                 
     63        } 
     64        public void testCreateMirrorItem() { 
     65                //create mirrorItems 
     66                IMapItem item1 = getRoot().createName("ABC"); 
     67                IMapItem item2 = getRoot().createMirror("ABC"); 
     68                //now we have 2 children 
     69                assertTrue(getRoot().getChildItems().length==2); 
     70                 
     71                //same CDS Uri 
     72                assertEquals(item1.getCDSURI(),item2.getCDSURI()); 
     73                //but not same Item 
     74                assertFalse(item1.equals(item2)); 
     75                //and not same rdf 
     76                assertFalse(item1.getDelegate().equals(item2.getDelegate())); 
     77                //get uri of item 1!!! 
     78                org.ontoware.rdf2go.model.node.URI itemURI = new org.ontoware.rdf2go.model.node.impl.URIImpl(item1.getCDSURI().toString());  
     79                //get cdsItem of item1 !!! 
     80                org.semanticdesktop.swecr.model.IItem cdsItem = store.getCDSModel().getItem(itemURI); 
     81                //cdsitem not null 
     82                assertNotNull(cdsItem); 
     83                 
     84                //erase item 2 
     85                item2.erase(); 
     86                //now we have one child 
     87                assertTrue(getRoot().getChildItems().length==1); 
     88                //but if we get cdsItem of Item1 again 
     89                cdsItem = store.getCDSModel().getItem(itemURI); 
     90                //it is erased through item2 
     91                assertNull(cdsItem); 
    6192        } 
    6293} 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.ui/src/main/java/info/imapping/piccolo/UIController.java

    r8917 r8918  
    244244                                selectedWidget.removeAllChildren(); 
    245245                                parentWidget.removeChildWidget(selectedWidget); 
    246                                 selectedWidget.getMapItem().erase(); 
     246                                selectedWidget.getMapItem().remove(); 
    247247                                parentWidget.select(); 
    248248                                 
  • trunk/java/org.semanticdesktop.nepomuk.comp.imapping/info.imapping.ui/src/main/java/info/imapping/piccolo/editor/WidgetEditor.java

    r8917 r8918  
    472472                                         * exception. 
    473473                                         */ 
    474                                         try { 
    475                                                 if (editing) { 
    476                                                         editItem(text); 
     474 
     475                                        if (editing) { 
     476                                                editItem(text); 
     477                                        } else { 
     478                                                IMapService mapService = widget.getController() 
     479                                                                .getMapService(); 
     480                                                if (mapService.isAlreadyNamed(text)) { 
     481                                                        String[] optionen = { "Cancel", 
     482                                                                        "Choose other Name", "Create TextItem", 
     483                                                                        "Create Mirror(do not delete)" }; 
     484 
     485                                                        int n = JOptionPane 
     486                                                                        .showOptionDialog( 
     487                                                                                        frame.getComponent(0), 
     488                                                                                        "Item with this name already exists,\n create Textitem or Rename", // Fragetext 
     489                                                                                        "Text or Rename", // Titel 
     490                                                                                        JOptionPane.YES_NO_CANCEL_OPTION, 
     491                                                                                        JOptionPane.QUESTION_MESSAGE, // Icon 
     492                                                                                        null, optionen, optionen[0]); 
     493                                                        if (n == 3) { 
     494                                                                createMirrorItem(text); 
     495                                                        } else if (n == 2) { 
     496                                                                createTextItem(text); 
     497                                                                log 
     498                                                                                .info("NameItem with a String " 
     499                                                                                                + text 
     500                                                                                                + " already existed, created new TextItem instead"); 
     501                                                        } else if (n == 1) { 
     502                                                                log 
     503                                                                                .info("NameItem with a String " 
     504                                                                                                + text 
     505                                                                                                + " already existed, chose renaming item"); 
     506                                                                return; 
     507                                                        } else { 
     508                                                                this.closeEditor(); 
     509                                                                this.editingFinished(); 
     510                                                                return; 
     511                                                        } 
    477512                                                } else { 
    478513                                                        createNameItem(text); 
    479514                                                } 
    480                                         } catch (Exception ex) { 
    481                                                 String[] optionen = {"Cancel", "Choose other Name","CreateTextItem"};  
    482                                                   
    483                                             int n = JOptionPane.showOptionDialog( null,  
    484                                                       "Item with this name already exists,\n create Textitem or Rename",      // Fragetext  
    485                                                       "Text or Rename",  // Titel  
    486                                                       JOptionPane.YES_NO_CANCEL_OPTION,  
    487                                                       JOptionPane.QUESTION_MESSAGE,  // Icon  
    488                                                       null, optionen,optionen[0] ); 
    489                                             if(n==2){ 
    490                                                 createTextItem(text); 
    491                                                 log 
    492                                                         .info("NameItem with a String " 
    493                                                                         + text 
    494                                                                         + " already existed, created new TextItem instead"); 
    495                                             }else if(n==1){ 
    496                                                 log 
    497                                                         .info("NameItem with a String " 
    498                                                                         + text 
    499                                                                         + " already existed, chose renaming item"); 
    500                                                 return; 
    501                                             } 
    502                                             else{ 
    503                                                 this.closeEditor(); 
    504                                                 this.editingFinished(); 
    505                                                 return; 
    506                                             } 
    507                                                  
    508                                                  
    509515                                        } 
    510516                                } 
     
    538544        } 
    539545 
     546         
     547 
    540548        public void startEditing() { 
    541549                setupHelplayer(); 
     
    607615                createChildWidget(childItem); 
    608616        } 
    609  
     617         
     618        private void createMirrorItem(String text) { 
     619                IMapItem childItem = mapItem.createMirror(text); 
     620                Point2D newWidgetPosition = widget.getChildContainer().globalToLocal( 
     621                                mouseClickPosition); 
     622                childItem 
     623                                .changePosition(new info.imapping.core.domain.impl.Point.ImmutablePoint( 
     624                                                newWidgetPosition.getX() - Widget.BASE_HEIGHT, 
     625                                                newWidgetPosition.getY() - Widget.BASE_HEIGHT)); 
     626                childItem.changeExpansionStatus(ExpansionStatus.collapsed); 
     627                createChildWidget(childItem); 
     628                 
     629        } 
    610630        private void createTextItem(final String text) { 
    611631                IMapItem childItem = mapItem.createText(text);