KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > jobs > ModifyValueJob


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.jobs;
22
23
24 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
25 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
26 import org.apache.directory.ldapstudio.browser.core.events.ValueModifiedEvent;
27 import org.apache.directory.ldapstudio.browser.core.internal.model.Value;
28 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
29 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
30 import org.apache.directory.ldapstudio.browser.core.model.IValue;
31 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
32
33
34 public class ModifyValueJob extends AbstractModificationJob
35 {
36
37     private IAttribute attribute;
38
39     private IValue oldValue;
40
41     private Object JavaDoc newRawValue;
42
43     private ValueModifiedEvent event;
44
45
46     public ModifyValueJob( IAttribute attribute, IValue oldValue, Object JavaDoc newRawValue )
47     {
48         this.attribute = attribute;
49         this.oldValue = oldValue;
50         this.newRawValue = newRawValue;
51         setName( BrowserCoreMessages.jobs__modify_value_name );
52     }
53
54
55     protected void executeAsyncModificationJob( ExtendedProgressMonitor monitor ) throws ModelModificationException
56     {
57
58         monitor.beginTask( BrowserCoreMessages.jobs__modify_value_task, 2 );
59         monitor.reportProgress( " " ); //$NON-NLS-1$
60
monitor.worked( 1 );
61
62         IValue newValue = new Value( attribute, newRawValue );
63         attribute.modifyValue( oldValue, newValue );
64         attribute.getEntry().getConnection().modify( oldValue, newValue, monitor );
65
66         this.event = new ValueModifiedEvent( attribute.getEntry().getConnection(), attribute.getEntry(), attribute,
67             oldValue, newValue );
68     }
69
70
71     protected IEntry getModifiedEntry()
72     {
73         return attribute.getEntry();
74     }
75
76
77     protected String JavaDoc[] getAffectedAttributeNames()
78     {
79         return new String JavaDoc[]
80             { this.attribute.getDescription() };
81     }
82
83
84     protected void runNotification()
85     {
86         if ( this.event != null )
87         {
88             EventRegistry.fireEntryUpdated( this.event, this );
89         }
90     }
91
92
93     protected String JavaDoc getErrorMessage()
94     {
95         return BrowserCoreMessages.jobs__modify_value_error;
96     }
97
98 }
99
Popular Tags