blob: 1122b34c4e8f8a4060ae5ec8ebc5284c5a61f47a [file] [log] [blame]
package org.eclipse.epp.sfx.archive.ui.internal;
import org.eclipse.epp.sfx.archive.ui.Activator;
import org.eclipse.epp.sfx.archive.ui.internal.model.Archive;
import org.eclipse.epp.sfx.archive.ui.internal.model.Entry;
import org.eclipse.epp.sfx.archive.ui.internal.model.ModelChangedEvent;
import org.eclipse.epp.sfx.archive.ui.internal.model.SFXArchiveModel;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.dialogs.FileSystemElement;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
public class SFXArchiveConfigurationPage extends FormPage {
private SFXArchiveModel fModel;
private SourceFormPart fSourceFormPart;
private UnpackFormPart fUnpackFormPart;
private DestinationFormPart fDestinationFormPart;
public SFXArchiveConfigurationPage(SFXArchiveConfigurationEditor editor, String id, String title) {
super(editor, id, title);
fModel = editor.getEditorDocumentProvider()
.getSFXArchiveModel(editor.getEditorInput());
}
protected void createFormContent(IManagedForm managedForm) {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 12;
layout.marginBottom = 12;
layout.marginLeft = 6;
layout.marginRight = 6;
layout.horizontalSpacing = 20;
layout.verticalSpacing = 17;
layout.makeColumnsEqualWidth = false;
layout.numColumns = 1;
FormToolkit toolkit = getEditor().getToolkit();
ScrolledForm form = managedForm.getForm();
form.setImage(Activator.getDefault()
.getImageDescriptor("/icons/obj16/sfx_archive_obj.gif").createImage());
form.setText("SFX Archive Configuration");
toolkit.decorateFormHeading(form.getForm());
Composite body = form.getBody();
body.setLayout(layout);
fSourceFormPart = new SourceFormPart(this, body);
fUnpackFormPart = new UnpackFormPart(this, body);
fDestinationFormPart = new DestinationFormPart(this, body);
managedForm.addPart(fSourceFormPart);
managedForm.addPart(fUnpackFormPart);
managedForm.addPart(fDestinationFormPart);
addModelListeners();
}
public void inputChanged(IEditorInput oldInput, IEditorInput newInput) {
removeModelListeners();
fModel = ((SFXArchiveConfigurationEditor) getEditor())
.getEditorDocumentProvider().getSFXArchiveModel(newInput);
addModelListeners();
}
private void addModelListeners() {
if (fModel != null) {
if (fSourceFormPart != null)
fModel.addModelListener(fSourceFormPart);
if (fUnpackFormPart != null)
fModel.addModelListener(fUnpackFormPart);
if (fDestinationFormPart != null)
fModel.addModelListener(fDestinationFormPart);
}
notifyRefresh();
}
private void removeModelListeners() {
if (fModel != null) {
if (fSourceFormPart != null)
fModel.removeModelListener(fSourceFormPart);
if (fUnpackFormPart != null)
fModel.removeModelListener(fUnpackFormPart);
if (fDestinationFormPart != null)
fModel.removeModelListener(fDestinationFormPart);
}
}
public SFXArchiveModel getModel() {
return fModel;
}
private void notifyRefresh() {
if (fModel != null) {
ModelChangedEvent event = new ModelChangedEvent(ModelChangedEvent.TYPE_REFRESH);
if (fSourceFormPart != null)
fSourceFormPart.modelChanged(event);
if (fUnpackFormPart != null)
fUnpackFormPart.modelChanged(event);
if (fDestinationFormPart != null)
fDestinationFormPart.modelChanged(event);
}
}
public ISelectionProvider getSelectionProvider() {
return fSourceFormPart;
}
public FileSystemElement getFileSystemElement(Archive archive, Entry entry) {
return fSourceFormPart.getFileSystemElement(archive, entry);
}
}