]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/javaeditor/saveparticipant/SaveParticipantDescriptor.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / javaeditor / saveparticipant / SaveParticipantDescriptor.java
1 /*******************************************************************************
2  * Copyright (c) 2006, 2011 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.javaeditor.saveparticipant;
12
13 import org.eclipse.core.runtime.Assert;
14
15 /**
16  * Describes a save participant contribution.
17  *
18  * @since 3.3
19  */
20 public class SaveParticipantDescriptor {
21
22         /** The listener */
23         private final IPostSaveListener fPostSaveListener;
24         /** The preference configuration block, if any */
25         private ISaveParticipantPreferenceConfiguration fPreferenceConfiguration;
26
27         /**
28          * Creates a new descriptor which connects a {@link IPostSaveListener}
29          * with an {@link ISaveParticipantPreferenceConfiguration}.
30          *
31          * @param listener the listener
32          */
33         SaveParticipantDescriptor(IPostSaveListener listener) {
34                 Assert.isNotNull(listener);
35
36                 fPostSaveListener= listener;
37         }
38
39         /**
40          * Returns the post save listener of the described
41          * save participant
42          *
43          * @return the listener
44          */
45         public IPostSaveListener getPostSaveListener()  {
46                 return fPostSaveListener;
47         }
48
49         /**
50          * Creates a new preference configuration of the described
51          * save participant.
52          *
53          * @return the preference configuration
54          */
55         public ISaveParticipantPreferenceConfiguration createPreferenceConfiguration() {
56                 return new AbstractSaveParticipantPreferenceConfiguration() {
57
58                         @Override
59                         protected String getPostSaveListenerId() {
60                     return fPostSaveListener.getId();
61             }
62
63                         @Override
64                         protected String getPostSaveListenerName() {
65                     return fPostSaveListener.getName();
66             }
67                 };
68         }
69
70         /**
71          * Returns the preference configuration of the described
72          * save participant.
73          *
74          * @return the preference configuration
75          */
76         public ISaveParticipantPreferenceConfiguration getPreferenceConfiguration() {
77                 if (fPreferenceConfiguration == null)
78                         fPreferenceConfiguration= createPreferenceConfiguration();
79
80             return fPreferenceConfiguration;
81     }
82
83         /**
84          * Returns the identifier of the described save participant.
85          *
86          * @return the non-empty id of this descriptor
87          */
88         public String getId() {
89                 return fPostSaveListener.getId();
90         }
91
92 }