java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Model.java
changeset 11 9b399cde6a3b
parent 10 ed2b6ebf138d
child 12 a2b41c8ee039
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Model.java	Wed Dec 15 23:29:14 2010 +0100
     1.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Model.java	Wed Dec 15 23:58:34 2010 +0100
     1.3 @@ -23,12 +23,12 @@
     1.4  	private static final Logger log = Logger.getLogger(Model.class.getSimpleName());
     1.5  	private String[] sloupečky = {"Název", "Hodnota"};
     1.6  	private HashSet<TableModelListener> posluchače = new HashSet<TableModelListener>();
     1.7 -	private UserDefinedFileAttributeView souborovySystem;
     1.8 +	private UserDefinedFileAttributeView souborovýSystém;
     1.9  	private ArrayList<Atribut> atributy = new ArrayList<Atribut>();
    1.10  
    1.11  	public Model(File soubor) throws IOException {
    1.12  		Path cesta = soubor.toPath();
    1.13 -		souborovySystem = cesta.getFileAttributeView(UserDefinedFileAttributeView.class);
    1.14 +		souborovýSystém = cesta.getFileAttributeView(UserDefinedFileAttributeView.class);
    1.15  		načtiAtributy();
    1.16  	}
    1.17  
    1.18 @@ -54,7 +54,7 @@
    1.19  
    1.20  	public Object getValueAt(int m, int n) {
    1.21  		if (n == 0) {
    1.22 -			return atributy.get(m).getKlic();
    1.23 +			return atributy.get(m).getKlíč();
    1.24  		} else if (n == 1) {
    1.25  			return atributy.get(m).getHodnota();
    1.26  		} else {
    1.27 @@ -68,19 +68,19 @@
    1.28  			if (n == 0) {
    1.29  				/** Měníme klíč – název atributu */
    1.30  				String novýKlíč = String.valueOf(value.toString());
    1.31 -				if (!novýKlíč.equals(a.getKlic())) {
    1.32 -					if (a.getKlic() != null) {
    1.33 -						souborovySystem.delete(a.getKlic());
    1.34 +				if (!novýKlíč.equals(a.getKlíč())) {
    1.35 +					if (a.isPlatnýKlíč()) {
    1.36 +						souborovýSystém.delete(a.getKlíč());
    1.37  					}
    1.38 -					a.setKlic(novýKlíč);
    1.39 -					if (a.getHodnotaBajty() != null) {
    1.40 -						souborovySystem.write(a.getKlic(), a.getHodnotaBajty());
    1.41 +					a.setKlíč(novýKlíč);
    1.42 +					if (a.isPlatnáHodnota()) {
    1.43 +						souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
    1.44  					}
    1.45  				}
    1.46  			} else if (n == 1) {
    1.47  				/** Měníme hodnotu atributu */
    1.48  				a.setHodnota(String.valueOf(value.toString()));
    1.49 -				souborovySystem.write(a.getKlic(), a.getHodnotaBajty());
    1.50 +				souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
    1.51  			}
    1.52  		} catch (IOException e) {
    1.53  			log.log(Level.SEVERE, "Selhalo ukládání atributu na souborový systém", e);
    1.54 @@ -110,16 +110,18 @@
    1.55  
    1.56  	public void odeberAtribut(Atribut a) throws IOException {
    1.57  		atributy.remove(a);
    1.58 -		souborovySystem.delete(a.getKlic());
    1.59 +		if (a.isPlatnýKlíč()) {
    1.60 +			souborovýSystém.delete(a.getKlíč());
    1.61 +		}
    1.62  		upozorniPosluchače();
    1.63  	}
    1.64  
    1.65  	public final void načtiAtributy() throws IOException {
    1.66 -		List<String> jménaAtributů = souborovySystem.list();
    1.67 +		List<String> jménaAtributů = souborovýSystém.list();
    1.68  		atributy.clear();
    1.69  		for (String jménoAtributu : jménaAtributů) {
    1.70 -			ByteBuffer hodnotaAtributu = ByteBuffer.allocate(souborovySystem.size(jménoAtributu));
    1.71 -			souborovySystem.read(jménoAtributu, hodnotaAtributu);
    1.72 +			ByteBuffer hodnotaAtributu = ByteBuffer.allocate(souborovýSystém.size(jménoAtributu));
    1.73 +			souborovýSystém.read(jménoAtributu, hodnotaAtributu);
    1.74  			atributy.add(new Atribut(jménoAtributu, hodnotaAtributu));
    1.75  		}
    1.76  		upozorniPosluchače();