<commit_before>/*******************************************************************************
 * Copyright (c) 2003 - 2005 University Of British Columbia and others.
 * 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.ui.editor;

import java.util.Iterator;

import javax.security.auth.login.LoginException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugzillaException;
import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.core.NewBugModel;
import org.eclipse.mylar.bugzilla.core.PossibleBugzillaFailureException;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.WebBrowserDialog;
import org.eclipse.mylar.bugzilla.ui.actions.RefreshBugzillaReportsAction;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaReportSelection;
import org.eclipse.mylar.core.util.ErrorLogger;
import org.eclipse.mylar.tasklist.ui.views.TaskListView;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.WorkspaceModifyOperation;


/**
 * An editor used to view a locally created bug that does not yet exist on a
 * server. It uses a <code>NewBugModel</code> object to store the data.
 */
public class NewBugEditor extends AbstractBugEditor {
	
	protected NewBugModel bug;
	protected Text descriptionText;
	protected String newSummary = "";
	protected String newDescription = "";
	
	/**
	 * Creates a new <code>NewBugEditor</code>.
	 */
	public NewBugEditor() {
		super();
	}

	@Override
	public IBugzillaBug getBug() {
		return bug;
	}

	@Override
	protected void addKeywordsList(String keywords, Composite attributesComposite) {
		// Since NewBugModels have no keywords, there is no
		// GUI for them.
	}

	@Override
	protected void createDescriptionLayout() {
		
		// Description Area
		Composite descriptionComposite = new Composite(infoArea, SWT.NONE);
		GridLayout descriptionLayout = new GridLayout();
		descriptionLayout.numColumns = 4;
		descriptionComposite.setLayout(descriptionLayout);
		descriptionComposite.setBackground(background);
		GridData descriptionData = new GridData(GridData.FILL_BOTH);
		descriptionData.horizontalSpan = 1;
		descriptionData.grabExcessVerticalSpace = false;
		descriptionComposite.setLayoutData(descriptionData);
		//	End Description Area
		
		Composite descriptionTitleComposite =
			new Composite(descriptionComposite, SWT.NONE);
		GridLayout descriptionTitleLayout = new GridLayout();
		descriptionTitleLayout.horizontalSpacing = 0;
		descriptionTitleLayout.marginWidth = 0;
		descriptionTitleComposite.setLayout(descriptionTitleLayout);
		descriptionTitleComposite.setBackground(background);
		GridData descriptionTitleData =
			new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		descriptionTitleData.horizontalSpan = 4;
		descriptionTitleData.grabExcessVerticalSpace = false;
		descriptionTitleComposite.setLayoutData(descriptionTitleData);
		newLayout(descriptionTitleComposite, 4, "Description:", HEADER).addListener(SWT.FocusIn, new DescriptionListener());
		
		descriptionText = 
			new Text(descriptionComposite,
				SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
		descriptionText.setFont(COMMENT_FONT);
		GridData descriptionTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		descriptionTextData.horizontalSpan = 4;
		descriptionTextData.widthHint = DESCRIPTION_WIDTH;
		descriptionTextData.heightHint = DESCRIPTION_HEIGHT;
		descriptionText.setLayoutData(descriptionTextData);
		descriptionText.setText(bug.getDescription());
		descriptionText.addListener(SWT.KeyUp, new Listener() {
			public void handleEvent(Event event) {
				String sel = descriptionText.getText() + event.character;
				if (!(newDescription.equals(sel))) {
					newDescription = sel;
					changeDirtyStatus(true);
				}
			}
		});
		descriptionText.addListener(SWT.FocusIn, new DescriptionListener());

        super.descriptionTextBox = descriptionText;
        
		this.createSeparatorSpace(descriptionComposite);
}

	@Override
	protected void createCommentLayout() {
		// Since NewBugModels have no comments, there is no
		// GUI for them.
	}

	@Override
	protected void addRadioButtons(Composite buttonComposite) {
		// Since NewBugModels have no special submitting actions,
		// no radio buttons are required.
	}

	@Override
	protected String getTitleString() {
		return bug.getLabel();
	}
	
	@Override
	protected void submitBug() {
		final BugPost form = new BugPost(); 
		form.setPrefix(BugPost.FORM_PREFIX_BUG_218);
		form.setPrefix(BugPost.FORM_PREFIX_BUG_220);
		
		form.setPostfix(BugPost.FORM_POSTFIX_216);
		form.setPostfix2(BugPost.FORM_POSTFIX_218);
		updateBug();

		setURL(form, "post_bug.cgi");
		// go through all of the attributes and add them to the bug post
		Iterator<Attribute> itr = bug.getAttributes().iterator();
		while (itr.hasNext()) {
			Attribute a = itr.next();
			if (a != null && a.getParameterName() != null
					&& a.getParameterName().compareTo("") != 0
					&& !a.isHidden()) {
				String key = a.getName();
				String value = null;

				// get the values from the attribute
				if (key.equalsIgnoreCase("OS")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Version")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Severity")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Platform")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Component")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Priority")) {
					value = a.getValue();<commit_msg>Completed: Bug 119254: New bug id error with Bugzilla 2.20 (parsing) https://bugs.eclipse.org/bugs/show_bug.cgi?id=119254<commit_after>/*******************************************************************************
 * Copyright (c) 2003 - 2005 University Of British Columbia and others.
 * 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.ui.editor;

import java.util.Iterator;

import javax.security.auth.login.LoginException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugzillaException;
import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.core.NewBugModel;
import org.eclipse.mylar.bugzilla.core.PossibleBugzillaFailureException;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.WebBrowserDialog;
import org.eclipse.mylar.bugzilla.ui.actions.RefreshBugzillaReportsAction;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaReportSelection;
import org.eclipse.mylar.core.util.ErrorLogger;
import org.eclipse.mylar.tasklist.ui.views.TaskListView;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.WorkspaceModifyOperation;


/**
 * An editor used to view a locally created bug that does not yet exist on a
 * server. It uses a <code>NewBugModel</code> object to store the data.
 */
public class NewBugEditor extends AbstractBugEditor {
	
	protected NewBugModel bug;
	protected Text descriptionText;
	protected String newSummary = "";
	protected String newDescription = "";
	
	/**
	 * Creates a new <code>NewBugEditor</code>.
	 */
	public NewBugEditor() {
		super();
	}

	@Override
	public IBugzillaBug getBug() {
		return bug;
	}

	@Override
	protected void addKeywordsList(String keywords, Composite attributesComposite) {
		// Since NewBugModels have no keywords, there is no
		// GUI for them.
	}

	@Override
	protected void createDescriptionLayout() {
		
		// Description Area
		Composite descriptionComposite = new Composite(infoArea, SWT.NONE);
		GridLayout descriptionLayout = new GridLayout();
		descriptionLayout.numColumns = 4;
		descriptionComposite.setLayout(descriptionLayout);
		descriptionComposite.setBackground(background);
		GridData descriptionData = new GridData(GridData.FILL_BOTH);
		descriptionData.horizontalSpan = 1;
		descriptionData.grabExcessVerticalSpace = false;
		descriptionComposite.setLayoutData(descriptionData);
		//	End Description Area
		
		Composite descriptionTitleComposite =
			new Composite(descriptionComposite, SWT.NONE);
		GridLayout descriptionTitleLayout = new GridLayout();
		descriptionTitleLayout.horizontalSpacing = 0;
		descriptionTitleLayout.marginWidth = 0;
		descriptionTitleComposite.setLayout(descriptionTitleLayout);
		descriptionTitleComposite.setBackground(background);
		GridData descriptionTitleData =
			new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		descriptionTitleData.horizontalSpan = 4;
		descriptionTitleData.grabExcessVerticalSpace = false;
		descriptionTitleComposite.setLayoutData(descriptionTitleData);
		newLayout(descriptionTitleComposite, 4, "Description:", HEADER).addListener(SWT.FocusIn, new DescriptionListener());
		
		descriptionText = 
			new Text(descriptionComposite,
				SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
		descriptionText.setFont(COMMENT_FONT);
		GridData descriptionTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		descriptionTextData.horizontalSpan = 4;
		descriptionTextData.widthHint = DESCRIPTION_WIDTH;
		descriptionTextData.heightHint = DESCRIPTION_HEIGHT;
		descriptionText.setLayoutData(descriptionTextData);
		descriptionText.setText(bug.getDescription());
		descriptionText.addListener(SWT.KeyUp, new Listener() {
			public void handleEvent(Event event) {
				String sel = descriptionText.getText() + event.character;
				if (!(newDescription.equals(sel))) {
					newDescription = sel;
					changeDirtyStatus(true);
				}
			}
		});
		descriptionText.addListener(SWT.FocusIn, new DescriptionListener());

        super.descriptionTextBox = descriptionText;
        
		this.createSeparatorSpace(descriptionComposite);
}

	@Override
	protected void createCommentLayout() {
		// Since NewBugModels have no comments, there is no
		// GUI for them.
	}

	@Override
	protected void addRadioButtons(Composite buttonComposite) {
		// Since NewBugModels have no special submitting actions,
		// no radio buttons are required.
	}

	@Override
	protected String getTitleString() {
		return bug.getLabel();
	}
	
	@Override
	protected void submitBug() {
		final BugPost form = new BugPost(); 
		form.setPrefix(BugPost.FORM_PREFIX_BUG_218);
		form.setPrefix2(BugPost.FORM_PREFIX_BUG_220);
		
		form.setPostfix(BugPost.FORM_POSTFIX_216);
		form.setPostfix2(BugPost.FORM_POSTFIX_218);
		updateBug();

		setURL(form, "post_bug.cgi");
		// go through all of the attributes and add them to the bug post
		Iterator<Attribute> itr = bug.getAttributes().iterator();
		while (itr.hasNext()) {
			Attribute a = itr.next();
			if (a != null && a.getParameterName() != null
					&& a.getParameterName().compareTo("") != 0
					&& !a.isHidden()) {
				String key = a.getName();
				String value = null;

				// get the values from the attribute
				if (key.equalsIgnoreCase("OS")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Version")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Severity")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Platform")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Component")) {
					value = a.getValue();
				} else if (key.equalsIgnoreCase("Priority")) {
					value = a.getValue();
{'fraction_non_alphanumeric': 0.12482813517620667, 'fraction_numerical': 0.005933859179390694, 'mean_word_length': 5.019163763066202, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5329842', 'n_tokens_mistral': 4518, 'n_tokens_neox': 3992, 'n_words': 860}