Java tutorial
/******************************************************************************* * Copyright (c) 2014 OpenLegacy Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * OpenLegacy Inc. - initial API and implementation *******************************************************************************/ package com.openlegacy.enterprise.ide.eclipse.editors.pages.details.jpa; import com.openlegacy.enterprise.ide.eclipse.Constants; import com.openlegacy.enterprise.ide.eclipse.Messages; import com.openlegacy.enterprise.ide.eclipse.editors.models.jpa.JpaNavigationModel; import com.openlegacy.enterprise.ide.eclipse.editors.pages.AbstractMasterBlock; import com.openlegacy.enterprise.ide.eclipse.editors.pages.helpers.FormRowCreator; import com.openlegacy.enterprise.ide.eclipse.editors.pages.helpers.FormRowCreator.JAVA_DOCUMENTATION_TYPE; import com.openlegacy.enterprise.ide.eclipse.editors.pages.helpers.jpa.ControlsUpdater; import com.openlegacy.enterprise.ide.eclipse.editors.pages.helpers.jpa.ModelUpdater; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; import org.eclipse.ui.forms.widgets.TableWrapData; import org.eclipse.ui.forms.widgets.TableWrapLayout; import org.openlegacy.designtime.db.generators.support.DbAnnotationConstants; import java.net.MalformedURLException; import java.util.Map; import java.util.UUID; /** * @author Ivan Bort * */ public class GeneralJpaNavigationDetailsPage extends AbstractJpaDetailsPage { private JpaNavigationModel navigationModel; public GeneralJpaNavigationDetailsPage(AbstractMasterBlock master) { super(master); } @Override public void revalidate() { } @Override public Class<?> getDetailsModel() { return JpaNavigationModel.class; } @Override public void createContents(Composite parent) { TableWrapLayout layout = new TableWrapLayout(); layout.topMargin = 5; layout.leftMargin = 5; layout.rightMargin = 2; layout.bottomMargin = 2; parent.setLayout(layout); FormToolkit toolkit = managedForm.getToolkit(); Section section = toolkit.createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR); section.marginWidth = 10; section.setText(Messages.getString("jpa.general.page.navigation.details.name")); //$NON-NLS-1$ section.setDescription(Messages.getString("jpa.general.page.details.desc")); //$NON-NLS-1$ TableWrapData td = new TableWrapData(TableWrapData.FILL, TableWrapData.TOP); td.grabHorizontal = true; section.setLayoutData(td); Composite client = toolkit.createComposite(section); GridLayout glayout = new GridLayout(); glayout.marginWidth = glayout.marginHeight = 0; glayout.numColumns = 2; client.setLayout(glayout); // create empty row FormRowCreator.createSpacer(toolkit, client, 2); // create row for "catalog" FormRowCreator.createStringRow(toolkit, client, mapTexts, getDefaultModifyListener(), Messages.getString("jpa.navigation.category"), "", DbAnnotationConstants.CATEGORY, //$NON-NLS-1$//$NON-NLS-2$ JAVA_DOCUMENTATION_TYPE.DB, "DbNavigation"); toolkit.paintBordersFor(section); section.setClient(client); } @Override public UUID getModelUUID() { return navigationModel != null ? navigationModel.getUUID() : null; } @Override protected void updateControls() { ControlsUpdater.updateJpaNavigationDetailsControls(navigationModel, mapTexts); } @Override protected void doUpdateModel(String key) throws MalformedURLException, CoreException { Map<String, Object> map = getValuesOfControlsForKey(key); ModelUpdater.updateJpaNavigationModel(getEntity(), navigationModel, key, (String) map.get(Constants.TEXT_VALUE)); } @Override protected void afterDoUpdateModel() { setDirty(getEntity().isDirty()); } @Override protected void selectionChanged(IStructuredSelection selection) { if (selection.size() == 1) { navigationModel = (JpaNavigationModel) selection.getFirstElement(); } else { navigationModel = null; } } }