Project

General

Profile

« Previous | Next » 

Revision 0e327bed

Added by Patrick Plitzner almost 8 years ago

  • moved toggle button to the top-right corner of the Media(Specimen)Section (#3339)
    • Changed label

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/MediaDetailsSection.java
10 10

  
11 11
package eu.etaxonomy.taxeditor.ui.section.description;
12 12

  
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.action.ToolBarManager;
13 16
import org.eclipse.jface.viewers.ISelectionProvider;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Control;
14 19
import org.eclipse.ui.forms.widgets.ExpandableComposite;
15 20
import org.eclipse.ui.forms.widgets.TableWrapLayout;
16 21

  
......
61 66

  
62 67
	}
63 68

  
69
	@Override
70
    protected Control createToolbar() {
71
        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
72

  
73
        final String label;
74
        if(element_media.isAdvancedMediaView()){
75
            label = "Use simple media view";
76
        }
77
        else{
78
            label = "Use advanced media view";
79
        }
80

  
81
        Action addAction = new Action("Use advanced media view", IAction.AS_PUSH_BUTTON) {
82
            /* (non-Javadoc)
83
             * @see org.eclipse.jface.action.Action#run()
84
             */
85
            @Override
86
            public void run() {
87
                element_media.toggleAdvancedMediaView();
88
            }
89
        };
90
        addAction.setToolTipText(label);
91

  
92
        toolBarManager.add(addAction);
93

  
94
        return toolBarManager.createControl(this);
95
    }
96

  
64 97
	/**
65 98
	 * <p>setEntity</p>
66 99
	 *
......
74 107
		element_media = (MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED);
75 108
		super.setEntity(entity);
76 109
		setSectionTitle();
110
        setTextClient(createToolbar());
77 111
		layout();
78 112
	}
79 113

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java
13 13
import java.util.List;
14 14
import java.util.Set;
15 15

  
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.events.SelectionListener;
19
import org.eclipse.swt.widgets.Button;
20

  
21 16
import eu.etaxonomy.cdm.model.media.Media;
22 17
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
23 18
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
......
41 36
    private UriWithLabelElement textUri;
42 37
    private MediaRepresentationSection section_mediaRepresentation;
43 38

  
44
    private Button checkBoxShowAdvancedView;
39
    private boolean isAdvancedMediaView;
45 40
    private MediaRepresentationPart singleMediaRepresentationPart;
46 41
    private ICdmFormElement parentFormElement;
47 42
    private int style;
......
61 56
    protected void createControls(ICdmFormElement formElement, Media entity, int style) {
62 57
        this.parentFormElement = formElement;
63 58
        this.style = style;
64
        checkBoxShowAdvancedView = formFactory.createButton(formElement.getLayoutComposite(), "Advanced Media View", SWT.CHECK | style);
65
        checkBoxShowAdvancedView.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
66
        checkBoxShowAdvancedView.addSelectionListener(new SelectionListener() {
67

  
68
            @Override
69
            public void widgetSelected(SelectionEvent e) {
70
                showAdvancedView(checkBoxShowAdvancedView.getSelection());
71
            }
72

  
73
            @Override
74
            public void widgetDefaultSelected(SelectionEvent e) {
75

  
76
            }
77
        });
78 59
    }
79 60

  
80 61
    /* (non-Javadoc)
......
86 67
        if(singleMediaRepresentationPart==null){
87 68
            singleMediaRepresentationPart = MediaUtils.initFirstMediaRepresentationPart(entity);
88 69
        }
89
        showAdvancedView(isAdvancedMediaView());
70
        initIsAdvancedMediaView();
71
        showAdvancedView();
90 72

  
91 73
    }
92 74

  
......
103 85
                textUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
104 86
            }
105 87
        }
106
        else if(eventSource==checkBoxShowAdvancedView){
107
            showAdvancedView(checkBoxShowAdvancedView.getSelection());
108
        }
88
    }
89

  
90
    public void toggleAdvancedMediaView(){
91
        isAdvancedMediaView = !isAdvancedMediaView;
92
        showAdvancedView();
109 93
    }
110 94

  
111 95
    /**
112 96
     * @param showAdvancedView
113 97
     */
114
    private void showAdvancedView(boolean showAdvancedView) {
115
        if(showAdvancedView){
98
    private void showAdvancedView() {
99
        if(isAdvancedMediaView){
116 100
            if(textUri!=null){
117 101
                removeElementsAndControls(textUri);
118 102
            }
......
130 114
        }
131 115
    }
132 116

  
133
    private boolean isAdvancedMediaView(){
117
    private void initIsAdvancedMediaView(){
134 118
        if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ADVANCED_MEDIA_SECTION)){
135
            checkBoxShowAdvancedView.setSelection(true);
136
            checkBoxShowAdvancedView.setEnabled(false);
137
            return true;
119
            isAdvancedMediaView = true;
120
            return;
138 121
        }
139 122
        Set<MediaRepresentation> representations = getEntity().getRepresentations();
140 123
        if(representations.size()>1){
141
            checkBoxShowAdvancedView.setSelection(true);
142
            checkBoxShowAdvancedView.setEnabled(false);
143
            return true;
124
            isAdvancedMediaView = true;
125
            return;
144 126
        }
145 127
        if(representations.size()==1){
146 128
            List<MediaRepresentationPart> parts = representations.iterator().next().getParts();
147 129
            if(parts.size()>1){
148
                checkBoxShowAdvancedView.setSelection(true);
149
                checkBoxShowAdvancedView.setEnabled(false);
150
                return true;
130
                isAdvancedMediaView =  true;
131
                return;
151 132
            }
152 133
        }
153
        return false;
134
        isAdvancedMediaView =  false;
154 135
    }
155 136

  
137
    /**
138
     * @return
139
     */
140
    public boolean isAdvancedMediaView() {
141
        return isAdvancedMediaView;
142
    }
156 143

  
157 144
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java
96 96
        text_title.setLanguageString(title);
97 97
    }
98 98

  
99
    public void toggleAdvancedMediaView(){
100
        mediaDetailElement.toggleAdvancedMediaView();
101
    }
102

  
99 103
    /*
100 104
     * (non-Javadoc)
101 105
     *
......
117 121
            }
118 122
        }
119 123
    }
124

  
125
    /**
126
     * @return
127
     */
128
    public boolean isAdvancedMediaView() {
129
        return mediaDetailElement.isAdvancedMediaView();
130
    }
120 131
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailElement.java
158 158
        }
159 159
    }
160 160

  
161
    public void toogleAdvancedMediaView() {
162
        mediaDetailElement.toggleAdvancedMediaView();
163
    }
164

  
165
    public boolean isAdvancedMediaView() {
166
        return mediaDetailElement.isAdvancedMediaView();
167
    }
168

  
161 169
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailSection.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.ui.section.occurrence.media;
11 11

  
12
import org.eclipse.jface.action.Action;
13
import org.eclipse.jface.action.IAction;
14
import org.eclipse.jface.action.ToolBarManager;
12 15
import org.eclipse.jface.viewers.ISelectionProvider;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Control;
13 18

  
14 19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
15 20
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
......
26 31
 */
27 32
public class MediaSpecimenGeneralDetailSection  extends AbstractCdmDetailSection<MediaSpecimen> {
28 33

  
34
    private MediaSpecimenGeneralDetailElement mediaSpecimenGeneralDetailElement;
35

  
29 36
    /**
30 37
     * @param formFactory
31 38
     * @param conversation
......
76 83
        }
77 84
    }
78 85

  
86
    @Override
87
    protected Control createToolbar() {
88
        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
89

  
90
        final String label;
91

  
92
        if(mediaSpecimenGeneralDetailElement.isAdvancedMediaView()){
93
            label = "Use simple media view";
94
        }
95
        else{
96
            label = "Use advanced media view";
97
        }
98
        Action addAction = new Action("Use advanced media view", IAction.AS_PUSH_BUTTON) {
99
            /* (non-Javadoc)
100
             * @see org.eclipse.jface.action.Action#run()
101
             */
102
            @Override
103
            public void run() {
104
                mediaSpecimenGeneralDetailElement.toogleAdvancedMediaView();
105
            }
106
        };
107
        addAction.setToolTipText(label);
108

  
109
        toolBarManager.add(addAction);
110

  
111
        return toolBarManager.createControl(this);
112
    }
113

  
79 114
    /* (non-Javadoc)
80 115
     * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
81 116
     */
82 117
    @Override
83 118
    protected AbstractCdmDetailElement<MediaSpecimen> createCdmDetailElement(AbstractCdmDetailSection<MediaSpecimen> parentElement, int style) {
84
        return formFactory.createMediaSpecimenGeneralDetailElement(parentElement);
119
        mediaSpecimenGeneralDetailElement = formFactory.createMediaSpecimenGeneralDetailElement(parentElement);
120
        return mediaSpecimenGeneralDetailElement;
85 121
    }
86 122
}

Also available in: Unified diff