Skip to main content
summaryrefslogtreecommitdiffstats
blob: bf4d782ce3ebe311ffb22d31841562edd7dc67ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.mergeWizard;

import java.util.Arrays;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.conflict.AttributeConflict;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.osee.framework.ui.skynet.widgets.xmerge.MergeUtility;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

/**
 * @author Theron Virgin
 */
public class EditAttributeWizardPage extends WizardPage {

   public static final String TITLE = "Editor Page";
   private AttributeConflict conflict;
   private String changeType = "";
   private Button sourceButton;
   private Button destButton;
   private Button clearButton;
   private Label imageLabel;
   private static final String SOURCE_BUTTON_TEXT = "Load Source Data";
   private static final String SOURCE_TEXT = ConflictResolutionWizard.SOURCE_TITLE;
   private static final String SOURCE_TOOLTIP = "Load the Editor with the Source Branch Attribute Value";
   private static final String DEST_BUTTON_TEXT = "Load Destination Data";
   private static final String DEST_TEXT = ConflictResolutionWizard.DEST_TITLE;
   private static final String DEST_TOOLTIP = "Load the Editor with the Destination Branch Attribute Value";
   private static final int NUM_COLUMNS = 1;
   private IEmbeddedAttributeEditor editor;

   private final Listener listener = new Listener() {
      @Override
      public void handleEvent(Event event) {
         // ...
         try {
            if (conflict.okToOverwriteMerge()) {
               if (event.widget == sourceButton) {
                  if (conflict.getSourceObject() != null) {
                     editor.update(conflict.getSourceObject());
                  }
               }
               if (event.widget == destButton) {
                  if (conflict.getDestObject() != null) {
                     editor.update(conflict.getDestObject());
                  }
               }
               if (event.widget == clearButton) {
                  editor.update("");
               }
            } else {
               MessageDialog.openInformation(getShell(), "Attention", MergeUtility.COMMITED_PROMPT);
            }

         } catch (Exception ex) {
            OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
         }
         getWizard().getContainer().updateButtons();
      }
   };

   public EditAttributeWizardPage(AttributeConflict conflict) {
      super(TITLE);
      try {
         this.conflict = conflict;
         changeType = conflict.getAttributeType().getName();
         if (!conflict.isWordAttribute()) {
            editor =
               EmbededAttributeEditorFactory.getEmbeddedEditor(conflict.getAttributeType(),
                  conflict.getSourceDisplayData(), Arrays.asList(conflict), true);
         }
      } catch (OseeCoreException ex) {
         OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
      }
   }

   @Override
   public void createControl(Composite parent) {
      setTitle("Edit the attribute ");
      Composite composite = new Composite(parent, SWT.NONE);

      if (editor == null) {
         setControl(composite);
         return;
      }

      GridLayout gl = new GridLayout();
      gl.numColumns = NUM_COLUMNS;
      composite.setLayout(gl);
      GridData gd = new GridData(SWT.BEGINNING);
      composite.setLayoutData(gd);
      gd.horizontalSpan = NUM_COLUMNS;

      imageLabel = new Label(composite, SWT.NONE);
      imageLabel.setText("hello there");
      imageLabel.setImage(null);

      try {
         new Label(composite, SWT.NONE).setText(ConflictResolutionWizard.ART_TEXT);
         new Label(composite, SWT.NONE).setText(ConflictResolutionWizard.INDENT + conflict.getArtifactName());
         new Label(composite, SWT.NONE).setText(ConflictResolutionWizard.TYPE_TEXT);
         new Label(composite, SWT.NONE).setText(ConflictResolutionWizard.INDENT + changeType);

         new Label(composite, SWT.NONE).setText("");

         new Label(composite, SWT.NONE).setText(SOURCE_TEXT);
         new Label(composite, SWT.NONE).setText(ConflictResolutionWizard.INDENT + conflict.getSourceDisplayData());
         // sourceButton =
         // createButton(conflict.getSourceDisplayData(),SOURCE_TOOLTIP,composite,gd);
         new Label(composite, SWT.NONE).setText(DEST_TEXT);
         new Label(composite, SWT.NONE).setText(ConflictResolutionWizard.INDENT + conflict.getDestDisplayData());
      } catch (Exception ex) {
         OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
      }

      Composite buttonComp = new Composite(composite, SWT.NONE);
      GridLayout glay = new GridLayout();
      glay.numColumns = 3;
      buttonComp.setLayout(glay);
      GridData gdata = new GridData(SWT.FILL);
      buttonComp.setLayoutData(gdata);
      gdata.horizontalSpan = 1;

      sourceButton = createButton(SOURCE_BUTTON_TEXT, SOURCE_TOOLTIP, buttonComp);
      destButton = createButton(DEST_BUTTON_TEXT, DEST_TOOLTIP, buttonComp);
      // clearButton = createButton(CLEAR_BUTTON_TEXT, CLEAR_TOOLTIP,
      // buttonComp, gdata);

      editor.create(composite, gd);

      setControl(composite);
   }

   private Button createButton(String text, String tooltip, Composite composite) {
      Button button = new Button(composite, SWT.PUSH);
      button.addListener(SWT.Selection, listener);
      button.setText(text);
      button.setToolTipText(tooltip);
      return button;
   }

   public boolean canFinish() {
      return editor.canFinish();
   }

   public boolean closingPage() {
      return editor.commit();
   }

   public void setResolution(Image image) {
      imageLabel.setImage(image);
   }

}

Back to the top