protected DockFactory<?, ?, ?> getFactory( String id ){ DockFactory<?, ?, ?> factory = PredefinedDockSituation.this.getFactory( id ); if( factory == PredefinedDockSituation.this.factory ){ return preload; } return factory; } };
protected DockFactory<?, ?, ?> getFactory( String id ){ DockFactory<?, ?, ?> factory = PredefinedDockSituation.this.getFactory( id ); if( factory == PredefinedDockSituation.this.factory ){ return preload; } return factory; } };
@SuppressWarnings("unchecked") public void write( PredefinedLayout layout, DataOutputStream out ) throws IOException { Version.write( out, Version.VERSION_1_0_7 ); DockLayoutInfo info = layout.getDelegate(); out.writeUTF( layout.getPredefined() ); if( info.getKind() == DockLayoutInfo.Data.BYTE ){ out.writeBoolean( true ); out.write( info.getDataByte() ); } else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ out.writeBoolean( true ); DockLayout delegate = info.getDataLayout(); String factoryId = delegate.getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new IOException( "Missing factory: " + factoryId ); out.writeUTF( factoryId ); factory.write( delegate.getData(), out ); } else if( info.getKind() == DockLayoutInfo.Data.NULL ){ out.writeBoolean( false ); } else{ throw new IllegalArgumentException( "Cannot store information as byte[], it is not present as raw byte[] or in an understandable format" ); } }
@SuppressWarnings("unchecked") public void write( PredefinedLayout layout, DataOutputStream out ) throws IOException { Version.write( out, Version.VERSION_1_0_7 ); DockLayoutInfo info = layout.getDelegate(); out.writeUTF( layout.getPredefined() ); if( info.getKind() == DockLayoutInfo.Data.BYTE ){ out.writeBoolean( true ); out.write( info.getDataByte() ); } else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ out.writeBoolean( true ); DockLayout delegate = info.getDataLayout(); String factoryId = delegate.getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new IOException( "Missing factory: " + factoryId ); out.writeUTF( factoryId ); factory.write( delegate.getData(), out ); } else if( info.getKind() == DockLayoutInfo.Data.NULL ){ out.writeBoolean( false ); } else{ throw new IllegalArgumentException( "Cannot store information as byte[], it is not present as raw byte[] or in an understandable format" ); } }
@SuppressWarnings("unchecked") public PredefinedLayout getLayout( DockElement element, Map<Dockable, Integer> children ) { if( shouldLayout( element )){ String factoryId = UNKNOWN + PredefinedDockSituation.super.getID( element ); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new IllegalStateException( "Missing factory: " + factoryId ); Object data = factory.getLayout( element, children ); DockLayout<Object> layout = new DockLayout<Object>( factoryId, data ); return new PredefinedLayout( elementToString.get( element ), new DockLayoutInfo( layout )); } else{ return new PredefinedLayout( elementToString.get( element ), new DockLayoutInfo() ); } }
@SuppressWarnings("unchecked") public PredefinedLayout getLayout( DockElement element, Map<Dockable, Integer> children ) { if( shouldLayout( element )){ String factoryId = UNKNOWN + PredefinedDockSituation.super.getID( element ); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new IllegalStateException( "Missing factory: " + factoryId ); Object data = factory.getLayout( element, children ); DockLayout<Object> layout = new DockLayout<Object>( factoryId, data ); return new PredefinedLayout( elementToString.get( element ), new DockLayoutInfo( layout )); } else{ return new PredefinedLayout( elementToString.get( element ), new DockLayoutInfo() ); } }
@SuppressWarnings("unchecked") public PredefinedLayout getPerspectiveLayout( PerspectiveElement element, Map<PerspectiveDockable, Integer> children ){ if( perspective == null ){ throw new IllegalStateException( "the perspective of this factory is not set, meaning this factory cannot be used handling perspective dependent tasks" ); } DockLayoutInfo info; if( shouldLayout( element, perspective )){ String factoryId = UNKNOWN + PredefinedDockSituation.super.getID( element ); DockFactory factory = getFactory( factoryId ); if( factory == null ) throw new IllegalStateException( "Missing factory: " + factoryId ); Object data = factory.getPerspectiveLayout( element, children ); DockLayout<Object> layout = new DockLayout<Object>( factoryId, data ); info = new DockLayoutInfo( layout ); } else{ info = new DockLayoutInfo(); } String key = perspective.get( element ); if( key == null ){ throw new IllegalStateException( "Expected a key for an element, the element should be known to the perspective, otherwise this method would not have been called: '" + element +"'" ); } return new PredefinedLayout( key, info ); }
@SuppressWarnings("unchecked") public PredefinedLayout getPerspectiveLayout( PerspectiveElement element, Map<PerspectiveDockable, Integer> children ){ if( perspective == null ){ throw new IllegalStateException( "the perspective of this factory is not set, meaning this factory cannot be used handling perspective dependent tasks" ); } DockLayoutInfo info; if( shouldLayout( element, perspective )){ String factoryId = UNKNOWN + PredefinedDockSituation.super.getID( element ); DockFactory factory = getFactory( factoryId ); if( factory == null ) throw new IllegalStateException( "Missing factory: " + factoryId ); Object data = factory.getPerspectiveLayout( element, children ); DockLayout<Object> layout = new DockLayout<Object>( factoryId, data ); info = new DockLayoutInfo( layout ); } else{ info = new DockLayoutInfo(); } String key = perspective.get( element ); if( key == null ){ throw new IllegalStateException( "Expected a key for an element, the element should be known to the perspective, otherwise this method would not have been called: '" + element +"'" ); } return new PredefinedLayout( key, info ); }
@SuppressWarnings("unchecked") public void estimateLocations( PredefinedLayout layout, LocationEstimationMap children ){ DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ factory.estimateLocations( delegate.getDataLayout().getData(), children ); } } }
@SuppressWarnings("unchecked") public void estimateLocations( PredefinedLayout layout, LocationEstimationMap children ){ DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ factory.estimateLocations( delegate.getDataLayout().getData(), children ); } } }
@SuppressWarnings("unchecked") public void layoutPerspective( PerspectiveElement element, PredefinedLayout layout, Map<Integer, PerspectiveDockable> children ){ DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT && shouldLayout( element, perspective )){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory factory = getFactory( factoryId ); if( factory != null ){ factory.layoutPerspective( element, delegate.getDataLayout().getData(), children ); } } }
@SuppressWarnings("unchecked") public void layoutPerspective( PerspectiveElement element, PredefinedLayout layout, Map<Integer, PerspectiveDockable> children ){ DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT && shouldLayout( element, perspective )){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory factory = getFactory( factoryId ); if( factory != null ){ factory.layoutPerspective( element, delegate.getDataLayout().getData(), children ); } } }
@SuppressWarnings("unchecked") public void setLayout( DockElement element, PredefinedLayout layout, Map<Integer, Dockable> children, PlaceholderStrategy placeholders ) { DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT && shouldLayout( element )){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ DockController controller = element.getController(); try{ if( controller != null ) controller.freezeLayout(); factory.setLayout( element, delegate.getDataLayout().getData(), children, placeholders ); } finally{ if( controller != null ) controller.meltLayout(); } } } }
@SuppressWarnings("unchecked") public void setLayout( DockElement element, PredefinedLayout layout, PlaceholderStrategy placeholders ) { DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT && shouldLayout( element )){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ DockController controller = element.getController(); try{ if( controller != null ) controller.freezeLayout(); factory.setLayout( element, delegate.getDataLayout().getData(), placeholders ); } finally{ if( controller != null ) controller.meltLayout(); } } } }
@SuppressWarnings("unchecked") public void setLayout( DockElement element, PredefinedLayout layout, Map<Integer, Dockable> children, PlaceholderStrategy placeholders ) { DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT && shouldLayout( element )){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ DockController controller = element.getController(); try{ if( controller != null ) controller.freezeLayout(); factory.setLayout( element, delegate.getDataLayout().getData(), children, placeholders ); } finally{ if( controller != null ) controller.meltLayout(); } } } }
@SuppressWarnings("unchecked") public void setLayout( DockElement element, PredefinedLayout layout, PlaceholderStrategy placeholders ) { DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT && shouldLayout( element )){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ DockController controller = element.getController(); try{ if( controller != null ) controller.freezeLayout(); factory.setLayout( element, delegate.getDataLayout().getData(), placeholders ); } finally{ if( controller != null ) controller.meltLayout(); } } } }
@SuppressWarnings("unchecked") public void write( PredefinedLayout layout, XElement element ) { element.addElement( "replacement" ).addString( "id", layout.getPredefined() ); DockLayoutInfo info = layout.getDelegate(); if( info.getKind() == DockLayoutInfo.Data.XML ){ element.addElement( info.getDataXML() ); } else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ DockLayout<?> delegate = layout.getDelegate().getDataLayout(); String factoryId = delegate.getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new XException( "Missing factory: " + factoryId ); XElement xdelegate = element.addElement( "delegate" ); xdelegate.addString( "id", factoryId ); factory.write( delegate.getData(), xdelegate ); } else if( info.getKind() == DockLayoutInfo.Data.NULL ){ // nothing to store } else{ throw new IllegalArgumentException( "Cannot store information as xml, it is neither present as raw xml nor in an understandable format" ); } }
@SuppressWarnings("unchecked") public void write( PredefinedLayout layout, XElement element ) { element.addElement( "replacement" ).addString( "id", layout.getPredefined() ); DockLayoutInfo info = layout.getDelegate(); if( info.getKind() == DockLayoutInfo.Data.XML ){ element.addElement( info.getDataXML() ); } else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ DockLayout<?> delegate = layout.getDelegate().getDataLayout(); String factoryId = delegate.getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new XException( "Missing factory: " + factoryId ); XElement xdelegate = element.addElement( "delegate" ); xdelegate.addString( "id", factoryId ); factory.write( delegate.getData(), xdelegate ); } else if( info.getKind() == DockLayoutInfo.Data.NULL ){ // nothing to store } else{ throw new IllegalArgumentException( "Cannot store information as xml, it is neither present as raw xml nor in an understandable format" ); } }
/** * Tries to read the xml data in <code>layout</code>. * @param layout the layout to read * @return either a new info or <code>null</code> if the data could * not be read */ @SuppressWarnings("unchecked") private DockLayoutInfo fillMissingXML( PredefinedLayout layout ){ XElement xdelegate = layout.getDelegate().getDataXML(); String factoryId = xdelegate.getString( "id" ); Object delegate = null; DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ){ DockFactory<?,?,BackupFactoryData<?>> backup = getBackup( factoryId ); if( backup != null ){ BackupFactoryData<Object> data = (BackupFactoryData<Object>)backup.read( xdelegate, getPlaceholderStrategy() ); if( data != null ) delegate = data.getData(); } } else{ delegate = factory.read( xdelegate, getPlaceholderStrategy() ); } if( delegate == null ){ return null; } return new DockLayoutInfo( new DockLayout<Object>( factoryId, delegate ) ); }
/** * Tries to read the xml data in <code>layout</code>. * @param layout the layout to read * @return either a new info or <code>null</code> if the data could * not be read */ @SuppressWarnings("unchecked") private DockLayoutInfo fillMissingXML( PredefinedLayout layout ){ XElement xdelegate = layout.getDelegate().getDataXML(); String factoryId = xdelegate.getString( "id" ); Object delegate = null; DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ){ DockFactory<?,?,BackupFactoryData<?>> backup = getBackup( factoryId ); if( backup != null ){ BackupFactoryData<Object> data = (BackupFactoryData<Object>)backup.read( xdelegate, getPlaceholderStrategy() ); if( data != null ) delegate = data.getData(); } } else{ delegate = factory.read( xdelegate, getPlaceholderStrategy() ); } if( delegate == null ){ return null; } return new DockLayoutInfo( new DockLayout<Object>( factoryId, delegate ) ); }